0
votes

I've looked around the Terraform data source for Azure rm and can't find what I'm looking for. How can I get an azure Managed Identity ID with a Terraform data source?

1

1 Answers

1
votes

There are two types of managed identities: System-assigned and User-assigned.

Some Azure services allow you to enable a managed identity directly on a service instance. For example, you can enable a managed identity on an Azure VM with an identity block. Also, you can export the identity attributes and access the Principal ID via ${azurerm_virtual_machine.example.identity.0.principal_id}.

If you are using this data source to access information about an existing Virtual Machine. You can export the following via the identity block.

output "identity" {
   value = data.azurerm_virtual_machine.example.identity
}
   
output "identity_identity_ids" {
   value = data.azurerm_virtual_machine.example.identity.*.identity_ids
}

output "identity_principal_id" {
  value = data.azurerm_virtual_machine.example.identity.*.principal_id
}

output "identity_tenant_id"{
   value = data.azurerm_virtual_machine.example.identity.*.tenant_id
}

output "identity_type" {
    value = data.azurerm_virtual_machine.example.identity.*.type
}

Result

enter image description here