Skip to content

Commit

Permalink
OCM-3794: Cluster name length should be at most 15 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
bardielle committed Sep 21, 2023
1 parent 767210a commit 7c77960
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions provider/clusterrosaclassic/cluster_rosa_classic_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
},
Expand Down
25 changes: 25 additions & 0 deletions subsystem/cluster_resource_rosa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7c77960

Please sign in to comment.