Skip to content

Commit

Permalink
allow azurerm_linux_virtual_machine_scale_set computer_name_prefix to
Browse files Browse the repository at this point in the history
end with dashes
  • Loading branch information
bchess committed Nov 5, 2020
1 parent 0932a0c commit 4130c34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions azurerm/internal/services/compute/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ func ValidateVmName(i interface{}, k string) (warnings []string, errors []error)

func ValidateLinuxComputerNameFull(i interface{}, k string) (warnings []string, errors []error) {
// Linux host name cannot exceed 64 characters in length
return ValidateLinuxComputerName(i, k, 64)
return ValidateLinuxComputerName(i, k, 64, false)
}

func ValidateLinuxComputerNamePrefix(i interface{}, k string) (warnings []string, errors []error) {
// Linux host name prefix cannot exceed 58 characters in length
return ValidateLinuxComputerName(i, k, 58)
return ValidateLinuxComputerName(i, k, 58, true)
}

func ValidateOrchestratedVMSSName(i interface{}, k string) (warnings []string, errors []error) {
return ValidateVmName(i, k)
}

func ValidateLinuxComputerName(i interface{}, k string, maxLength int) (warnings []string, errors []error) {
func ValidateLinuxComputerName(i interface{}, k string, maxLength int, allowDashSuffix bool) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string but it wasn't!", k))
Expand All @@ -82,7 +82,7 @@ func ValidateLinuxComputerName(i interface{}, k string, maxLength int) (warnings
errors = append(errors, fmt.Errorf("%q cannot begin with an underscore", k))
}

if strings.HasSuffix(v, ".") || strings.HasSuffix(v, "-") {
if strings.HasSuffix(v, ".") || (strings.HasSuffix(v, "-") && !allowDashSuffix) {
errors = append(errors, fmt.Errorf("%q cannot end with an period or dash", k))
}

Expand Down
7 changes: 6 additions & 1 deletion azurerm/internal/services/compute/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestValidateLinuxComputerName(t *testing.T) {
for _, v := range testData {
t.Logf("[DEBUG] Testing %q..", v.input)

_, errors := ValidateLinuxComputerName(v.input, "computer_name", 100)
_, errors := ValidateLinuxComputerName(v.input, "computer_name", 100, false)
actual := len(errors) == 0
if v.expected != actual {
t.Fatalf("Expected %t but got %t", v.expected, actual)
Expand Down Expand Up @@ -226,6 +226,11 @@ func TestValidateLinuxComputerNamePrefix(t *testing.T) {
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg",
expected: false,
},
{
// dash suffix
input: "abc-",
expected: true,
},
}

for _, v := range testData {
Expand Down

0 comments on commit 4130c34

Please sign in to comment.