From 957d1cb3a87cf370c65988315bc203f5f6df8d44 Mon Sep 17 00:00:00 2001 From: Dan Wendorf Date: Wed, 19 Oct 2016 17:58:44 -0700 Subject: [PATCH] Azure RM loadbalancer rules have correct naming restrictions - The name cannot be empty - The name cannot be more than 80 characters - The name must begin with a letter or number - The name must end with a letter, number, or underscore - The name must only contain letters, numbers, underscores, periods, or hyphens --- .../azurerm/resource_arm_loadbalancer_rule.go | 12 ++++++------ .../azurerm/resource_arm_loadbalancer_rule_test.go | 10 +++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go index 3f2839ee6..997c1ccd6 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go @@ -324,9 +324,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)) } @@ -339,14 +339,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 diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_rule_test.go b/builtin/providers/azurerm/resource_arm_loadbalancer_rule_test.go index 482444121..8415c9a53 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_rule_test.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_rule_test.go @@ -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 {