0

I am trying to override some properties in a template parameter file in a powershell script then pass the object to the Test-AzureRmResourceGroupDeployment cmdlet to test it. The following works;

Test-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile 'template.json' -TemplateParameterFile 'parameters.json'

However, it does not work when I load the parameters and pass the object;

$params = Get-Content 'parameters.json' | Out-String | ConvertFrom-Json | ConvertPSObjectToHashtable
Test-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile 'template.json' -TemplateParameterObject $params.parameters

The ConvertPSObjectToHashtable function is one I got from here.

When I run the second command, I get the following error;

Code    : InvalidTemplate
Message : Deployment template validation failed: 'The provided value for the template parameter 'location' at line '7' and column '22' is not valid.'.
Details : 

Why doesn't it accept the parameters object, and how do I fix it?

Steztric
  • 2,832
  • 2
  • 24
  • 43

1 Answers1

1

I test in my lab, I get the same error log with you. The root reason is Azure json template is like below:

   "adminUsername": {
      "value": "ghuser"
    },

If json template is like below, the function will work.

"adminUsername":"ghuser"

You also could test in your lab, if you transfer following parameters to - TemplateParameterObject, it works fine.

PS D:\compare> $parms

Name                           Value
----                           -----
adminPassword                  ********
dnsLabelPrefix                 shuitest123
adminUsername                  shui

However, your $params.parameters is like below:

PS D:\compare> $params.parameters

Name                           Value
----                           -----
adminPassword                  {value}
dnsLabelPrefix                 {value}
adminUsername                  {value}

What you need to do is convert Azure parameter json file to adminUsername:shui or modify json file like "adminUsername":"ghuser".

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • Ah ok. Thanks for the tips. Unfortunately the `-TemplateParameterObject` is not very well documented. Your suggestion might not work for password that is passed as a reference to a key vault secret. I can always give it a try. – Steztric Jul 07 '17 at 07:44