From 7c4d61537eb06560c8e7fbec675a9991ebb2178a Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Wed, 20 May 2020 12:56:02 +0800 Subject: [PATCH 1/3] Fix #6920 --- azurerm/internal/services/compute/validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/compute/validation.go b/azurerm/internal/services/compute/validation.go index b10ac6771fb7..ca6704888477 100644 --- a/azurerm/internal/services/compute/validation.go +++ b/azurerm/internal/services/compute/validation.go @@ -35,7 +35,7 @@ func ValidateVmName(i interface{}, k string) (warnings []string, errors []error) errors = append(errors, fmt.Errorf("%q must begin with an alphanumeric character", k)) } - if matched := regexp.MustCompile(`[a-z0-9_]$`).Match([]byte(v)); !matched { + if matched := regexp.MustCompile(`[a-zA-Z0-9_]$`).Match([]byte(v)); !matched { errors = append(errors, fmt.Errorf("%q must end with an alphanumeric character or underscore", k)) } From 2d3ef5dba4af1c5f1d843bdc520a5b46705e5f6b Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Wed, 20 May 2020 16:34:11 +0800 Subject: [PATCH 2/3] Resolve comments --- azurerm/internal/services/compute/validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/compute/validation.go b/azurerm/internal/services/compute/validation.go index ca6704888477..24ca7a2b9e56 100644 --- a/azurerm/internal/services/compute/validation.go +++ b/azurerm/internal/services/compute/validation.go @@ -35,7 +35,7 @@ func ValidateVmName(i interface{}, k string) (warnings []string, errors []error) errors = append(errors, fmt.Errorf("%q must begin with an alphanumeric character", k)) } - if matched := regexp.MustCompile(`[a-zA-Z0-9_]$`).Match([]byte(v)); !matched { + if matched := regexp.MustCompile(`\w$`).Match([]byte(v)); !matched { errors = append(errors, fmt.Errorf("%q must end with an alphanumeric character or underscore", k)) } From afd83021290f9b19195682a3153616a920bb53a8 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Wed, 20 May 2020 16:44:01 +0800 Subject: [PATCH 3/3] Test cases added --- azurerm/internal/services/compute/validation_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/azurerm/internal/services/compute/validation_test.go b/azurerm/internal/services/compute/validation_test.go index e30c65d49ff4..b11f960fec76 100644 --- a/azurerm/internal/services/compute/validation_test.go +++ b/azurerm/internal/services/compute/validation_test.go @@ -72,6 +72,16 @@ func TestValidateVmName(t *testing.T) { input: "12345", expected: false, }, + { + // can start with upper case letter + input: "Test", + expected: true, + }, + { + // can end with upper case letter + input: "TEST", + expected: true, + }, } for _, v := range testData {