hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.61k stars 4.65k forks source link

terraform apply -refresh-only does not work on azurerm_windows_virtual_machine "computer_name" #27856

Open bandarr opened 3 weeks ago

bandarr commented 3 weeks ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.8

AzureRM Provider Version

4.8.0

Affected Resource(s)/Data Source(s)

azurerm_windows_virtual_machine

Terraform Configuration Files

resource "azurerm_windows_virtual_machine" "i-am-a-vm" {
  name                  = "vm-IAmWhatIAm"
  location              = azurerm_resource_group.example.location
  resource_group_name   = azurerm_resource_group.example.name
  network_interface_ids = [azurerm_network_interface.iamwhatiam.id]
  size                  = local.Two-Core-Production-Size
  tags                  = local.common-tags

  lifecycle {
    prevent_destroy = true
    ignore_changes = [admin_password]
  }

  zone = "1"

  source_image_id = local.image-id

  os_disk {
    caching                = "ReadWrite"
    storage_account_type   = "Premium_LRS"
  }

  computer_name  = "iAmNOTWhatIAm"
  admin_username = "iamanadmin"
  admin_password = local.Temporary-Admin-Password

  identity {
    type = local.SystemAssigned
  }
}

Debug Output/Panic Output

No changes. Your infrastructure still matches the configuration.

Expected Behaviour

terraform apply -refresh-only should indicate that the computer_name should be updated in the state when the computer_name in the state is different from the computer name in the Azure portal.

Actual Behaviour

terraform apply -refresh-only sees no changes to the configuration

Steps to Reproduce

  1. Rename Windows VM from within Windows
  2. Confirm that the new computer name appears in the Azure Portal
  3. terraform apply -refresh-only

Important Factoids

No response

References

No response

ms-zhenhua commented 2 weeks ago

Hi @bandarr, Thank you for reaching out. The provider internally invokes Azure REST API. Could you please check whether Azure returns the right computerName value? You may follow the steps below:

  1. enable TF_LOG and TF_LOG_PATH according to this document
  2. Rerun terraform apply -refresh-only
  3. Find the computerName from GET API in the generated log
bandarr commented 1 week ago

Hi @bandarr, Thank you for reaching out. The provider internally invokes Azure REST API. Could you please check whether Azure returns the right computerName value? You may follow the steps below:

  1. enable TF_LOG and TF_LOG_PATH according to this document
  2. Rerun terraform apply -refresh-only
  3. Find the computerName from GET API in the generated log

Set TF_LOG to "TRACE" and examined output:

computerName is set to the old computer name, whereas the Azure Portal reflects the correct, new name.

ms-zhenhua commented 1 week ago

Seems the Azure Portal reflects the different value from the Azure REST API. You may create an issue with the X-Ms-Correlation-Request-Id of your GET API on azure-rest-api-specs to let Azure Service team confirm this issue.