Giter Club home page Giter Club logo

Comments (7)

DRuggeri avatar DRuggeri commented on July 20, 2024

The id_attribute is set at the provider level, but is used at the resource level. When an object is created and returns:

{
  "id": "foo",
  "name": "bar",
. . . 
}

the internal terraform ID of that object will be just foo and subsequent calls to the API (unless messing with *_path) will go to [value_of_path]/foo

This is set at the provider level since it's a reasonable assumption that the attribute used to identify an object is going to be the same attribute across all objects.

I think it would be more aligned with "terraform-isms" to create multiple provider instances if the API does such a strange thing.

from terraform-provider-restapi.

DRuggeri avatar DRuggeri commented on July 20, 2024

Does this address the question sufficiently enough to close the issue, @rberlind?

from terraform-provider-restapi.

rberlind avatar rberlind commented on July 20, 2024

Using multiple provider instances could certainly be done and would be needed for other reasons such as using the provider in a single Terraform configuration against multiple API servers.

I don't agree that the ID would be the same for all objects even if hitting a single API server. Different APIs within a single API server might use different field for ID. For instance, the Terraform Enterprise API uses "name" to retrieve a specific workspace whereas most of its other API endpoints use "id". Compare https://www.terraform.io/docs/enterprise/api/workspaces.html#update-a-workspace and https://www.terraform.io/docs/enterprise/api/policies.html#update-a-policy. The first requires specifying the workspace name instead of the id (which does exist) while the second requires specifying the id itself.

It also turns out that datasources as currently written need id_attribute to be set. If different datasources wanted to use a different field as the "id", being able to set it in both the resource and in the datasource would avoid having to use multiple instances of the provider unless absolutely necessary.

Perhaps it would make sense to add id_attribute field to both the resource and datasource schemas and have those override id_attribute set in the provider if set? That way, a user who did have the same id_attribute for all API endpoints on a single API server would only need to set it once, at the provider level; but users who needed different id_attributes could override the value that had been set in the provider itself? I might be able to try adding this.

Making this change is certainly not urgent. As you said, multiple provider instances can always be used.

from terraform-provider-restapi.

DRuggeri avatar DRuggeri commented on July 20, 2024

SO sorry for the long delay. Thinking more about it, id_attribute really is an object-level construct anyway. I've done as you suggest and made the value available in the resource, datasource AND provider. If all of the objects will work the same, it's easier/more user friendly to set it on the provider. Otherwise, each resource/datasource can have it's own distinct setting now as of 1.3.0.

from terraform-provider-restapi.

rberlind avatar rberlind commented on July 20, 2024

Awesome. Thanks. I do think the extra flexibility will be useful.

from terraform-provider-restapi.

DRuggeri avatar DRuggeri commented on July 20, 2024

Cool - we'll call it good and close this one out.

from terraform-provider-restapi.

rberlind avatar rberlind commented on July 20, 2024

Thanks!

from terraform-provider-restapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.