terraform-provider-azurerm: Previously applied configs for "azurerm_mssql_virtual_machine" fails if the virtual machine is not in Running state

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 Terraform Provider Azurerm: 2.7.0

Affected Resource(s)

  • azurerm_mssql_virtual_machine

Terraform Configuration Files

resource "azurerm_mssql_virtual_machine" "vm_sql" {
  count                            = "1"
  virtual_machine_id               = element(azurerm_virtual_machine.vm_db.*.id,count.index)
  sql_license_type                 = "PAYG"

  auto_patching {
    day_of_week                            = "Sunday"
    maintenance_window_duration_in_minutes = 180
    maintenance_window_starting_hour       = 2
  }

Debug Output

Panic Output

Error: reading Sql Virtual Machine (Sql Virtual Machine Name “vmname” / Resource Group “rgname”): sqlvirtualmachine.SQLVirtualMachinesClient#Get: Failure responding to request: StatusCode=400 – Original Error: autorest/azure: Service returned an error. Status=400 Code=“VmNotRunning” Message=“The VM: /subscriptions/xxxx-xxxx-xxxx-xxxx-xxxxx/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vmname is not in running state.” The action Terraform Plan failed

Expected Behavior

VM should be skipped if it’s not in the Running state. Or it would be great to have some parameters to enable/disable the “skip” option.

Actual Behavior

Terraform plan/apply failed if VM is not in the Running state.

Steps to Reproduce

  1. terraform plan

Important Factoids

References

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 4
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Any update on this one? It’s really annoying to have the VM started up just so my TF plan can complete…

This confirms that a workaround i needed in the terraform provider

This is ultimately an API limitation, where the API doesn’t work unless the Virtual Machine is powered on - whilst Terraform could look to start/stop the Virtual Machine at plan-time to workaround this, Terraform’s plan functionality is read-only (and supposed to be idempotent) - as such I’m not sure there’s much we can do to workaround this in Terraform unfortunately.

As such I’ve tagged this issue as upstream/microsoft since this requires a fix in the Azure API - and I’d recommend opening an issue on the Azure/azure-rest-api-specs repository where someone from the Service Team should be able to take a look, and once this bug is fixed in the Azure API this’ll automatically start working in Terraform.

Thanks!

Could be, but it’s only an issue for azurerm_mssql_virtual_machine, not for regular VM. It’s a bit weird that they would work differently.

I am experiencing this issue as well. I have three environments which are applied from 1 pipeline trough stages. Running the test stage works like a charm, but the acceptance environment is normally turned off, so every time I run the pipeline, I run into issue with the plan of acceptance env due to turned off SQL machine. Really annoying so please fix this!