diff --git a/internal/schema/resource_kafka_cluster_v2/kafka_cluster_v2_resource_gen.go b/internal/schema/resource_kafka_cluster_v2/kafka_cluster_v2_resource_gen.go index d14ba23..24efd13 100644 --- a/internal/schema/resource_kafka_cluster_v2/kafka_cluster_v2_resource_gen.go +++ b/internal/schema/resource_kafka_cluster_v2/kafka_cluster_v2_resource_gen.go @@ -153,7 +153,10 @@ func KafkaClusterV2ResourceSchema(ctx context.Context) schema.Schema { Computed: true, Description: "Conduktor Gateway Virtual cluster name (default `passthrough`). Only used if type is `Gateway`", MarkdownDescription: "Conduktor Gateway Virtual cluster name (default `passthrough`). Only used if type is `Gateway`", - Default: stringdefault.StaticString("passthrough"), + Validators: []validator.String{ + validation.NonEmptyString(), + }, + Default: stringdefault.StaticString("passthrough"), }, }, CustomType: KafkaFlavorType{ diff --git a/internal/schema/validation/non_empty_string.go b/internal/schema/validation/non_empty_string.go new file mode 100644 index 0000000..565b113 --- /dev/null +++ b/internal/schema/validation/non_empty_string.go @@ -0,0 +1,49 @@ +package validation + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = nonEmpty{} + +// stringNonEmpty validates that a string Attribute's length is at least a certain value. +type nonEmpty struct { +} + +// Description describes the validation in plain text formatting. +func (validator nonEmpty) Description(_ context.Context) string { + return "string should not be empty" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator nonEmpty) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v nonEmpty) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + if len(value) == 0 { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( + request.Path, + v.Description(ctx), + "\"\"", + )) + return + } +} + +// NonEmptyString returns a validator which ensures that any configured +// attribute value a not empty string. Null (unconfigured) and unknown (known after apply) +// values are skipped. +func NonEmptyString() validator.String { + return nonEmpty{} +} diff --git a/provider_code_spec.json b/provider_code_spec.json index e501d5c..a3754bf 100644 --- a/provider_code_spec.json +++ b/provider_code_spec.json @@ -989,7 +989,19 @@ ], "schema_definition": "stringdefault.StaticString(\"passthrough\")" } - } + }, + "validators": [ + { + "custom": { + "imports": [ + { + "path": "github.com/conduktor/terraform-provider-conduktor/internal/schema/validation" + } + ], + "schema_definition": "validation.NonEmptyString()" + } + } + ] } }, {