-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for resource schema properties with nested structures #155
Comments
Hi @dikhan! The comment you found is accurate in that it isn't currently supported, but it is no longer correct that there isn't a known way to support this. In fact, the forthcoming Terraform v0.12 has a new protocol for providers that lays the groundwork for this being possible, but the SDK itself is not ready to support it for the moment because it is still trying to support Terraform 0.10, 0.11 and 0.12 at once and so is constrained a little. After the final Terraform v0.12 release is out, we'll begin a project to improve the SDK to support the new v0.12 features (which is likely to also mark the end of ongoing Terraform 0.10 and 0.11 support), which should allow what you wanted to do here. In the meantime, existing providers have achieved an approximation of what you want to do here by using a resource "swaggercodegen_cdn_v1" "my_cdn" {
object_nested_scheme_property {
name = "dani"
object_property {
account = "something"
}
}
} The provider code will see In this case we usually give the list attribute a name that makes it appear that it's declaring the existence of a new object or a category of settings. I can't give a specific example because your issue here didn't include any specific nouns to work with, but you can see similar usage in a number of existing providers, including ones for other CDNs like the AWS provider's support for CloudFront and the Fastly provider. (Some of those are using |
Hi @apparentlymart ! Thanks a lot for the quick response, and apologies for my slow response xP...I managed to put the work around together based on your suggestion and it worked :) Here's the tf config example:
And this is the result after the apply:
And the state file for the ref:
Limiting the list to just one element does give the feeling that the object property is list-ness; however this might cause some confusion to the users when they interpolate these properties in other resources as they will need to be aware of the type and index accordingly the array to fetch the value. Nevertheless, this is not something that is a blocker at the moment and cannot be solved with proper documentation that clarifies this behaviour so the user is aware of it. So all good :) Looking forward to seeing the new version 0.12 in action. Do you think there will be a lot of incompatible changes when migrating custom providers to the new SDK? Please feel free to close this feature request considering the workaround suggested and also the fact that 0.12 sdk will have this use case covered. Thanks! |
As recommended by terraform main maintainer (see ticket ref below), limiting the property to MAX one elem so internally terraform will not perform basic validation which was causing issues previously. If a given property is marked with the following extension: x-terraform-nested-object, the property will be translated to internal terraform property schema as a list of one elem (to show the listless appearing in the configuration) More info about it in the following ticket: https://github.com/hashicorp/terraform/issues/21217
…imiting the property to MAX one elem so internally terraform will not perform basic validation which was causing issues previously. Created TODO placeholders for the team to fill out. More info about it in the following ticket: https://github.com/hashicorp/terraform/issues/21217#issuecomment-489699737
I'm curious if a schema like the following will be supported by the approach of approximation of using a
|
What is the best practice to get only the attributes the user set in .tf of nested structures? |
Just for discoverability purposes through search I will say that I sometimes refer to this as |
@radeksimko I'm also wondering if you are considering support for element of type This is a real case scenario for https://github.com/terraform-providers/terraform-provider-vra7 where you create blueprints for resources and each vRA client can have different keys for those configurations. So this provider should expect anything inside |
0.12 core does support that, the SDK does not yet. In core there is a concept of a |
@paultyng #248 was closed, do you know if there is still any plan to add support for nested data structures to the SDK? The comments in #248 were somewhat ambiguous. My specific use case is that I'm creating a custom data-source provider that queries an external API and returns arbitrary JSON data (depending on the query provided by the user). Right now I'm just returning a JSON string that the end user then must pass to |
I no longer work at HashiCorp (so will tag in @paddycarver) but I believe the answer to this is that you can currently only use the DynamicPseudoType via https://github.com/hashicorp/terraform-plugin-go (the lower level SDK), but it is possible to switch which SDK you are using on a resource by resource basis. |
Current Terraform Version
Use-cases
As a service provider building my own custom terraform provider, I would like to be able to have resources with schemas that contain properties with nested structures.
More context:
One of the APIs I am building a custom terraform plugin for, requires support for nested objects (nested structures).
After building the custom terraform provider providing support for the API aforementioned, I ran into the following error message when managing such resource:
The terraform config looks like this:
For the sake of more context, the API in question has the following OpenAPI v2 spec model.
Attempted Solutions
So far I have just tried to understand where the error is being thrown, and that's where I ran into the following line of code from the terraform core library where it clearly states that nested structs are not currently supported:
Link to potentially the source of the issue:
https://github.com/hashicorp/terraform/blob/master/helper/schema/schema.go#L1646
Pasting here the comment line the above link points to:
The translated terraform resource schema struct for the above definition looks as follows:
I am happy yo contribute to add support for this feature, however the comment above seems to suggest the terraform team has not decided yet
how to handle nested structures in maps
so I was wondering if you could provide more insight about this.Thanks!
Proposal
References
The text was updated successfully, but these errors were encountered: