'Store multiple secrets in Keyvault with one Azure Cli command

Sorry, Noobie here. Perhaps it is a very easy and obvious answer but I am trying to store an extensive list of keyvault secrets and am looking for an easy-ish way to do it compared with entering each one at a time. I figure using the CLI would be a quicker way to get this done than the Azure Resource Manager interface.



Solution 1:[1]

Don't know if this will actually help anyone because its so basic but I ended up creating a for loop script in bash that takes the input files as variables and dynamically creates the keyvault and populates said keyvault with the values based on the values.txt name.

running:

bash keyvault_creator.sh key.txt vault1.txt

runs:

#!/bin/bash

key=$1
value=$2

az keyvault create --location <location> --name "${value%.*}" --resource-group <ResourceGroupName>

paste $key $value | while read if of; do
  echo "$if" "$of"
  az keyvault secret set --vault-name "${value%.*}" --name "$if" --value "$of"
done

Solution 2:[2]

If by "ARM Interface" you mean a template, there is a template already written for this case: https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.keyvault/key-vault-secret-create

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akira_Yam
Solution 2 bmoore-msft