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

Scale Sets and VM Extensions #453

Closed
codyja opened this Issue Oct 25, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@codyja

codyja commented Oct 25, 2017

Hi All,
I'm seeing an issue when I'm using scale sets and VM Extensions to run CustomScript extensions. From the documentation on CustomScript extension, there's mention of a "timestamp" option that can be applied to "trigger a re-run of the script by changing value of this field" on the Azure side. I image it would require a vm "upgrade" on the azure side to reapply the change.

When I change the timestamp, or the actual commandToExecute, it doesn't seem to change anything. I still see the old first run commandToExecute in the terraform.tfstate file, even after multiple changes and runs. One thing I do notice is every time I run terraform plan/apply, it does seem to do this every time I run it:

Terraform will perform the following actions:

  ~ module.vm_builds.azurerm_virtual_machine_scale_set.vm_linux
      sku.1920218716.capacity: "" => "2"
      sku.1920218716.name:     "" => "Standard_A4"
      sku.3895405802.capacity: "2" => "0"
      sku.3895405802.name:     "Standard_A4" => ""

Documentation for CustomScript extension: https://github.com/Azure/custom-script-extension-linux

timestamp (optional, 32-bit integer) use this field only to trigger a re-run of the script by changing value of this field.

Terraform Version

Terraform v0.10.7

Affected Resource(s)

Please list the resources as a list, for example:

  • azurerm_virtual_machine_scale_set

Terraform Configuration Files

Here's a piece from my main.tf file under the module reference block.

  #
  custom_extension          = {
    name                    = "customScript"
    publisher               = "Microsoft.Azure.Extensions"
    type                    = "CustomScript"
    type_handler_version    = "2.0"
    settings                = <<SETTINGS
        {
          "commandToExecute": "curl google.com -o /tmp/s2.html",
          "timestamp": 123456799
        }
      SETTINGS
    }

Here's a section from my module file to build the scale set.

variable custom_extension         { type = "map"}

resource "azurerm_virtual_machine_scale_set" "vm_linux" {
  name                                       = "${lower(var.scale_set_name)}"
  location                                   = "${var.vnet_location}"
  resource_group_name                        = "${var.resource_group_name}"
  upgrade_policy_mode                        = "${var.upgrade_policy_mode}"

  sku {
    capacity = "${var.scale_set_capacity}"
    name = "${var.vm_size}"
  }

  storage_profile_image_reference = "${list(var.storage_image_reference)}"

  storage_profile_os_disk {
    create_option = "FromImage"
    caching = "ReadWrite"
    managed_disk_type = "Standard_LRS"
  }

  storage_profile_data_disk {
    create_option = "Empty"
    lun = 0
    caching = "ReadWrite"
    disk_size_gb = 10
  }

  os_profile {
    computer_name_prefix                     = "${lower(var.vm_prefix)}"
    admin_username                           = "${var.username}"
    admin_password                           = "${var.password}"
  }

  network_profile {
    "ip_configuration" {
      name = "tf_network_profile"
      subnet_id = "/subscriptions/${var.subscription_id}/resourceGroups/${var.resource_group_name}/providers/Microsoft.Network/virtualNetworks/${var.vnet_name}/subnets/${var.subnet_name}"
    }
    name = "test_ip"
    primary = true
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }

  extension = "${list(var.custom_extension)}"

  tags                                       = "${merge(var.custom_tags, module.tags.standard_tags)}"
}

Expected Behavior

I believe with the timestamp option, it should treat each rerun as a change and terraform should chane the extension on the Azure side.

@tombuildsstuff

This comment has been minimized.

Show comment
Hide comment
@tombuildsstuff

tombuildsstuff Dec 6, 2017

Contributor

hey @codyja

Thanks for opening this issue - apologies for the delayed response here!

I've taken a look into this and it appears that settings was missing from the Hash (which is used to detect changes in Set's) - I've fixed this in PR #609, which also includes a new test-case to ensure this behaviour is caught in future :)

Thanks!

Contributor

tombuildsstuff commented Dec 6, 2017

hey @codyja

Thanks for opening this issue - apologies for the delayed response here!

I've taken a look into this and it appears that settings was missing from the Hash (which is used to detect changes in Set's) - I've fixed this in PR #609, which also includes a new test-case to ensure this behaviour is caught in future :)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment