Hi,
I’m looking to implement a resource using the plugin framework and am experiencing issues with nested objects in the schema. From reading some of the SDK migration docs and similar posts here I looked to move this nested object from the schema’s ‘Attributes’ to ‘Blocks’ but now face the ‘block count changed’ error when the resource’s create handler goes to update this block attribute.
Resource struct
type resourceChannelData struct {
ARN types.String `tfsdk:"arn"`
Name types.String `tfsdk:"name"`
ChannelGroupName types.String `tfsdk:"channel_group_name"`
Description types.String `tfsdk:"description"`
InputType types.String `tfsdk:"input_type"`
IngestEndpoints fwtypes.SetNestedObjectValueOf[ingestEndpointModel] `tfsdk:"ingest_endpoints"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
}
type ingestEndpointModel struct {
Id types.String `tfsdk:"id"`
Url types.String `tfsdk:"url"`
}
Schema
{
Attributes: map[string]schema.Attribute{
names.AttrARN: framework.ARNAttributeComputedOnly(),
"channel_group_name": schema.StringAttribute{
Required: true,
},
names.AttrName: schema.StringAttribute{
Required: true,
},
names.AttrDescription: schema.StringAttribute{
Optional: true,
},
"input_type": schema.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf(func() []string {
values := awstypes.InputType("").Values()
strValues := make([]string, len(values))
for i, v := range values {
strValues[i] = string(v)
}
return strValues
}()...),
},
},
names.AttrTags: tftags.TagsAttribute(),
names.AttrTagsAll: tftags.TagsAttributeComputedOnly(),
},
Blocks: map[string]schema.Block{
"ingest_endpoints": schema.SetNestedBlock{
CustomType: fwtypes.NewSetNestedObjectTypeOf[ingestEndpointModel](ctx),
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
Validators: []validator.Set{
setvalidator.SizeAtMost(1),
},
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Computed: true,
},
"url": schema.StringAttribute{
Computed: true,
},
},
},
},
},
}
This ‘ingest_endpoints’ property is intended to not be surfaced to the user but instead to be computed from create handler. It will always be set from handler and cannot change. I have tried this functionality both as a ‘Set’ and ‘List’, different permutations of Computed, Required, Validators & PlanModifiers but i consistency receive the Error
Error: Provider produced inconsistent result after apply
When applying changes to aws_media_packagev2_channel.channel, provider
"provider[\"registry.terraform.io/hashicorp/aws\"]" produced an unexpected
new value: .ingest_endpoints: block set length changed from 0 to 2.
This is a bug in the provider, which should be reported in the provider's own