Azure-quickstart-templates: Where is a REAL sample of how to pass the secret/values into the 201-key-vault-secret-create template?

Created on 12 Nov 2019  路  7Comments  路  Source: Azure/azure-quickstart-templates

201-key-vault-secret-create

Issue Details

The help indicates that the format for the secret key/value pairs is
Specifies all secrets {\"secretName\":\"\",\"secretValue\":\"\"} wrapped in a secure object.

I have tried this value directly and get:
Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Object'. Actual 'String'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'. (Code: InvalidTemplate)

I also tried: {"secretName":"testme","secretValue":"now"}

and got:
Deployment template validation failed: 'The template resource '[concat(parameters('keyVaultName'), '/', parameters('secretsObject').secrets[copyIndex()].secretName)]' at line '137' and column '5' is not valid: The language expression property 'secrets' doesn't exist, available properties are 'secretName, secretValue'.. Please see https://aka.ms/arm-template-expressions for usage details.'. (Code: InvalidTemplate)

What is a good example of sending in multiple sets of key/value pairs for secret/values and can you please update the documentation so one doesn't hunt all over Google and Stackoverflow trying to find examples?

Most helpful comment

2 days and not one answer? As a professional developer with 25+ years experience I find this UNACCEPTABLE!

All 7 comments

2 days and not one answer? As a professional developer with 25+ years experience I find this UNACCEPTABLE!

I am also getting the same error. Have you guys found a workaround to pass multiple secrets in a template properly?

I don't know what you guys already tried but this example works well for me.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/key-vault-parameter

The following works:

Example deployment from Azure DevOps services:

stored under Variables:

secretsObject: {"secrets":[{"secretName":"Name1","secretValue":"Value1"},{"secretName":"Name2","secretValue":"Value2"}]}

Then you can call using "$(secretsObject)"

or if you want to embed further into the variables:

{"secrets":[{"secretName":"Name1","secretValue":"$(Value1)"},{"secretName":"Name2","secretValue":"$(Value2)"}]}

I managed to work around this by doing the following:

My Input
{"secrets":[{"secretName":"supersecretname","secretValue":"supersecretvalue"}]}

My Parameter
"secretsObject": { "type": "String", "defaultValue": "{}", "metadata": { "description": "Specifies secretsObject as JSON string {\"secrets\":[{\"secretName\":\"x\",\"secretValue\": \"y\"}]}" } }
My Variable
"secretsObject": "[json(parameters('secretsObject'))]",

My Resource
{ "type": "Microsoft.KeyVault/vaults/secrets", "name": "[concat(parameters('keyVaultName'), '/', variables('secretsObject').secrets[copyIndex()].secretName)]", "apiVersion": "2018-02-14", "dependsOn": [ "[concat('Microsoft.KeyVault/vaults/', parameters('keyVaultName'))]" ], "copy": { "name": "secretsCopy", "count": "[length(variables('secretsObject').secrets)]" }, "properties": { "value": "[variables('secretsObject').secrets[copyIndex()].secretValue]" } }

I had the same issue, but I got around it by removing the defaultValue: "{}" from the secretsObject -definition, which it was interpreting as string instead of secureObject.

For me, using Azure CLI to deploy ( az deployment group create --name Dev --resource-group test1 --template-file azuredeploy.json --parameters azuredeploy.parameters.json) I had to do these additional steps to deploy the quickstart template:

  • add tenantId as parameter with my Azure AD tenant id as value
  • Populate the keyVaultName with with my own unique name for it and objectId with object id from my App Registrations in Azure AD.
Was this page helpful?
0 / 5 - 0 ratings