-
Notifications
You must be signed in to change notification settings - Fork 94
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
Consider raising error when a List
(or Set
) attribute defines both ElementType
and CustomType
#947
Comments
Schema definitions which use a custom type for attributes which embed a collection type (e.g., The following two examples are taken from hashicorp/terraform-plugin-docs#342, and hashicorp/terraform-plugin-docs#343, respectively: "health_check_arns": schema.ListAttribute{
ElementType: types.StringType,
CustomType: cctypes.MultisetType, // `MultisetType embeds `ListType`
/* ... */
}, "framework_controls": schema.SetNestedAttribute{
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"control_scope": schema.SingleNestedAttribute{
Attributes: map[string]schema.Attribute{
"compliance_resource_ids": schema.ListAttribute{
ElementType: types.StringType,
CustomType: cctypes.MultisetType, // MultisetType embeds `ListType`
/* ... */
},
/* ... */ In both instances, the As a consequence, this results in the block: {
attributes: {
name: "framework_controls"
nested_type: {
attributes: {
name: "control_scope"
nested_type: {
attributes: {
name: "compliance_resource_ids"
type: "[\"list\",\"dynamic\"]"
description: "The ID of the only AWS resource that you want your control scope to contain."
optional: true
computed: true
} The usage of func (l ListType) ElementType() attr.Type {
if l.ElemType == nil {
return missingType{}
}
return l.ElemType
} The func (t missingType) TerraformType(_ context.Context) tftypes.Type {
return tftypes.DynamicPseudoType
} Depending upon the where in the schema this occurs, this can give rise to unexpected results (e.g., Adding CustomType to a ListAttribute changes generated description to List of Dynamic), or errors (e.g., Unexpected error NestingSet blocks may not contain attributes of cty.DynamicPseudoType). In the latter case, the error is raised in Terraform core due to a validation failure. |
Drive-by note: I see this issue two ways -- One, we could do what is proposed here since it reflects the current framework implementation. I would classify this more as a bug fix in the sense of not notifying provider developers more upfront of the errant implementation and needing to unfortunately discover/triage the issue other ways. Two, this could potentially be turned around as a framework feature request that attributes could automatically do what you tried to do there with both fields. There is the Maybe its worth treating this issue as-is as a bug fix and creating a separate feature request to see if about the feasibility of using the additional type system interface if its detected on the custom type. When it comes to more gnarly schema definitions like collection-based nested attributes, needing to effectively repeat all the type information of a |
Module version
Use-cases
If the schema definition of a
List
(orSet
) attribute contains bothElementType
andCustomType
thenElementType
is not effective.Consider reporting such a case during schema verification.
References
Relates hashicorp/terraform-plugin-docs#342.
Relates hashicorp/terraform-plugin-docs#343.
The text was updated successfully, but these errors were encountered: