|
| 1 | +--- |
| 2 | +title: Azure Quickstart - Create an Azure key vault and a secret using Bicep | Microsoft Docs |
| 3 | +description: Quickstart showing how to create Azure key vaults, and add secrets to the vaults using Bicep. |
| 4 | +services: key-vault |
| 5 | +author: schaffererin |
| 6 | +tags: azure-resource-manager |
| 7 | +ms.service: key-vault |
| 8 | +ms.subservice: secrets |
| 9 | +ms.topic: quickstart |
| 10 | +ms.custom: mvc, subject-armqs, devx-track-azurepowershell, mode-arm |
| 11 | +ms.date: 04/08/2022 |
| 12 | +ms.author: v-eschaffer |
| 13 | +#Customer intent: As a security admin who is new to Azure, I want to use Key Vault to securely store keys and passwords in Azure. |
| 14 | +--- |
| 15 | + |
| 16 | +# Quickstart: Set and retrieve a secret from Azure Key Vault using Bicep |
| 17 | + |
| 18 | +[Azure Key Vault](../general/overview.md) is a cloud service that provides a secure store for secrets, such as keys, passwords, certificates, and other secrets. This quickstart focuses on the process of deploying a Bicep file to create a key vault and a secret. |
| 19 | + |
| 20 | +[!INCLUDE [About Bicep](../../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +To complete this article: |
| 25 | + |
| 26 | +* If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 27 | + |
| 28 | +## Review the Bicep file |
| 29 | + |
| 30 | +The template used in this quickstart is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/key-vault-create/). |
| 31 | + |
| 32 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.keyvault/key-vault-create/main.bicep"::: |
| 33 | + |
| 34 | +Two Azure resources are defined in the Bicep file: |
| 35 | + |
| 36 | +* [**Microsoft.KeyVault/vaults**](/azure/templates/microsoft.keyvault/vaults): create an Azure key vault. |
| 37 | +* [**Microsoft.KeyVault/vaults/secrets**](/azure/templates/microsoft.keyvault/vaults/secrets): create a key vault secret. |
| 38 | + |
| 39 | +## Deploy the Bicep file |
| 40 | + |
| 41 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 42 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 43 | + |
| 44 | + # [CLI](#tab/CLI) |
| 45 | + |
| 46 | + ```azurecli |
| 47 | + az group create --name exampleRG --location eastus |
| 48 | + az deployment group create --resource-group exampleRG --template-file main.bicep --parameters keyVaultName=<vault-name> objectID=<object-id> |
| 49 | + ``` |
| 50 | +
|
| 51 | + # [PowerShell](#tab/PowerShell) |
| 52 | +
|
| 53 | + ```azurepowershell |
| 54 | + New-AzResourceGroup -Name exampleRG -Location eastus |
| 55 | + New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -keyVaultName "<vault-name>" -objectID "<object-id>" |
| 56 | + ``` |
| 57 | +
|
| 58 | + --- |
| 59 | +
|
| 60 | + > [!NOTE] |
| 61 | + > Replace **\<vault-name\>** with the name of the key vault. Replace **\<object-id\>** with the object ID of a user, service principal, or security group in the Azure Active Directory tenant for the vault. The object ID must be unique for the list of access policies. Get it by using Get-AzADUser or Get-AzADServicePrincipal cmdlets. |
| 62 | +
|
| 63 | + When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 64 | +
|
| 65 | +## Review deployed resources |
| 66 | +
|
| 67 | +Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group. |
| 68 | +
|
| 69 | +# [CLI](#tab/CLI) |
| 70 | +
|
| 71 | +```azurecli-interactive |
| 72 | +az resource list --resource-group exampleRG |
| 73 | +``` |
| 74 | + |
| 75 | +# [PowerShell](#tab/PowerShell) |
| 76 | + |
| 77 | +```azurepowershell-interactive |
| 78 | +Get-AzResource -ResourceGroupName exampleRG |
| 79 | +``` |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Clean up resources |
| 84 | + |
| 85 | +When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources. |
| 86 | + |
| 87 | +# [CLI](#tab/CLI) |
| 88 | + |
| 89 | +```azurecli-interactive |
| 90 | +az group delete --name exampleRG |
| 91 | +``` |
| 92 | + |
| 93 | +# [PowerShell](#tab/PowerShell) |
| 94 | + |
| 95 | +```azurepowershell-interactive |
| 96 | +Remove-AzResourceGroup -Name exampleRG |
| 97 | +``` |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Next steps |
| 102 | + |
| 103 | +In this quickstart, you created a key vault and a secret using Bicep and then validated the deployment. To learn more about Key Vault and Bicep, continue on to the articles below. |
| 104 | + |
| 105 | +- Read an [Overview of Azure Key Vault](../general/overview.md) |
| 106 | +- Learn more about [Bicep](../../azure-resource-manager/bicep/overview.md) |
| 107 | +- Review the [Key Vault security overview](../general/security-features.md) |
0 commit comments