Skip to content

Commit

Permalink
Merge pull request #10693 from kangaechu/add-validation-to-ElbName
Browse files Browse the repository at this point in the history
Add validation to the name of aws_elb resource.
  • Loading branch information
anGie44 authored Nov 24, 2021
2 parents 1e6d287 + 09e1b78 commit dc7cabb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/10693.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_lb: Update `name` and `name_prefix` plan-time validation to exclude `"internal-"`
```
8 changes: 8 additions & 0 deletions internal/service/elbv2/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func validName(v interface{}, k string) (ws []string, errors []error) {
errors = append(errors, fmt.Errorf(
"%q cannot end with a hyphen: %q", k, value))
}
if regexp.MustCompile(`^internal-`).MatchString(value) {
errors = append(errors, fmt.Errorf(
`%q cannot begin with "internal-": %q`, k, value))
}
return
}

Expand All @@ -47,6 +51,10 @@ func validNamePrefix(v interface{}, k string) (ws []string, errors []error) {
errors = append(errors, fmt.Errorf(
"%q cannot begin with a hyphen: %q", k, value))
}
if regexp.MustCompile(`^internal-`).MatchString(value) {
errors = append(errors, fmt.Errorf(
`%q cannot begin with "internal-": %q`, k, value))
}
return
}

Expand Down
2 changes: 2 additions & 0 deletions internal/service/elbv2/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestValidName(t *testing.T) {
"tf-test-elb-tf-test-elb-tf-test-elb",
"-tf-test-elb",
"tf-test-elb-",
"internal-tf-test-elb",
}

for _, s := range invalidNames {
Expand All @@ -49,6 +50,7 @@ func TestValidNamePrefix(t *testing.T) {
"tf.test.elb.",
"tf-test",
"-test",
"internal-",
}

for _, s := range invalidNamePrefixes {
Expand Down

0 comments on commit dc7cabb

Please sign in to comment.