I am running into a cycle error when assigning keyvault access policy to the resource’s managed identity I am trying to create. Currently we have modules for App_Config, Windows Function, Redis, etc.. All of them are created with either system or user managed identiy. They all need access to keyvaults.
Currently I use the generate the keyvault’s access_policies by looping thru the resources and grabbing the manage_identity for each resource.
What is the best way to break this cycle error and apply keyvault access to resources???
2
Answers
Cycle error occurs, when the azurerm_key_vault depends on the azurerm_managed_identity resource, when assigning access policy to the managed identity. Whereas azurerm_managed_identity resource also depends on the azurerm_key_vault resource, when using Key Vault’s ID .
To resolve this cycle error, separating managed identity creation and the assignment of the Key Vault access policy into two separate Terraform configurations or modules is the way.
Indirect dependency between the resources can be avoided and cycle error can be resolved.
code:
Reference: Importing multiple Azure KeyVault Access Policies | StackOverflow
If you were to use user-assigned managed identities created by the
azurerm_user_assigned_identity
resource then you could:azurerm_user_assigned_identity
.