diff --git a/provider/clusterrosaclassic/cluster_rosa_classic_resource.go b/provider/clusterrosaclassic/cluster_rosa_classic_resource.go index 90533f6c..02eb5af3 100644 --- a/provider/clusterrosaclassic/cluster_rosa_classic_resource.go +++ b/provider/clusterrosaclassic/cluster_rosa_classic_resource.go @@ -29,6 +29,7 @@ import ( semver "github.com/hashicorp/go-version" ver "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -123,6 +124,9 @@ func (r *ClusterRosaClassicResource) Schema(ctx context.Context, req resource.Sc "name": schema.StringAttribute{ Description: "Name of the cluster. Cannot exceed 15 characters in length.", Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtMost(15), + }, PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, diff --git a/subsystem/cluster_resource_rosa_test.go b/subsystem/cluster_resource_rosa_test.go index 023c8230..a44ce587 100644 --- a/subsystem/cluster_resource_rosa_test.go +++ b/subsystem/cluster_resource_rosa_test.go @@ -1046,6 +1046,31 @@ var _ = Describe("rhcs_cluster_rosa_classic - create", func() { `) Expect(terraform.Apply()).ToNot(BeZero()) }) + + It("Should fail cluster creation when cluster name length is more than 15", func() { + // Run the apply command: + terraform.Source(` + resource "rhcs_cluster_rosa_classic" "my_cluster" { + name = "my-cluster-234567" + cloud_region = "us-west-1" + aws_account_id = "123" + properties = { + cluster_name = "too_long" + } + sts = { + operator_role_prefix = "test" + role_arn = "", + support_role_arn = "", + instance_iam_roles = { + master_role_arn = "", + worker_role_arn = "", + } + } + } + `) + Expect(terraform.Apply()).ToNot(BeZero()) + + }) Context("Test destroy cluster", func() { BeforeEach(func() {