Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix EKS cluster name regex #35874

Merged
merged 5 commits into from
Feb 20, 2024

Conversation

acwwat
Copy link
Contributor

@acwwat acwwat commented Feb 18, 2024

Description

This PR is to fix the regex pattern for the EKS cluster name that is included in the documentation for numerous EKS-related resources.

I'd also like to ask the maintainers to see whether it makes sense to just remove the regex from the non-cluster resource docs. Once the EKS cluster is created (and it makes sense to provide the regex there), the name is simply referenced by other resources so I don't think providing the exact format is super useful. Let me know what you think - I can update the PR to remove them if you think it makes sense. Thanks.

Relations

Closes #35843

References

Referred to the API reference for the cluster name regex.

Output from Acceptance Testing

$ make testacc TESTS=TestValidClusterName PKG=eks
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/eks/... -v -count 1 -parallel 20 -run='TestValidClusterName'  -timeout 360m
=== RUN   TestValidClusterName
=== PAUSE TestValidClusterName
=== CONT  TestValidClusterName
--- PASS: TestValidClusterName (0.00s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/eks        0.186s

$

Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added size/XS Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/eks Issues and PRs that pertain to the eks service. labels Feb 18, 2024
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 18, 2024
@mattburgess
Copy link
Collaborator

Looks like the validation function is actually incorrect as well.

Feel free to include the following change in this PR @acwwat :

diff --git a/internal/service/eks/validate.go b/internal/service/eks/validate.go
index 9195a044cb..3bb4b598c6 100644
--- a/internal/service/eks/validate.go
+++ b/internal/service/eks/validate.go
@@ -17,7 +17,7 @@ func validClusterName(v interface{}, k string) (ws []string, errors []error) {
        }
 
        // https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html#API_CreateCluster_RequestSyntax
-       pattern := `^[0-9A-Za-z][0-9A-Za-z_-]+$`
+       pattern := `^[0-9A-Za-z][0-9A-Za-z_-]*$`
        if !regexache.MustCompile(pattern).MatchString(value) {
                errors = append(errors, fmt.Errorf(
                        "%q doesn't comply with restrictions (%q): %q",
diff --git a/internal/service/eks/validate_test.go b/internal/service/eks/validate_test.go
index f6627cc653..777f7aa024 100644
--- a/internal/service/eks/validate_test.go
+++ b/internal/service/eks/validate_test.go
@@ -20,6 +20,10 @@ func TestValidClusterName(t *testing.T) {
                        Value:    "my-valid-eks-cluster_1_dev",
                        ErrCount: 0,
                },
+               {
+                       Value:    "a",
+                       ErrCount: 0,
+               },
                {
                        Value:    `_invalid`,
                        ErrCount: 1,

The new test fails on current main:

$ make testacc TESTS=TestValidClusterName PKG=eks
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/eks/... -v -count 1 -parallel 20 -run='TestValidClusterName'  -timeout 360m
=== RUN   TestValidClusterName
=== PAUSE TestValidClusterName
=== CONT  TestValidClusterName
    validate_test.go:65: Expected the EKS Cluster Name to trigger a validation error: a, expected 0, got 1 errors
--- FAIL: TestValidClusterName (0.00s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/eks	0.362s
FAIL
make: *** [GNUmakefile:359: testacc] Error 1

And passes with the regex change applied:

$ make testacc TESTS=TestValidClusterName PKG=eks
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/eks/... -v -count 1 -parallel 20 -run='TestValidClusterName'  -timeout 360m
=== RUN   TestValidClusterName
=== PAUSE TestValidClusterName
=== CONT  TestValidClusterName
--- PASS: TestValidClusterName (0.00s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/eks	0.330s

@mattburgess
Copy link
Collaborator

Oh, and as to your suggestion about removing the regex from all but the cluster resource docs I'd definitely agree although I'm a mere contributor not a maintainer.

@acwwat acwwat changed the title docs: Fix cluster name regex for all EKS resources fix: Fix EKS cluster name regex Feb 20, 2024
@github-actions github-actions bot added the tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. label Feb 20, 2024
@acwwat acwwat force-pushed the d-aws_eks-fix_cluster_name_regex branch from 43c93e1 to 8822a47 Compare February 20, 2024 06:07
@acwwat
Copy link
Contributor Author

acwwat commented Feb 20, 2024

@mattburgess Thanks for catching the regex issue in the code. I've incorporated your suggested changes to the code. I've also decided to just remove the regex from the non-cluster resource docs for cleanliness and ease of maintenance going forward.

@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Feb 20, 2024
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀.

@ewbankkit
Copy link
Contributor

@acwwat Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 824ced2 into hashicorp:main Feb 20, 2024
43 checks passed
@github-actions github-actions bot added this to the v5.38.0 milestone Feb 20, 2024
@acwwat acwwat deleted the d-aws_eks-fix_cluster_name_regex branch February 22, 2024 08:01
Copy link

This functionality has been released in v5.38.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. service/eks Issues and PRs that pertain to the eks service. size/XS Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Docs]: Incorrect regex on EKS cluster name argument
3 participants