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

Update resource azurerm_virtual_machine with storage datadisk #1593

Closed
petit-lu opened this issue Jul 17, 2018 · 5 comments
Closed

Update resource azurerm_virtual_machine with storage datadisk #1593

petit-lu opened this issue Jul 17, 2018 · 5 comments

Comments

@petit-lu
Copy link

petit-lu commented Jul 17, 2018

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

Description

I purpose to update resource azurerm_virtual_machine with storage datadisk. Today if you deploy a VM with a Premium datadisk, and you want change this value to "Standard" after deployment, Terraform can't do this change.
But if you use resource azurerm_managed_datadisk, to create your datadisk, this resource is able to change "Premium" > "Standard" or "Standard" to "Premium" datadisk if your VM is offline.

New or Affected Resource(s)

  • azurerm_virtual_machine

Potential Terraform Configuration

Terraform will perform the following actions:

  ~ module.servers.azurerm_virtual_machine.vm-linux-with-datadisk
      storage_data_disk.0.managed_disk_type: "Premium_LRS" => "Standard_LRS"



Error: Error applying plan:

1 error(s) occurred:

* module.servers.azurerm_virtual_machine.vm-linux-with-datadisk: 1 error(s) occurred:

* azurerm_virtual_machine.vm-linux-with-datadisk: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="OperationNotAllowed" Message="Managed disk storage account type change through Virtual Machine 'upgradesrvdev00' is not allowed. Please update disk resource at ......./providers/Microsoft.Compute/disks/datadisk-upgradesrvdev0-0." Target="dataDisk.managedDisk.storageAccountType"

References

  • #0000
@JunyiYi JunyiYi changed the title Update ressource azurerm_virtual_machine with storage datadisk Update resource azurerm_virtual_machine with storage datadisk Aug 9, 2018
@JunyiYi JunyiYi self-assigned this Aug 9, 2018
@uj7380
Copy link

uj7380 commented Oct 22, 2018

This issue was resolved? Or, the status of issue is still "opened"?

@degerrit
Copy link

