Using the Azure CLI to provide a key vault in Azure

MVP

 

Start the CloudShell in the Azure portal or go to the following URL: https://shell.azure.com/

Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#Here you can find out which subscription you are working with
az account show

 

#View all subscriptions
az account list --all --output table

 

#change the subscription (if necessary)
az account set --subscription "Name of the Subscription"

 

#Create a resource group
az group create --name "myResourceGroup" --location "westeurope"

 

#Create a key vault (choose your own unique key vault name => replace "twkvdemo2020" with your name)
az keyvault create --name "twkvdemo2020" --resource-group "myResourceGroup" --location "westeurope"

 

#Add a secret to Key Vault
az keyvault secret set --vault-name "twkvdemo2020" --name "ExamplePassword" --value "hVFkk965BuUv"

 

#View the value contained in the secret as plain text
az keyvault secret show --name "ExamplePassword" --vault-name "twkvdemo2020"

 

#To view your secrets
az keyvault secret list --vault-name "twkvdemo2020"

 

#Create access policy
az keyvault set-policy --name "twkvdemo2020" --upn "jwest@tomwechsler.ch" --secret-permissions get, list

 

#Enable Key Vault for deployment
az keyvault update --name "twkvdemo2020" --resource-group "myResourceGroup" --enabled-for-deployment "true"

 

#Enable Key Vault for disk encryption
az keyvault update --name "twkvdemo2020" --resource-group "myResourceGroup" --enabled-for-disk-encryption "true"

 

#Enable Key Vault for template deployment
az keyvault update --name "twkvdemo2020" --resource-group "myResourceGroup" --enabled-for-template-deployment "true"

 

Now you have your own Azure Key Vault deployed with the Azure CLI! Congratulations!

If you don't need the resource group (also to save costs) don't forget the clean up.

 

#Clean up resources
az group delete --name myResourceGroup --yes

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, @azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

 

0 Replies