Question

Difficulty: EasyAzure Key Vault Secret, Key, and Certificate Management

You need to use the Azure CLI to create a new Azure Key Vault, store a database connection string as a secret, and then retrieve that secret. What is the correct sequence of Azure CLI commands to achieve this?

  1. 1Run `az group create` to create a resource group.
  2. 2Run `az keyvault create` to create the Key Vault.
  3. 3Run `az keyvault secret set` to add the secret.
  4. 4Run `az keyvault secret show` to retrieve the secret value.

Answer

The correct sequence is to first create the resource group with `az group create`, then create the Key Vault with `az keyvault create`, next store the secret with `az keyvault secret set`, and finally retrieve the secret with `az keyvault secret show`.
To store and retrieve a secret using the Azure CLI, you must progress from global resource containers to the specific secret value. First, the resource group is created. Next, the Key Vault is provisioned within that resource group. Once the vault exists, the secret is written using the set command, and finally, the secret is retrieved using the show command.

Step-by-Step Solution

1
Create the resource group.
A resource group is provisioned in Azure.
Azure Key Vault requires a resource group to hold the resource.
2
Create the Key Vault.
The Key Vault instance is created inside the resource group.
Secrets must be stored within a specific Key Vault instance.
3
Set the secret.
The secret is successfully written to the Key Vault.
The connection string must be written to Key Vault storage before it can be referenced or read.
4
Show the secret.
The secret's value and metadata are returned.
Retrieving the secret requires querying the specific secret name inside the vault.

Key Concept

Azure Key Vault CLI Secret Management Lifecycle
Rate this question