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

azurerm_container_app - fix validation for container app name and container names #28528

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/services/containerapps/validate/validate.go
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ func ContainerAppName(i interface{}, k string) (warnings []string, errors []erro
return
}

if matched := regexp.MustCompile(`^([a-z])[a-z0-9-]{0,58}[a-z0-9]?$`).Match([]byte(v)); !matched || strings.HasSuffix(v, "-") || strings.Contains(v, "--") {
if matched := regexp.MustCompile(`^([a-z])[a-z0-9-]{0,30}[a-z0-9]?$`).Match([]byte(v)); !matched || strings.HasSuffix(v, "-") || strings.Contains(v, "--") {
errors = append(errors, fmt.Errorf("%q must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character and cannot have '--'. The length must not be more than 32 characters", k))
return
}
@@ -118,7 +118,7 @@ func ContainerAppContainerName(i interface{}, k string) (warnings []string, erro
return
}

if matched := regexp.MustCompile(`^([a-zA-Z0-9])[a-zA-Z0-9-.]{0,254}[a-z]?$`).Match([]byte(v)); !matched || strings.HasSuffix(v, "-") {
if matched := regexp.MustCompile(`^([a-z])[a-z0-9-.]{0,58}[a-z]$`).Match([]byte(v)); !matched || strings.HasSuffix(v, "-") {
errors = append(errors, fmt.Errorf("%q must consist of lower case alphanumeric characters, '-', or '.', start with an alphabetic character, and end with an alphanumeric character. The length must not be more than 60 characters", k))
}

101 changes: 101 additions & 0 deletions internal/services/containerapps/validate/validate_test.go
Original file line number Diff line number Diff line change
@@ -324,3 +324,104 @@ func TestContainerAppScaleRuleConcurrentRequests(t *testing.T) {
}
}
}

func TestValidateContainerAppName(t *testing.T) {
cases := []struct {
Input string
Valid bool
}{
{
Input: "",
},
{
Input: "-",
},
{
Input: "9",
},
{
Input: "a-",
},
{
Input: "a.",
},
{
Input: "a--a",
},
{
Input: "Cannothavecapitals",
},
{
Input: "a-a",
Valid: true,
},
{
Input: "val-1-id",
Valid: true,
},
{
Input: "invalid12345678901234567890123456",
},
}

for _, tc := range cases {
t.Logf("[DEBUG] Testing Value %s", tc.Input)
_, errors := ContainerAppName(tc.Input, "test")
valid := len(errors) == 0

if tc.Valid != valid {
t.Fatalf("Expected %t but got %t for %s: %+v", tc.Valid, valid, tc.Input, errors)
}
}
}

func TestValidateContainerAppContainerName(t *testing.T) {
cases := []struct {
Input string
Valid bool
}{
{
Input: "",
},
{
Input: "-",
},
{
Input: "9",
},
{
Input: "a-",
},
{
Input: "a.",
},
{
Input: "a--a",
Valid: true,
},
{
Input: "Cannothavecapitals",
},
{
Input: "a-a",
Valid: true,
},
{
Input: "val-1-id",
Valid: true,
},
{
Input: "invalid12345678901234567890123456",
},
}

for _, tc := range cases {
t.Logf("[DEBUG] Testing Value %s", tc.Input)
_, errors := ContainerAppContainerName(tc.Input, "test")
valid := len(errors) == 0

if tc.Valid != valid {
t.Fatalf("Expected %t but got %t for %s: %+v", tc.Valid, valid, tc.Input, errors)
}
}
}