Skip to content

Commit

Permalink
Merge pull request #609 from terraform-providers/vmss-extension
Browse files Browse the repository at this point in the history
`azurerm_virtual_machine_scale_set`: ensuring changes to the `settings` object are detected
  • Loading branch information
tombuildsstuff authored Dec 6, 2017
2 parents ad6d27e + 3cc2133 commit df8a94a
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 2 deletions.
16 changes: 14 additions & 2 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
},
},
},
Set: resourceArmVirtualMachineScaleSetOsProfileLWindowsConfigHash,
Set: resourceArmVirtualMachineScaleSetOsProfileWindowsConfigHash,
},

"os_profile_linux_config": {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ func resourceArmVirtualMachineScaleSetOsProfileLinuxConfigHash(v interface{}) in
return hashcode.String(buf.String())
}

func resourceArmVirtualMachineScaleSetOsProfileLWindowsConfigHash(v interface{}) int {
func resourceArmVirtualMachineScaleSetOsProfileWindowsConfigHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
if m["provision_vm_agent"] != nil {
Expand All @@ -1189,6 +1189,18 @@ func resourceArmVirtualMachineScaleSetExtensionHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%t-", m["auto_upgrade_minor_version"].(bool)))
}

// we need to ensure the whitespace is consistent
settings := m["settings"].(string)
if settings != "" {
expandedSettings, err := structure.ExpandJsonFromString(settings)
if err == nil {
serialisedSettings, err := structure.FlattenJsonToString(expandedSettings)
if err == nil {
buf.WriteString(fmt.Sprintf("%s-", serialisedSettings))
}
}
}

return hashcode.String(buf.String())
}

Expand Down
149 changes: 149 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,35 @@ func TestAccAzureRMVirtualMachineScaleSet_extension(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachineScaleSet_extensionUpdate(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
location := testLocation()
config := testAccAzureRMVirtualMachineScaleSetExtensionTemplate(ri, location)
updatedConfig := testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(ri, location)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
testCheckAzureRMVirtualMachineScaleSetExtension(resourceName),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
testCheckAzureRMVirtualMachineScaleSetExtension(resourceName),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(ri, testLocation())
Expand Down Expand Up @@ -2252,6 +2281,14 @@ resource "azurerm_virtual_machine_scale_set" "test" {
admin_password = "Passwword1234"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/myadmin/.ssh/authorized_keys"
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com"
}
}
network_profile {
name = "TestNetworkProfile"
primary = true
Expand Down Expand Up @@ -2300,6 +2337,118 @@ SETTINGS
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_storage_account" "test" {
name = "accsa%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_container" "test" {
name = "vhds"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "acctvmss-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
overprovision = false
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 1
}
os_profile {
computer_name_prefix = "testvm-%d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/myadmin/.ssh/authorized_keys"
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com"
}
}
network_profile {
name = "TestNetworkProfile"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = "os-disk"
caching = "ReadWrite"
create_option = "FromImage"
vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"]
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
extension {
name = "CustomScript"
publisher = "Microsoft.Azure.Extensions"
type = "CustomScript"
type_handler_version = "2.0"
auto_upgrade_minor_version = true
settings = <<SETTINGS
{
"commandToExecute": "echo $HOSTNAME",
"timestamp": 12345679955
}
SETTINGS
protected_settings = <<SETTINGS
{
"storageAccountName": "${azurerm_storage_account.test.name}",
"storageAccountKey": "${azurerm_storage_account.test.primary_access_key}"
}
SETTINGS
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit df8a94a

Please sign in to comment.