Azure Key Vault Secrets

The azure_secret helper fetches secrets from Azure Key Vault Service.



user = "<%= azure_secret("demo-#{Terraspace.env}-user") %>"
pass = "<%= azure_secret("demo-#{Terraspace.env}-pass") %>"

For example if you have these secret values:

$ az keyvault secret show --name "demo-dev-user" --vault-name $VAULT | jq '.value'
$ az keyvault secret show --name "demo-dev-pass" --vault-name $VAULT | jq '.value'


user = "bob"
pass = "test"


To set up the Azure Key Vault to use:


TerraspacePluginAzurerm.configure do |config|
  config.secrets.vault = "REPLACE_WITH_YOUR_VAULT_NAME"

Key Vault Access Policy

When you create the Azure Key Vault, only the user used to create the vault has permission to access secrets from it. The Azure AD application also needs Azure Key Vault permissions to retrieve the secret. Else you’ll get an error like this:

The user, group or application ‘appid=EXAMPLE-bb76-432a-b5e4-73a53e0a27f7;oid=1a99ba5c-1b7c-4970-85e9-EXAMPLE;iss=’ does not have secrets get permission on key vault ‘vault-name-EXAMPLE;location=eastus’. For help resolving this issue, please see”

Note: You may have set up the ARM_* env vars in the Learn Azure Configure Guide docs.

Refer to the Docs to set up: Assign a Key Vault access policy using the Azure portal