Pulumi azure: assign access policy to keyvault

123 Views Asked by At

I want to assign an access policy to the Keyvault without importing the keyvault. Since importing a resource like keyvault is a real pain, considering you have to list every required property of the KV(100+ lines with a lot of parametrization needed), I would like to do it in a simpler way.

I want to grant access for an sql server to the keyvault using service principal, here is the code I create the access policy:

access_policy = keyvault.AccessPolicyEntryArgs(
    object_id       = sp_id,
    tenant_id       = auth.tenant_id,
    permissions     = keyvault.PermissionsArgs(keys=[keyvault.KeyPermissions.GET, keyvault.KeyPermissions.UNWRAP_KEY, keyvault.KeyPermissions.WRAP_KEY])
)

How can I assign it to the keyvault? Is there a simpler way to do it?

1

There are 1 best solutions below

0
On

Yes, you can use a get function on the vault, in this case get_vault

vault = keyvault.get_vault(resourceGroupName=rg.name, vaultName="my-key-vault")