Proposed solution is to initialize a nil variable first then perform a length check:
// Convert NotIn to a go slice, start off from an uninitialized slice so that the value is nil if the input is empty.
var notIn []*string
if len(rssv.NotIn.Elements()) != 0 {
var err error
notIn, err = frameworktype.SliceOfPrimitiveToGo[string](ctx, rssv.NotIn.Elements())
if err != nil {
resp.Diagnostics.AddError(
"convertPolicyAssignmentResourceSelectorsToSdkType: error",
fmt.Sprintf("unable to convert ResourceSelectorSelectorsValue.NotIn elements to Go slice: %s", err.Error()),
)
return nil
}
}
Source Azure/terraform-azurerm-avm-ptn-alz#132#issuecomment-2439924137
Thanks to @JWilkinsonMB
repro code:
Apply output:
Suspect code:
https://github.com/Azure/terraform-provider-alz/blob/8203c5dd1fea8e754e69b6ebc75769e4c84e4d31/internal/provider/architecture_data_source.go#L333-L363
Proposed solution is to initialize a nil variable first then perform a length check: