Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow azurerm_linux_virtual_machine_scale_set computer_name_prefix to end with dashes #9182

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 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,8 +82,12 @@ 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, "-") {
errors = append(errors, fmt.Errorf("%q cannot end with an period or dash", k))
if strings.HasSuffix(v, ".") {
errors = append(errors, fmt.Errorf("%q cannot end with a period", k))
}

if !allowDashSuffix && strings.HasSuffix(v, "-") {
errors = append(errors, fmt.Errorf("%q cannot end with a dash", k))
}
bchess marked this conversation as resolved.
Show resolved Hide resolved

// Linux host name cannot contain the following characters
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