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 ebd5b1f commit 731365a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 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 @@ -19,6 +19,7 @@ import (
"context"
"errors"
"fmt"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"net/http"
"sort"
"strings"
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
54 changes: 33 additions & 21 deletions subsystem/cluster_resource_rosa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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",
Expand All @@ -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": "/",
Expand All @@ -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 = {
Expand Down Expand Up @@ -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())
})
Expand Down

0 comments on commit 731365a

Please sign in to comment.