We have a couple of set/list attributes in the resource schema to migrate from SDKv2 to terraform-plugin-framework. Some of them is tricky to work. One is a computed, optional SetAttribute, with some required attributes and some attributes need default. For example:
"sdkv2_set_attribute": {
Type: schema.TypeSet,
Description: "A set",
Optional: true,
Computed: true,
Elem: setElement(),
}
func setElement() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"attr_1": {
Type: schema.TypeInt,
Required: true,
Description: "attr1",
},
"attr_2": {
Type: schema.TypeBool,
Description: "attr2",
Optional: true,
Default: false,
},
}
}
}
We’ve tried some options but neither of them works well so far:
-
Nested attribute: we can’t use it because we must support protocol 5
-
Nested block: it can include these attributes settings, however, the block must be inputed in the config and the required attributes must be set in the case. Because the list/set is optional in sdkv2, user usually doesn’t have it in the config. Without the block in the config, this error is raised:
Error: Provider produced inconsistent result after apply
When applying changes to my_resource.test, provider
"provider[\"registry.terraform.io/hashicorp/linode\"]" produced an unexpected
new value: .my_set_block: actual set element
cty.ObjectVal(map[string]cty.Value{"id":some_id,
"label":some_label) does not correlate with any element in
plan.
This is a bug in the provider, which should be reported in the provider's own
issue tracker.
Error: Provider produced inconsistent result after apply
When applying changes to my_resource.test, provider
"provider[\"registry.terraform.io/hashicorp/linode\"]" produced an unexpected
new value: .my_set_block: block set length changed from 0 to 1.
- List/set attribute + object type: it can’t have complicated setting, i.e. defaults, required, etc. I tried to set default in ModifyPlan() but doesn’t work:
Error: Provider produced invalid plan
Provider "registry.terraform.io/hashicorp/linode" planned an invalid value
for my_resource.test.my_list: planned value
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{"my_attr":cty.StringVal("my_default_string")...}
does not match config value
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{"my_attr":cty.NullVal(cty.String)...}
Can we have any suggestion on what’s the approach we should go with and how may we fix the issues discovered? Thank you in advance.