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 6, 2020
1 parent 0932a0c commit ba53ee8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource {
// only applicable when `priority` is set to `Spot`
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
ValidateFunc: validation.StringInSlice([]string{
string(compute.Deallocate),
string(compute.Delete),
Expand All @@ -147,7 +147,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource {
"health_probe_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
ValidateFunc: azure.ValidateResourceID,
},

Expand All @@ -171,7 +171,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource {
"priority": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
Default: string(compute.Regular),
ValidateFunc: validation.StringInSlice([]string{
string(compute.Regular),
Expand Down
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))
}

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ func VirtualMachineScaleSetAutomatedOSUpgradePolicySchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
ForceNew: false,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down

0 comments on commit ba53ee8

Please sign in to comment.