Hello,
I’m trying to migrate an existing provider from v2 SDK to the new framework but am confused how to set a model field (Domain
, assigned the type types.Set
) from the Read
method of the resource.
The schema looks like this:
Blocks: map[string]schema.Block{
"domain": schema.SetNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"comment": schema.StringAttribute{
MarkdownDescription: "An optional comment about the domain",
Optional: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "The domain that this service will respond to. It is important to note that changing this attribute will delete and recreate the resource",
Required: true,
},
},
},
},
},
Effectively the structure of the ‘block’ is like a map where a ‘domain’ consists of a ‘comment’ and a ‘name’
So something like the following provider code doesn’t make sense to me because it looks like I’m only storing values in the set (where I think I should be storing a key/value, e.g. comment=“foo” and name=“bar”):
domains := []attr.Value{}
for _, domain := range clientDomainResp {
if v, ok := domain.GetCommentOk(); ok {
domains = append(domains, NewStringValue(*v),)
}
if v, ok := domain.GetNameOk(); ok {
domains = append(domains, NewStringValue(*v),)
}
}
set, _ := types.SetValue(types.StringType, domains)
data.Domain = set
UPDATE: Looks like (from a test error I’m seeing) that I need to assign a tftypes.Set[tftypes.Object["comment":tftypes.String, "name":tftypes.String]]
. Again, I’m not sure how to do this
I’ve really struggled with this, so hopefully someone can help clarify for me.
Thanks!