Skip to content

Commit

Permalink
Remove acr validator from scopemaps (#11784)
Browse files Browse the repository at this point in the history
Remove incorrect validator from scopemaps, as mentioned in #11783
  • Loading branch information
LP0101 authored and favoretti committed May 26, 2021
1 parent 41eb286 commit c745fec
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func resourceContainerRegistryScopeMap() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ContainerRegistryName,
ValidateFunc: validate.ContainerRegistryScopeMapName,
},

"description": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package validate

import (
"fmt"
"regexp"
)

func ContainerRegistryScopeMapName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[a-zA-Z0-9\-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"alpha numeric characters and hyphens only are allowed in %q: %q", k, value))
}

if 5 > len(value) {
errors = append(errors, fmt.Errorf("%q cannot be less than 5 characters: %q", k, value))
}

if len(value) >= 50 {
errors = append(errors, fmt.Errorf("%q cannot be longer than 50 characters: %q %d", k, value, len(value)))
}

return warnings, errors
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package validate_test

import (
"testing"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/validate"
)

func TestContainerRegistryScopeMapName(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "four",
ErrCount: 1,
},
{
Value: "5five",
ErrCount: 0,
},
{
Value: "five-123",
ErrCount: 0,
},
{
Value: "hello-world",
ErrCount: 0,
},
{
Value: "hello_world",
ErrCount: 1,
},
{
Value: "helloWorld",
ErrCount: 0,
},
{
Value: "helloworld12",
ErrCount: 0,
},
{
Value: "hello@world",
ErrCount: 1,
},

{
Value: "qfvbdsbvipqdbwsbddbdcwqffewsqwcdw21ddwqwd3324120",
ErrCount: 0,
},
{
Value: "qfvbdsbvipqdbwsbddbdcwqffewsqwcdw21ddwqwd33241202",
ErrCount: 0,
},
{
Value: "qfvbdsbvipqdbwsbddbdcwqfjjfewsqwcdw21ddwqwd3324120fadfadf",
ErrCount: 1,
},
}

for _, tc := range cases {
_, errors := validate.ContainerRegistryScopeMapName(tc.Value, "azurerm_container_registry_scope_map")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected the Azure RM Container Registry Token Name to trigger a validation error: %v", errors)
}
}
}

0 comments on commit c745fec

Please sign in to comment.