diff --git a/go.mod b/go.mod index 3d720939c..0c88e8ab0 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect github.com/hashicorp/terraform-json v0.23.0 // indirect + github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.3 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect diff --git a/internal/providers/pluginfw/tfschema/struct_to_schema.go b/internal/providers/pluginfw/tfschema/struct_to_schema.go index 7d8f0c988..3acb5a999 100644 --- a/internal/providers/pluginfw/tfschema/struct_to_schema.go +++ b/internal/providers/pluginfw/tfschema/struct_to_schema.go @@ -9,9 +9,11 @@ import ( "github.com/databricks/terraform-provider-databricks/common" tfcommon "github.com/databricks/terraform-provider-databricks/internal/providers/pluginfw/common" "github.com/databricks/terraform-provider-databricks/internal/tfreflect" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" dataschema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -87,8 +89,13 @@ func typeToSchema(ctx context.Context, v reflect.Value) NestedBlockObject { // Note: Objects are treated as lists for backward compatibility with the Terraform v5 protocol (i.e. SDKv2 resources). switch value.(type) { case types.List: + validators := []validator.List{} + if structTag.singleObject { + validators = append(validators, listvalidator.SizeAtMost(1)) + } scmBlock[fieldName] = ListNestedBlockBuilder{ NestedObject: typeToSchema(ctx, fieldValue), + Validators: validators, } case types.Map: scmAttr[fieldName] = MapNestedAttributeBuilder{