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

custom_data forces VM recreation every time even if the data is the same #6756

Closed
roeizavida opened this issue May 4, 2020 · 3 comments
Closed
Labels
service/virtual-machine upstream/terraform This issue is blocked on an upstream issue within Terraform (Terraform Core/CLI, The Plugin SDK etc)

Comments

@roeizavida
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Terraform v0.12.24
+ provider.azurerm v2.8.0
+ provider.external v1.2.0
+ provider.null v2.1.2
+ provider.random v2.2.1
+ provider.template v2.1.2

Affected Resource(s)

  • azurerm_linux_virtual_machine

Terraform Configuration Files

resource "azurerm_linux_virtual_machine" "vm" {
  name                         = var.name
  resource_group_name          = var.resource_group_name
  location                     = var.location
  size                         = var.size
  availability_set_id          = var.availability_set_id
  proximity_placement_group_id = var.proximity_placement_group_id

  network_interface_ids = [
    azurerm_network_interface.nic_0.id,
    azurerm_network_interface.nic_1.id,
    azurerm_network_interface.nic_2.id
  ]

  plan {
    name      = "bundle2"
    publisher = "paloaltonetworks"
    product   = "vmseries1"
  }

  source_image_reference {
    publisher = "paloaltonetworks"
    offer     = "vmseries1"
    sku       = "bundle2"
    version   = "9.0.4"
  }

  os_disk {
    name                 = "${var.name}-os"
    caching              = "ReadWrite"
    storage_account_type = "StandardSSD_LRS"
  }

  computer_name                   = var.name
  admin_username                  = var.admin_username
  admin_password                  = var.admin_password
  disable_password_authentication = false
  allow_extension_operations      = true

  admin_ssh_key {
      username   = var.admin_username
      public_key = var.public_key
  }

  custom_data = base64encode("storage-account=${data.azurerm_storage_account.bootstrap_storage_account.name},access-key=${data.azurerm_storage_account.bootstrap_storage_account.primary_access_key},file-share=${azurerm_storage_share.bootstrap_storage_share.name},share-directory=files")
}

Expected Behavior

Terraform should check if custom_data base64 value was changed and mark the VM for redeployment only if it changed.

Actual Behavior

Every terraform apply, the VM is marked for recreation even if the base64 value of custom_data is the same every time. When removing custom_data line, the VM is not recreated.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

Similar issue but this solution is not working although it was supposed to be fixed in version 2.0:

@tombuildsstuff tombuildsstuff added the upstream/terraform This issue is blocked on an upstream issue within Terraform (Terraform Core/CLI, The Plugin SDK etc) label May 4, 2020
@asanCar
Copy link

asanCar commented May 19, 2020

It happens exactly the same for us, despite the custom_data property is not highlighted as the recreation cause.

Meanwhile we have added this block to the azurerm_linux_virtual_machine as a workarround:

lifecycle {
    ignore_changes = [custom_data]
  }

@tombuildsstuff
Copy link
Contributor

hi @roeizavida @asanCar

Thanks for opening this issue.

The root-cause of this bug is an issue in Terraform Core where information from Data Sources isn't cached (and thus refreshed every time) - coupled with a limitation of the Azure API where the contents of the custom_data field aren't returned through the API - meaning that Terraform assumes this content has changed.

As @asanCar has mentioned it should be possible to use ignore_changes to workaround this in the interim (although that has issues where, for example, changes to the custom data are ignored). In Terraform Core there's two issues tracking this, the first regarding Data Source Caching explicitly - and the other for Data Resource Lifecycle Adjustments (which is the current issue).

However since this is a bug in Terraform Core (and the Azure API doesn't return this information) unfortunately this isn't something we're able to fix in the Azure Provider at this time - and as such I'm going to close this issue in favour of this issue in Terraform Core which should ultimately fix this - would you mind subscribing to that issue for updates?

Thanks!

@ghost
Copy link

ghost commented Jun 18, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/virtual-machine upstream/terraform This issue is blocked on an upstream issue within Terraform (Terraform Core/CLI, The Plugin SDK etc)
Projects
None yet
Development

No branches or pull requests

3 participants