Reputation: 2942
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?
Upvotes: 0
Views: 385
Reputation: 19195
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"
.
Upvotes: 1