I’m trying to migrate my resource definition from Terraform Plugin SDK v2 to Plugin Framework. I need to maintain (at least for now) backwards compatibility for the users of the provider and I need to stick to blocks for objects, rather than attributes.
So far, the road has been bumpy, to say the least, however, I’ve been stuck with a peculiar problem for days now and would appreciate any suggestions/help.
What I’m trying to achieve?
I have an object, called “objective”, it’s a block set (and has to stay this way for backwards compatibility). The elements of the set are fairly complex, they have some computed fields. Previously (in the SDK) there was this very hand schema.NewSet function, which also accepted a hashing function and thus let me only focus on a couple of attributes which uniquely defined each element.
Now, there’s no such option out of the box, so I decided to implement a custom equality function for these elements, and in order to do that I had to create a custom type:
return schema.SetNestedBlock{
Description: description,
MarkdownDescription: description,
Validators: []validator.Set{
setvalidator.IsRequired(),
setvalidator.SizeAtLeast(1),
},
NestedObject: schema.NestedBlockObject{
CustomType: objectiveType,
Attributes: objectiveAttributes,
Blocks: objectiveBlocks,
},
}
I can link the full type definition, along with a corresponding value definition, but these two seem to be working well.
What I’m getting now, is when Terraform is reading the config, it drops the following error:
While creating a Set value, an invalid element was detected. A Set must use
the single, given element type. This is always an issue with the provider and
should be reported to the provider developers.
Set Element Type: frameworkprovider.sloObjectiveType
Set Index (0) Element Type:
types.ObjectType[...
This was unexpected, but I figured maybe I’ve missed adding CustomType to the set schema? So I added this:
CustomType: types.SetType{
ElemType: objectiveType,
},
To no avail.
And thus I wonder, what I’m missing here? Is this even the right path? Or maybe there’s some other, easier way to implement custom set elements uniqueness constraints?
Framework version: v1.15.0
