When creating new resource in Azure that have secrets like passwords or ssl certificates you can securely save them in the Key Vault and get them from the Key Vault when you deploy. Only the people who need access to the secrets can read and write them to the Key Vault. In a infrastructure as code scenario the secrets are supplied when deploying your templates to Azure. The code it self will be free of secrets.

To accomplish this you need to do following:

  • Deploy a Key Vault
  • Add the secret to the Key Vault
  • Create a ARM template that uses the secret on deployment

Deploy a Key Vault
When you need to access the Key Vault from you deployment, you need to set the enabledForTemplateDeployment to true. The following ARM template will create a Key Vault that is enable for deployments:

Add secret to the Key Vault
Secret can be added to the Key Vault with an ARM template, with Powershell or you can add it in the portal.

Create a ARM template that uses the secret on deployment
The last step is using the secrets in your arm templates. This can be done by making a reference to your key vault in the parameters:

This way of referencing the password is to static for a infrastructure as code scenario. The next step is to get the secret dynacly from the Key Vault in the environment you are deploying into. This can be done by giving the resourceGroupName, vaultName and secretName as parameters.

This way you are able to get the secrets from the Key Vault in the subscription your are deploying into.

Some extra information can be found at: resource-manager-keyvault-parameter