diff --git a/stackit/internal/services/telemetrylink/link/resource.go b/stackit/internal/services/telemetrylink/link/resource.go index 9a30a4c25..9052fa1d9 100644 --- a/stackit/internal/services/telemetrylink/link/resource.go +++ b/stackit/internal/services/telemetrylink/link/resource.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "regexp" "strings" "time" @@ -179,10 +180,24 @@ func (r *telemetryLinkResource) Schema(_ context.Context, _ resource.SchemaReque "display_name": schema.StringAttribute{ Description: schemaDescriptions["display_name"], Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 32), + stringvalidator.RegexMatches( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`), + "The display name must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.", + ), + }, }, "description": schema.StringAttribute{ Description: schemaDescriptions["description"], Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtMost(1024), + stringvalidator.RegexMatches( + regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9 \-]*)?$`), + "The description must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.", + ), + }, }, "region": schema.StringAttribute{ Description: schemaDescriptions["region"], diff --git a/stackit/internal/services/telemetryrouter/accesstoken/resource.go b/stackit/internal/services/telemetryrouter/accesstoken/resource.go index a4659171f..5021a8acc 100644 --- a/stackit/internal/services/telemetryrouter/accesstoken/resource.go +++ b/stackit/internal/services/telemetryrouter/accesstoken/resource.go @@ -5,9 +5,11 @@ import ( "errors" "fmt" "net/http" + "regexp" "strings" "time" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -172,6 +174,13 @@ func (r *telemetryRouterAccessTokenResource) Schema(_ context.Context, _ resourc "display_name": schema.StringAttribute{ Description: schemaDescriptions["display_name"], Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 32), + stringvalidator.RegexMatches( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`), + "The display name must start with an alphanumeric character and can contain only letters, numbers, spaces, and hyphens.", + ), + }, }, "region": schema.StringAttribute{ Description: schemaDescriptions["region"], @@ -185,6 +194,13 @@ func (r *telemetryRouterAccessTokenResource) Schema(_ context.Context, _ resourc "description": schema.StringAttribute{ Description: schemaDescriptions["description"], Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtMost(1024), + stringvalidator.RegexMatches( + regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9 \-]*)?$`), + "The description must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.", + ), + }, }, "ttl": schema.Int32Attribute{ Description: schemaDescriptions["ttl"], diff --git a/stackit/internal/services/telemetryrouter/destination/resource.go b/stackit/internal/services/telemetryrouter/destination/resource.go index b4ecb3de3..638f4b064 100644 --- a/stackit/internal/services/telemetryrouter/destination/resource.go +++ b/stackit/internal/services/telemetryrouter/destination/resource.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "regexp" "strings" "time" @@ -293,6 +294,13 @@ func (r *telemetryRouterDestinationResource) Schema(_ context.Context, _ resourc "display_name": schema.StringAttribute{ Description: schemaDescriptions["display_name"], Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 32), + stringvalidator.RegexMatches( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`), + "The display name must start with an alphanumeric character and can contain only letters, numbers, spaces, and hyphens.", + ), + }, }, "config": schema.SingleNestedAttribute{ Description: schemaDescriptions["config"], @@ -420,6 +428,13 @@ func (r *telemetryRouterDestinationResource) Schema(_ context.Context, _ resourc "description": schema.StringAttribute{ Description: schemaDescriptions["description"], Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtMost(1024), + stringvalidator.RegexMatches( + regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9 \-]*)?$`), + "The description must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.", + ), + }, }, "creation_time": schema.StringAttribute{ Description: schemaDescriptions["creation_time"], diff --git a/stackit/internal/services/telemetryrouter/instance/resource.go b/stackit/internal/services/telemetryrouter/instance/resource.go index 8fdcf1134..bc58e371d 100644 --- a/stackit/internal/services/telemetryrouter/instance/resource.go +++ b/stackit/internal/services/telemetryrouter/instance/resource.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "net/http" + "regexp" "strings" "time" @@ -195,6 +196,13 @@ func (r *telemetryRouterInstanceResource) Schema(_ context.Context, _ resource.S "display_name": schema.StringAttribute{ Description: schemaDescriptions["display_name"], Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 32), + stringvalidator.RegexMatches( + regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9 \-]*$`), + "The display name must start with an alphanumeric character and can contain only letters, numbers, spaces, and hyphens.", + ), + }, }, "region": schema.StringAttribute{ Description: schemaDescriptions["region"], @@ -208,6 +216,13 @@ func (r *telemetryRouterInstanceResource) Schema(_ context.Context, _ resource.S "description": schema.StringAttribute{ Description: schemaDescriptions["description"], Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtMost(1024), + stringvalidator.RegexMatches( + regexp.MustCompile(`^([a-zA-Z0-9][a-zA-Z0-9 \-]*)?$`), + "The description must start with an alphanumeric character and can only contain letters, numbers, spaces, and hyphens.", + ), + }, }, "filter": schema.SingleNestedAttribute{ Description: schemaDescriptions["filter"],