terraform-plugin-framework
terraform-plugin-framework copied to clipboard
"Follow" Embedded Structs
terraform-plugin-go version
v0.4.0
Use cases
Consider the following type 👇🏼
type Port struct {
FromPort int `json:"fromPort" tfsdk:"from_port"`
ToPort int `json:"toPort" tfsdk:"to_port"`
}
type Source struct {
Address string `json:"address" tfsdk:"address"`
MAC string `json:"mac" tfsdk:"mac"`
*Port
}
In JSON
, address, mac, fromPort, and toPort
would all be at the same level. I want this identical behavior for tdsdk
. Currently, it'll complain that the embedded *Port
field doesn't contain a tag.
Attempted solutions
I have a workaround worth about 100 lines of code that implements FromTerraform5Value
and ToTerraform5Value
.
Proposal
Implement the same behavior as encoding/json
so that...
"destination": {
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{
"from_port": {
Type: types.NumberType,
Required: true,
},
"to_port": {
Type: types.NumberType,
Required: true,
},
"address": {
Type: types.StringType,
Optional: true,
},
}),
Required: true,
},
...will natively be unmarshaled into the aforementioned type.
References
This issue appears to be specific to terraform-plugin-framework, so going to transfer it over there.
I would love this feature. It would allow me to embed a BaseModel in specific ResourcesModel and DataSourceModel. Currently I need to duplicate all the fields.
@frankgreco If you still have the workaround, would you be willing to share it?
@skirsten I gave up and restructured my Go types. TBH I'm kind of disappointed in the level of engagement these GH issues get from developing trying to try the new framework.
Additional HashiCorp Discuss references:
- https://discuss.hashicorp.com/t/struct-embedding-in-attribute-models/51456
- https://discuss.hashicorp.com/t/terraform-plugin-framework-nested-itself/51504
Will bring this up during our team's next regularly scheduled triage meeting to get it on the schedule. To set expectations, efforts (reviews or implementations) in this area may not happen until late April as we already have other features queued up in the meantime.
- 1 here, also want this feature.
Time has passed and this is a useful feature. @bflad, has the team had a chance to look into merging the PR implementing this? I'm facing the same issue today.
UP ?
I just got done refactoring a provider because I never in 100 years would've thought that embedding a struct would not be supported.
This is a much needed feature. I am also facing the need of refactoring a complete provider because I cannot share a BaseModel between datasource and resource, if this feature is not implemented
+1 🙏