terraform-plugin-framework
terraform-plugin-framework copied to clipboard
Consider Splitting tfsdk.Attribute into datasource.Attribute, provider.Attribute, and resource.Attribute
Module version
Post plan modification support
Use-cases
Plan modifications can only occur on resource attributes. Since the Attribute type is shared across data source, provider, and resource schemas, it is possible to define plan modifiers on data source and provider attributes which will have no effect. This can be confusing for provider developers.
Attempted Solutions
Note behavior in Go documentation.
Proposal
Consider creating separate Go types for data source, provider, and resource attributes which can cause compile-time errors for functionality not supported by each type. e.g.
package datasource
type Attribute struct{
// ... Type, etc. ....
}
package provider
type Attribute struct{
// ... Type, etc. ....
}
package resource
type Attribute struct{
// ... Type, etc. ....
PlanModifiers []AttributePlanModifier
}
References
- https://github.com/hashicorp/terraform-plugin-framework/pull/123/files#r702095995
I am gently suspicious that the fix will make things confusing (nested attributes can accept provider attributes inside a data source attribute?) but I think it's an interesting line of inquiry.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.