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

Cannot use virtual_machine_data_disk_attachment on a VM with azurerm_user_assigned_identity #2485

Closed
fatal-exception opened this issue Dec 10, 2018 · 4 comments · Fixed by #4538
Assignees
Labels
Milestone

Comments

@fatal-exception
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 Version
Terraform v0.11.10

provider.azurerm v1.19.0

Affected Resource(s)

azurerm_virtual_machine_data_disk_attachment

Terraform Configuration Files

resource "azurerm_user_assigned_identity" "identity" {
  resource_group_name = "volumetest"
  location            = "westeurope"

  name = "volume-test-id"
}

data "azurerm_subscription" "subscription" {}

resource "azurerm_managed_disk" "volumetest" {
  name                 = "volumetest"
  location             = "westeurope"
  resource_group_name  = "volumetest"
  storage_account_type = "Standard_LRS"
  create_option        = "Empty"
  disk_size_gb         = "100"

  tags {
    subscription_name = "sandbox"
  }
}

resource "azurerm_virtual_machine_data_disk_attachment" "jenkins_home" {
  managed_disk_id    = "${azurerm_managed_disk.volumetest.id}"
  virtual_machine_id = "${azurerm_virtual_machine.volumetest.id}"
  lun                = "10"
  caching            = "ReadWrite"
}
terraform {
  required_version = "0.11.10"
}
resource "azurerm_resource_group" "volumetest" {
  name     = "volumetest"
  location = "westeurope"
}

resource "azurerm_subnet" "volumetest" {
  name                 = "volumetest"
  resource_group_name  = "volumetest"
  virtual_network_name = "volumetest"
  address_prefix       = "10.0.1.0/24"
}

resource "azurerm_virtual_network" "volumetest" {
  name                = "volumetest"
  location            = "westeurope"
  resource_group_name = "volumetest"
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_virtual_machine" "volumetest" {
  name                          = "volumetest"
  location                      = "westeurope"
  resource_group_name           = "volumetest"
  vm_size                       = "Standard_DS2_v2"
  delete_os_disk_on_termination = true
  network_interface_ids         = ["${azurerm_network_interface.nic.id}"]

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  storage_os_disk {
    name              = "osdisk"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    os_type           = "Linux"
    managed_disk_type = "Standard_LRS"
  }

  os_profile {
    computer_name  = "volumetest-sandbox"
    admin_username = "azureuser"
    admin_password = "PasswordAuthIsDisabledButThisIsRequired"
  }

  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      key_data = "${file("./files/id_rsa.pub")}"
      path     = "/home/azureuser/.ssh/authorized_keys"
    }
  }

  identity {
    type = "UserAssigned"

    identity_ids = [
      "${azurerm_user_assigned_identity.identity.id}",
    ]
  }

  tags {
    role              = "volumetest"
    subscription_name = "sandbox"
  }
}

resource "azurerm_network_interface" "nic" {
  name                = "volumetest"
  resource_group_name = "volumetest"
  location            = "westeurope"

  ip_configuration {
    name                          = "ipconfig"
    subnet_id                     = "${azurerm_subnet.volumetest.id}"
    private_ip_address_allocation = "Dynamic"
  }
}

Expected Behavior

A VM is created with both a Managed Service Identity, and an attached disk

Actual Behavior

terraform apply

azurerm_virtual_machine_data_disk_attachment.volumetest: Creating...
  caching:                   "" => "ReadWrite"
  create_option:             "" => "Attach"
  lun:                       "" => "10"
  managed_disk_id:           "" => "/subscriptions/2678e156-815b-4ed8-a214-18a708c038fd/resourceGroups/volumetest/providers/Microsoft.Compute/disks/volumetest"
  virtual_machine_id:        "" => "/subscriptions/2678e156-815b-4ed8-a214-18a708c038fd/resourceGroups/volumetest/providers/Microsoft.Compute/virtualMachines/volumetest"
  write_accelerator_enabled: "" => "false"

Error: Error applying plan:

1 error(s) occurred:

* azurerm_virtual_machine_data_disk_attachment.volumetest: 1 error(s) occurred:

* azurerm_virtual_machine_data_disk_attachment.volumetest: Error updating Virtual Machine "volumetest" (Resource Group "volumetest") with Disk "volumetest": compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidIdentityValues" Message="Invalid value for the identities '/subscriptions/2678e156-815b-4ed8-a214-18a708c038fd/resourcegroups/volumetest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/volume-test-id'. The 'UserAssignedIdentities' property keys should only be empty json objects or null."

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Steps to Reproduce

See configuration example above, add a valid ssh pubkey in ./files/id_rsa.pub, then run terraform apply

Important Factoids

If I manually remove the Managed Service Identity from the VM, the volume attaches and detaches fine. Once the VM has a Managed Service Identity, terraform can neither attach nor detach a disk - it always has the error shown above.

The key error seems to be:

Error updating Virtual Machine "volumetest" (Resource Group "volumetest") with Disk "volumetest": compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidIdentityValues" Message="Invalid value for the identities '/subscriptions/2678e156-815b-4ed8-a214-18a708c038fd/resourcegroups/volumetest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/volume-test-id'. The 'UserAssignedIdentities' property keys should only be empty json objects or null."

@tombuildsstuff tombuildsstuff added service/disk-attachments Virtual Machine Disk Attachments bug labels Dec 10, 2018
@fatal-exception
Copy link
Author

Hi all,

I'm just wondering if there is any indication of whether this might make it into a workstream some time soon? If not, then we may need to redesign around the limitation in Azure

Thanks!

Matt

@tombuildsstuff tombuildsstuff added this to the 1.24.0 milestone Feb 21, 2019
@tombuildsstuff tombuildsstuff modified the milestones: 1.24.0, 1.25.0 Mar 5, 2019
@tombuildsstuff tombuildsstuff modified the milestones: v1.25.0, v1.24.0, v1.26.0 Mar 14, 2019
@katbyte katbyte modified the milestones: v1.26.0, v1.27.0 Apr 17, 2019
@tombuildsstuff tombuildsstuff modified the milestones: v1.28.0, v2.0.0 May 7, 2019
@msaurabhee
Copy link

This is becoming important? Was this fixed?

@ghost
Copy link

ghost commented Oct 29, 2019

This has been released in version 1.36.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 = "~> 1.36.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Nov 9, 2019

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 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants