Merge pull request #9468 from wendorf/arm_loadbalancer_rule_naming_fix

Azure RM loadbalancer rules have correct naming restrictions
This commit is contained in:
Paul Stack 2016-10-25 15:12:26 +01:00 committed by GitHub
commit d485512d71
2 changed files with 15 additions and 7 deletions

View File

@ -332,9 +332,9 @@ func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalan
func validateArmLoadBalancerRuleName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[a-zA-Z._-]+$`).MatchString(value) {
if !regexp.MustCompile(`^[a-zA-Z_0-9.-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only word characters and hyphens allowed in %q: %q",
"only word characters, numbers, underscores, periods, and hyphens allowed in %q: %q",
k, value))
}
@ -347,14 +347,14 @@ func validateArmLoadBalancerRuleName(v interface{}, k string) (ws []string, erro
errors = append(errors, fmt.Errorf(
"%q cannot be an empty string: %q", k, value))
}
if !regexp.MustCompile(`[a-zA-Z]$`).MatchString(value) {
if !regexp.MustCompile(`[a-zA-Z0-9_]$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must end with a word character: %q", k, value))
"%q must end with a word character, number, or underscore: %q", k, value))
}
if !regexp.MustCompile(`^[a-zA-Z]`).MatchString(value) {
if !regexp.MustCompile(`^[a-zA-Z0-9]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must start with a word character: %q", k, value))
"%q must start with a word character or number: %q", k, value))
}
return

View File

@ -25,7 +25,7 @@ func TestResourceAzureRMLoadBalancerRuleNameLabel_validation(t *testing.T) {
ErrCount: 1,
},
{
Value: "test123test",
Value: "test#test",
ErrCount: 1,
},
{
@ -48,6 +48,14 @@ func TestResourceAzureRMLoadBalancerRuleNameLabel_validation(t *testing.T) {
Value: "TestRule",
ErrCount: 0,
},
{
Value: "Test123Rule",
ErrCount: 0,
},
{
Value: "TestRule",
ErrCount: 0,
},
}
for _, tc := range cases {