Skip to content

Commit

Permalink
Merge pull request #4585 from terraform-providers/f/vmss-windows
Browse files Browse the repository at this point in the history
New Resource: `azurerm_windows_virtual_machine_scale_set`
  • Loading branch information
tombuildsstuff authored Oct 21, 2019
2 parents a01c0e1 + bae54cd commit e9adf34
Show file tree
Hide file tree
Showing 21 changed files with 9,255 additions and 8 deletions.
12 changes: 11 additions & 1 deletion azurerm/helpers/validate/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ func SharedImageVersionName(v interface{}, k string) (warnings []string, errors
return warnings, errors
}

// VirtualMachineTimeZone returns a case-sensitive validation function for the Time Zones for a Virtual Machine
func VirtualMachineTimeZone() schema.SchemaValidateFunc {
return virtualMachineTimeZone(false)
}

// VirtualMachineTimeZone returns a case-insensitive validation function for the Time Zones for a Virtual Machine
func VirtualMachineTimeZoneCaseInsensitive() schema.SchemaValidateFunc {
return virtualMachineTimeZone(true)
}

func virtualMachineTimeZone(ignoreCase bool) schema.SchemaValidateFunc {
// Candidates are listed here: http://jackstromberg.com/2017/01/list-of-time-zones-consumed-by-azure/
candidates := []string{
"",
Expand Down Expand Up @@ -163,5 +173,5 @@ func VirtualMachineTimeZone() schema.SchemaValidateFunc {
"West Pacific Standard Time",
"Yakutsk Standard Time",
}
return validation.StringInSlice(candidates, true)
return validation.StringInSlice(candidates, ignoreCase)
}
2 changes: 1 addition & 1 deletion azurerm/helpers/validate/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestVirtualMachineTimeZone(t *testing.T) {
}

for _, tc := range cases {
_, errors := VirtualMachineTimeZone()(tc.Value, "unittest")
_, errors := VirtualMachineTimeZoneCaseInsensitive()(tc.Value, "unittest")

if len(errors) != tc.Errors {
t.Fatalf("Expected VirtualMachineTimeZone to trigger '%d' errors for '%s' - got '%d'", tc.Errors, tc.Value, len(errors))
Expand Down
4 changes: 4 additions & 0 deletions azurerm/internal/services/compute/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ func ValidateLinuxName(i interface{}, k string) (warnings []string, errors []err
return validateName(64)(i, k)
}

func ValidateWindowsName(i interface{}, k string) (warnings []string, errors []error) {
return validateName(16)(i, k)
}

func validateName(maxLength int) func(i interface{}, k string) (warnings []string, errors []error) {
return func(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
Expand Down
68 changes: 68 additions & 0 deletions azurerm/internal/services/compute/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,71 @@ func TestValidateLinuxName(t *testing.T) {
}
}
}

func TestValidateWindowsName(t *testing.T) {
testData := []struct {
input string
expected bool
}{
{
// empty
input: "",
expected: false,
},
{
// basic example
input: "hello",
expected: true,
},
{
// can't start with an underscore
input: "_hello",
expected: false,
},
{
// can't end with a dash
input: "hello-",
expected: false,
},
{
// can't contain an exclamation mark
input: "hello!",
expected: false,
},
{
// dash in the middle
input: "malcolm-middle",
expected: true,
},
{
// can't end with a period
input: "hello.",
expected: false,
},
{
// 14 chars
input: "abcdefghijklmn",
expected: true,
},
{
// 15 chars
input: "abcdefghijklmno",
expected: true,
},
{
// 16 chars
input: "abcdefghijklmnop",
expected: false,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q..", v.input)

_, errors := ValidateWindowsName(v.input, "name")
actual := len(errors) == 0
if v.expected != actual {
t.Fatalf("Expected %t but got %t", v.expected, actual)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func VirtualMachineScaleSetIdentitySchema() *schema.Schema {
},

"identity_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -191,7 +191,7 @@ func ExpandVirtualMachineScaleSetIdentity(input []interface{}) (*compute.Virtual
Type: compute.ResourceIdentityType(raw["type"].(string)),
}

identityIdsRaw := raw["identity_ids"].([]interface{})
identityIdsRaw := raw["identity_ids"].(*schema.Set).List()
identityIds := make(map[string]*compute.VirtualMachineScaleSetIdentityUserAssignedIdentitiesValue)
for _, v := range identityIdsRaw {
identityIds[v.(string)] = &compute.VirtualMachineScaleSetIdentityUserAssignedIdentitiesValue{}
Expand Down
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ func Provider() terraform.ResourceProvider {
// 2.0 resources
if features.SupportsTwoPointZeroResources() {
resources["azurerm_linux_virtual_machine_scale_set"] = resourceArmLinuxVirtualMachineScaleSet()
resources["azurerm_windows_virtual_machine_scale_set"] = resourceArmWindowsVirtualMachineScaleSet()
}

// avoids this showing up in test output
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_dev_test_lab_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func resourceArmDevTestLabSchedules() *schema.Resource {
"time_zone_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.VirtualMachineTimeZone(),
ValidateFunc: validate.VirtualMachineTimeZoneCaseInsensitive(),
},

"notification_settings": {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func resourceArmVirtualMachine() *schema.Resource {
Optional: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validate.VirtualMachineTimeZone(),
ValidateFunc: validate.VirtualMachineTimeZoneCaseInsensitive(),
},
"winrm": {
Type: schema.TypeList,
Expand Down
Loading

0 comments on commit e9adf34

Please sign in to comment.