In case this helps, I had an identical "Managed disk storage account type change" Azure error on terraform 0.12.10 but with no indication in the plan that the managed_disk_type was going to be changed (and, as far as I can tell afterwards - it wasn't : Premium_LRS = Premium SSD?)

The VM in question was just imported into terraform, so some state information might have been missing (?). On the other hand, the error came from Azure, so terraform was trying to change something Azure did not allow us to change.

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "azurerm" (hashicorp/azurerm) 1.35.0...
- Downloading plugin for provider "template" (hashicorp/template) 2.1.2...

Plan (stripped of some lines not changing):

$ terraform plan

  # module.rgxx-prod-postgres-01.module.vm.azurerm_virtual_machine.virtual_machine[0] will be updated in-place
  ~ resource "azurerm_virtual_machine" "virtual_machine" {
      + delete_data_disks_on_termination = false
      + delete_os_disk_on_termination    = false
        id                               = "/subscriptions/7.../providers/Microsoft.Compute/virtualMachines/DB-Postgres-01"
        name                             = "DB-Postgres-01"
        network_interface_ids            = [
            "/subscriptions/7.../providers/Microsoft.Network/networkInterfaces/DB-Postgres-01-nic",
        ]
      - primary_network_interface_id     = "/subscriptions/7.../providers/Microsoft.Network/networkInterfaces/DB-Postgres-01-nic" -> null
      ~ tags                             = {
          ~ "Application" = ""
          - "Purpose"     = "" -> null
          + "environment" = "Dev"
          + "purpose"     = "Postgres server"
        }
        vm_size                          = "Standard_DS2_v2"
        zones                            = []

      ~ boot_diagnostics {
            enabled     = true
          ~ storage_uri = "https://xx.blob.core.windows.net/" -> "https://yy.blob.core.windows.net/"
        }

        os_profile {
        }
        os_profile_linux_config {
            disable_password_authentication = true
            ssh_keys {
            }
        }

      + storage_data_disk {
          + caching                   = "ReadOnly"
          + create_option             = "Empty"
          + disk_size_gb              = 32
          + lun                       = 0
          + managed_disk_type         = "Premium_LRS"
          + name                      = "DB-Postgres-01-datadisk"
          + write_accelerator_enabled = false
        }
      + storage_data_disk {
          + lun                       = 1
        }
      + storage_data_disk {
          + lun                       = 2
        }

        storage_image_reference {
        }

        storage_os_disk {
            caching                   = "ReadWrite"
            create_option             = "FromImage"
            disk_size_gb              = 250
            managed_disk_id           = "/subscriptions/7.../providers/Microsoft.Compute/disks/DB-Postgres-01_OsDisk_1_bcxxx"
            managed_disk_type         = "Premium_LRS"
            name                      = "DB-Postgres-01_OsDisk_1_bcxxx"
            os_type                   = "Linux"
            write_accelerator_enabled = false
        }
    }

Plan: 0 to add, 2 to change, 0 to destroy.

Again, no disks to be changed:

$ terraform show
  ~ module.rgxx-prod-postgres-01.module.vm.azurerm_network_interface.network_interface_card[0]
  ~ module.rgxx-prod-postgres-01.module.vm.azurerm_virtual_machine.virtual_machine[0]
$ terraform apply -input=false "terraform_plan_${CI_PIPELINE_ID}_${CI_COMMIT_SHORT_SHA}_${GITLAB_USER_ID}.tfout"
Acquiring state lock. This may take a few moments...
module.rgxx-prod-postgres-01.module.vm.azurerm_network_interface.network_interface_card[0]: Modifying... [id=/subscriptions/7.../providers/Microsoft.Network/networkInterfaces/DB-Postgres-01-nic]
module.rgxx-prod-postgres-01.module.vm.azurerm_network_interface.network_interface_card[0]: Modifications complete after 2s [id=/subscriptions/7.../providers/Microsoft.Network/networkInterfaces/DB-Postgres-01-nic]
module.rgxx-prod-postgres-01.module.vm.azurerm_virtual_machine.virtual_machine[0]: Modifying... [id=/subscriptions/7.../providers/Microsoft.Compute/virtualMachines/DB-Postgres-01]

Error: compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: Code="OperationNotAllowed" Message="Managed disk storage account type change through Virtual Machine 'DB-Postgres-01' is not allowed. Please update disk resource at /subscriptions/7.../providers/Microsoft.Compute/disks/DB-Postgres-01_OsDisk_1_bcxxx." Target="osDisk.managedDisk.storageAccountType"

  on modules/vm-0.1-customdisk/main.tf line 66, in resource "azurerm_virtual_machine" "virtual_machine":
  66: resource "azurerm_virtual_machine" "virtual_machine" {

In the end, I stopped and deallocated the VM and then the terraform apply job went through without any errors, and without any discernable change in OS disk...

@tombuildsstuff tombuildsstuff added the service/disk-attachments Virtual Machine Disk Attachments label Jan 16, 2020
@tombuildsstuff tombuildsstuff added this to the v2.0.0 milestone Jan 16, 2020
@jackofallops
Copy link
Member

Closing this as we're currently working on version 2.0 of the Azure Provider which we previously announced in #2807.
As a part of this we're introducing five new resources which will supersede the existing azurerm_virtual_machine and azurerm_virtual_machine_scale_set resources:

azurerm_linux_virtual_machine
azurerm_linux_virtual_machine_scale_set
azurerm_virtual_machine_scale_set_extension
azurerm_windows_virtual_machine
azurerm_windows_virtual_machine_scale_set

We recently opened #5550 which adds support for the new Virtual Machine resources - which require attaching Data Disks using the azurerm_managed_disk and azurerm_virtual_machine_data_disk_attachment resources rather than having them defined inline, which allows for more granular control/flexibility when modifying disks. Since the existing Virtual Machine resource is being superseded, unfortunately we have no plans to backport this to the existing azurerm_virtual_machine resource - however we’ll be publishing information on the new resources (and how you can opt-into the Beta) in the near-future.

Thanks

  • Ste

@ghost
Copy link

ghost commented Feb 24, 2020

This has been released in version 2.0.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.0.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 4, 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 Mar 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants