Comments (7)
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.
Does this address the question sufficiently enough to close the issue, @rberlind?
from terraform-provider-restapi.
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.
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.
Awesome. Thanks. I do think the extra flexibility will be useful.
from terraform-provider-restapi.
Cool - we'll call it good and close this one out.
from terraform-provider-restapi.
Thanks!
from terraform-provider-restapi.
Related Issues (20)
- "POST" not working as destroy method HOT 2
- How to build / test local changes to the provider. HOT 3
- import is not documented
- Add support to ignore changes in read-only attributes HOT 2
- Incorrect License Display in GitHub REST API
- How to update predefined resources (already created by default)? HOT 1
- Diff is not shown in case of manual changes outside of terraform
- Error while installing mastercard/restapi v1.18.0: error checking (signature: openpgp: key expired)
- Pulling in data from endpoint with no query parameters?
- Support for different Content-Type / Headers for each method
- Delete API not triggered on destroy (redux)
- [Feature Request] Moving all the parameters from the provider to restapi_object
- Multiple base URIs
- [curl] allow request body, content-type to be provided as strings
- Error: internal validation failed; object ID is not set, but may have been created; this should never happen HOT 1
- terraform import ignore query_string
- restapi_object data is not optional
- Read Data Support Breaks APIs that don't accept a body for GET method HOT 2
- HTTP Method Specific Headers
- Resource not recreated if not found with `read_search`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-restapi.