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.59k stars 4.62k forks source link

Can't assign azurerm_user_assigned_identity to virtual machines #6079

Closed jknash closed 4 years ago

jknash commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.12.23

Affected Resource(s)

azurerm_linux_virtual_machine azurerm_windows_virtual_machine azurerm_user_assigned_identity

Terraform Configuration Files

The following code contains an identity block example from a virtual machine and the azurerm_user_assigned_identity resource. The identity block errors out whether I'm using only SystemAssigned or UserAssigned as well as when I have both in type. The virtual machine type doesn't matter, either.

   identity {
    type = "SystemAssigned, UserAssigned"
    identity_ids = ["azurerm_user_assigned_identity.linmgmt.id"]
  }

resource "azurerm_user_assigned_identity" "linmgmt" {
  resource_group_name = azurerm_resource_group.prd-mgmt.name
  location            = azurerm_resource_group.prd-mgmt.location

  name = "prdMgmtLinmgmt"
}

Debug Output

Panic Output

Expected Behavior

The user assigned identity should be associated with the virtual machine.

Actual Behavior

No matter what I do, I receive the following error:

Error: Error updating Linux Virtual Machine "linmgmt01" (Resource Group "prd-mgmt01"): compute.VirtualMachinesClient#Update: Failure sending request: StatusCode=400 -- Original Error: Code="LinkedInvalidPropertyId" Message="Property id 'azurerm_user_assigned_identity.linmgmt.id' at path '' is invalid. Expect fully qualified resource Id that start with '/subscriptions/{subscriptionId}' or '/providers/{resourceProviderNamespace}/'."

Steps to Reproduce

My Configuration always passes in the plan, but fails when I run apply.

  1. terraform apply

Important Factoids

I'm running in an azure sponsorship subscription, but every other resource works just fine.

References

None that I can find.

ArcturusZhang commented 4 years ago

Hi @jknash thanks for this issue! I suppose this error is caused by a typo in your config file. identity_ids = ["azurerm_user_assigned_identity.linmgmt.id"] should be

identity_ids = [azurerm_user_assigned_identity.linmgmt.id]

or

identity_ids = ["${azurerm_user_assigned_identity.linmgmt.id}"]

otherwise it will be a literal string with content azurerm_user_assigned_identity.linmgmt.id which is not an acceptable id.

jknash commented 4 years ago

I will try it again, but I believe I tried both. I’ll let you know shortly.


From: Arcturus notifications@github.com Sent: Wednesday, March 11, 2020 10:01:42 PM To: terraform-providers/terraform-provider-azurerm terraform-provider-azurerm@noreply.github.com Cc: jknash jknash@gmail.com; Mention mention@noreply.github.com Subject: Re: [terraform-providers/terraform-provider-azurerm] Can't assign azurerm_user_assigned_identity to virtual machines (#6079)

Hi @jknashhttps://github.com/jknash thanks for this issue! I suppose this error is caused by a typo in your config file. identity_ids = ["azurerm_user_assigned_identity.linmgmt.id"] should be

identity_ids = [azurerm_user_assigned_identity.linmgmt.id]

or

identity_ids = ["${azurerm_user_assigned_identity.linmgmt.id}"]

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/terraform-providers/terraform-provider-azurerm/issues/6079#issuecomment-597982272, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA7KMQ774AFNX6SGJMIBY6TRHBGBNANCNFSM4LF7RSFA.

jknash commented 4 years ago

Nope, you're right. :). Thank you so much! I just removed the quotes and it worked fine. Sorry for wasting your time!!

identity { type = "SystemAssigned, UserAssigned" identity_ids = [azurerm_user_assigned_identity.consul.id] }

ArcturusZhang commented 4 years ago

Nope, you're right. :). Thank you so much! I just removed the quotes and it worked fine. Sorry for wasting your time!!

identity { type = "SystemAssigned, UserAssigned" identity_ids = [azurerm_user_assigned_identity.consul.id] }

No problem, thanks!

ghost commented 4 years ago

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!