diff --git a/internal/providers/pluginfw/tfschema/customizable_schema.go b/internal/providers/pluginfw/tfschema/customizable_schema.go index b7051b450..b2837371a 100644 --- a/internal/providers/pluginfw/tfschema/customizable_schema.go +++ b/internal/providers/pluginfw/tfschema/customizable_schema.go @@ -61,6 +61,8 @@ func (s *CustomizableSchema) AddValidator(v any, path ...string) *CustomizableSc return a.AddValidator(v.(validator.List)) case ListNestedAttributeBuilder: return a.AddValidator(v.(validator.List)) + case ListNestedBlockBuilder: + return a.AddValidator(v.(validator.List)) case MapAttributeBuilder: return a.AddValidator(v.(validator.Map)) case MapNestedAttributeBuilder: diff --git a/internal/providers/pluginfw/tfschema/customizable_schema_test.go b/internal/providers/pluginfw/tfschema/customizable_schema_test.go index 6de3c0002..0b6fc49eb 100644 --- a/internal/providers/pluginfw/tfschema/customizable_schema_test.go +++ b/internal/providers/pluginfw/tfschema/customizable_schema_test.go @@ -115,6 +115,28 @@ func TestCustomizeSchemaSetReadOnly(t *testing.T) { assert.True(t, scm.Attributes["map"].IsComputed()) } +type testTfSdkListNestedAttribute struct { + List types.List `tfsdk:"list"` +} + +func (testTfSdkListNestedAttribute) GetComplexFieldTypes(context.Context) map[string]reflect.Type { + return map[string]reflect.Type{ + "list": reflect.TypeOf(NestedTfSdk{}), + } +} + +func TestCustomizeSchemaSetReadOnly_RecursivelySetsFieldsOfListNestedAttributes(t *testing.T) { + scm := ResourceStructToSchema(context.Background(), testTfSdkListNestedAttribute{}, func(c CustomizableSchema) CustomizableSchema { + c.ConvertToAttribute("list").SetReadOnly("list") + return c + }) + for _, field := range []string{"name", "enabled"} { + assert.True(t, !scm.Attributes["list"].(schema.ListNestedAttribute).NestedObject.Attributes[field].IsOptional()) + assert.True(t, !scm.Attributes["list"].(schema.ListNestedAttribute).NestedObject.Attributes[field].IsRequired()) + assert.True(t, scm.Attributes["list"].(schema.ListNestedAttribute).NestedObject.Attributes[field].IsComputed()) + } +} + func TestCustomizeSchemaAddValidator(t *testing.T) { scm := ResourceStructToSchema(context.Background(), TestTfSdk{}, func(c CustomizableSchema) CustomizableSchema { c.AddValidator(stringLengthBetweenValidator{}, "description") diff --git a/internal/providers/pluginfw/tfschema/list_nested_attribute.go b/internal/providers/pluginfw/tfschema/list_nested_attribute.go index 9cd882990..adc97a7ed 100644 --- a/internal/providers/pluginfw/tfschema/list_nested_attribute.go +++ b/internal/providers/pluginfw/tfschema/list_nested_attribute.go @@ -85,6 +85,7 @@ func (a ListNestedAttributeBuilder) SetReadOnly() AttributeBuilder { a.Computed = true a.Optional = false a.Required = false + a.NestedObject.SetReadOnly() return a } diff --git a/internal/providers/pluginfw/tfschema/nested_attribute_object.go b/internal/providers/pluginfw/tfschema/nested_attribute_object.go index bf9f63923..f12702f7b 100644 --- a/internal/providers/pluginfw/tfschema/nested_attribute_object.go +++ b/internal/providers/pluginfw/tfschema/nested_attribute_object.go @@ -25,3 +25,9 @@ func (a NestedAttributeObject) BuildResourceAttribute() schema.NestedAttributeOb Attributes: resourceAttributes, } } + +func (a NestedAttributeObject) SetReadOnly() { + for attr, attrV := range a.Attributes { + a.Attributes[attr] = attrV.SetReadOnly() + } +}