diff --git a/provider/clusterrosaclassic/cluster_rosa_classic_resource.go b/provider/clusterrosaclassic/cluster_rosa_classic_resource.go index 90533f6c..f3cbfbe0 100644 --- a/provider/clusterrosaclassic/cluster_rosa_classic_resource.go +++ b/provider/clusterrosaclassic/cluster_rosa_classic_resource.go @@ -19,6 +19,7 @@ import ( "context" "errors" "fmt" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "net/http" "sort" "strings" @@ -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 2a61e04f..90b57d7c 100644 --- a/subsystem/cluster_resource_rosa_test.go +++ b/subsystem/cluster_resource_rosa_test.go @@ -1046,6 +1046,30 @@ 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() { @@ -1740,6 +1764,7 @@ var _ = Describe("rhcs_cluster_rosa_classic - create", func() { CombineHandlers( VerifyRequest(http.MethodPatch, "/api/clusters_mgmt/v1/clusters/123"), VerifyJQ(`.additional_trust_bundle`, "123"), + VerifyJQ(`.proxy.https_proxy`, "https://proxy.com"), RespondWithPatchedJSON(http.StatusCreated, template, `[ { "op": "add", @@ -1759,6 +1784,13 @@ var _ = Describe("rhcs_cluster_rosa_classic - create", func() { } } }, + { + "op": "add", + "path": "/proxy", + "value": { + "https_proxy" : "https://proxy.com" + } + }, { "op": "add", "path": "/", @@ -1775,6 +1807,7 @@ var _ = Describe("rhcs_cluster_rosa_classic - create", func() { cloud_region = "us-west-1" aws_account_id = "123" proxy = { + https_proxy = "https://proxy.com", additional_trust_bundle = "123", } sts = { @@ -1980,27 +2013,6 @@ var _ = Describe("rhcs_cluster_rosa_classic - create", func() { } } } - `) - Expect(terraform.Apply()).NotTo(BeZero()) - - // Expected at least one of the following: http-proxy, https-proxy, additional-trust-bundle - terraform.Source(` - resource "rhcs_cluster_rosa_classic" "my_cluster" { - name = "my-cluster" - cloud_region = "us-west-1" - aws_account_id = "123" - proxy = { - } - sts = { - operator_role_prefix = "test" - role_arn = "", - support_role_arn = "", - instance_iam_roles = { - master_role_arn = "", - worker_role_arn = "", - } - } - } `) Expect(terraform.Apply()).NotTo(BeZero()) })