New-AzureRmResourceGroupDeployment with -TemplateParameterObject doesn't support parameter named "name"
ARM template with parameter named name
$template = @{
'$schema' = "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
contentVersion = "1.0.0.0"
parameters = @{
name = @{ type = "string" }
}
variables = @{}
resources = @()
outputs = @{}
}
ConvertTo-Json -InputObject $template -Depth 1024 | Out-File -File template.json -Force
$templateParams = @{ name = "name-test" }
New-AzureRmResourceGroupDeployment -ResourceGroupName test-rg -TemplateFile template.json -TemplateParameterObject $templateParams
Causes a prompt for a parameter nameFromTemplate
cmdlet New-AzureRmResourceGroupDeployment at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
nameFromTemplate:
If you give it an object representing all the template parameters, it seems like it shouldn't be getting confused.
This is currently by design. If a parameter name used in the template conflicts with the name of an inline parameter (Name is a valid parameter for this cmdlet), then we append the keyword fromTemplate to distinguish between the two. Please let me know if this sounds reasonable and I will close the issue.
@ravbhatnagar but why is that necessary in my situation?
What you are saying makes sense when passing the template parameters as additional cmdlet parameters
New-AzureRmResourceGroupDeployment -ResourceGroupName 'test-rg' -TemplateFile 'template.json' -Name 'deployment-name' -NameFromTemplate 'name-test'
But why should there be any confusion when it is getting passed through -TemplateParameterObject?
New-AzureRmResourceGroupDeployment -ResourceGroupName 'test-rg' -TemplateFile 'template.json' -Name 'deployment-name' -TemplateParameterObject @{ name = "name-test" }
The current design is functionally complete, but it doesn't seem ideal because it was pretty confusing initially when it started prompting me for nameForTemplate. I would argue it is confusing because it is unexpected when using -TemplateParameterObject.
I agree, it can be confusing. Let me see if we can solve this for TemplateParameterObject.
@ravbhatnagar looks like there is actually a bug. I can't find a way to use -TemplateParameterObject and pass a parameter named name.
The following doesn't prompt for any parameters
$template = @{
'$schema' = "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
contentVersion = "1.0.0.0"
parameters = @{
name = @{ type = "string" }
}
variables = @{}
resources = @()
outputs = @{}
}
ConvertTo-Json -InputObject $template -Depth 1024 | Out-File -File template.json -Force
$templateParams = @{ nameFromTemplate = "name-test" }
New-AzureRmResourceGroupDeployment -ResourceGroupName test-rg -TemplateFile template.json -TemplateParameterObject $templateParams
and throws an error saying nameFromTemplate is not a valid parameter name.
WARNING: The output object type of this cmdlet will be modified in a future release.
New-AzureRmResourceGroupDeployment : 4:23:48 PM - Error: Code=InvalidTemplate; Message=Deployment
template validation failed: 'The template parameters 'nameFromTemplate' in the parameters file are
not valid; they are not present in the original template and can therefore not be provided at
deployment time. The only supported parameters for this template are 'name'. Please see
http://aka.ms/arm-deploy/#parameter-file for usage details.'.
At line:13 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName test-group -Tem ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
New-AzureRmResourceGroupDeployment : The deployment validation failed.
At line:13 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName test-group -Tem ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmResourceGroupDeployment], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand
Hopefully the resolution to this issue involves allowing passing a parameter named name through the -TemplateParameterObject
Thanks!
@gregjhogan The current issue is that if you use a parameter name like "name" and specify the value in the parameter Object, it is ignoring that and asking you for the value again. It appends FromTemplate to the param (called name in this case). But in the output, you can see the value you provide for nameFromTemplate is actually used to update the value of "name" parameter.
In above example you should specify templateParams object as $templateParams = @{ name = "name-test" }
You see the above issue, as the parameter name is not defined in the template file. But we will fix the other issue where it should not prompt you if the param is already present in the object.
@ravbhatnagar can you please fix this?! When using either -TemplateParameterFile or -TemplateParameterObject there is no non-interactive way to pass a parameter named name. I would say when it is in the parameter file or parameter object it should know that is what you want to pass for the value. If that is not possible, please at least support what it asks for when in interactive mode by expecting a parameter named nameFromTemplate in my parameter file or object. Thanks!
Any plans to fix this? I'm running into the same issue.
How can I make the script run seamlessly in a Visual Studio Team Services release? Would it be enough to rename the parameter?
@fleed - If you have a parameter name "Name" in your template, it will prompt you to enter value for parameter - "nameFromTemplate". This is because the cmdlet itself has a parameter called Name. So, an easy fix would be to rename the parameter.
We will fix the other issue which is as follows -The current issue is that if you use a parameter name like "name" and specify the value in the parameter Object, it is ignoring that and asking you for the value again. It appends FromTemplate to the param (called name in this case).
I'm suffering from this when I export templates from Azure. If you export a template/parameter set from a created resource, the 'name' fieldname is extended to match the resource in the template and the corresponding parameters file. If you try to export a resource by filling in the values in the gui and clicking on Automation Options, it just uses the 'name' fieldname for the parameter, thereby rendering the automation broken. If you try to use PS to suck in the parameter file with convertfrom-json so that you remove the param, the command fails because the schema does not mark 'name' as valid. There is no -force to accept it, unfortunately. Editing files produced by MS to be consumed by the MS script provided in the same archive is not desirable. I don't want to have to tell clients that the easy tool has a bunch of manual editing steps to fix the problems it creates. So, please let name be used, perhaps with a -pleaseUseTheNameInTheParameterFileEvenThoughThisCmdletHasItsOwnNameParameterBecauseImNotConfused flag. Cheers, Tim broken-template.zip
small note: if you export the templates created by msft through the portal, you have the same issue. workaround at the moment (although silly) is replace the name parameter with for example appname, solved. something that can be easily fixed by msft i'm guessing? ;-)
ravbhatnagar, the thing you are not making clear here, is where to put: $templateParams = @{ name = "name-test" }
This is the template: "parameters": { "name": { "type": "string" },
This is the parameter file:
"parameters": { "type": { "value": "web" }, "name": { "value": "" },
or does the hash get put in the parameter or piped into the script some how?
New-AzureRmResourceGroupDeployment -Name $deploymentName -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath
Or is it at the bottom of the template file:
"resources": [
{
"name": "[parameters('name')]",
"type": "microsoft.insights/components",
"location": "[parameters('regionId')]",
"apiVersion": "2014-08-01",
"properties": {
"ApplicationId": "[parameters('name')]",
"Application_Type": "[parameters('type')]",
"HockeyAppToken": "[parameters('hockeyAppToken')]",
"HockeyAppId": "[parameters('hockeyAppId')]",
"Flow_Type": "Redfield",
"Request_Source": "[parameters('requestSource')]"
}
}
@i255d ,
"name" needs to be renamed, in your ARM template, with a different name so name it so it does not conflict with a parameter called "name" in the cmdlet.
@ravbhatnagar any idea when you will make the fix you previously mentioned? Right now there is no noninteractive way to deploy a template with a parameter named 'name'. Thanks!
@angeloedades @ravbhatnagar I thought my message made it pretty clear that I understand that "name" needs to be renamed, the questions is where? I don't know what a ARM template is. (Azure Resource Manager?)
I did get it to work. First I changed it in the JSON Parameter file:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "type": { "value": "web" }, "name-test": { "value": "Message-Marker-Prod" }, "hockeyAppToken": { "value": "" }, "hockeyAppId": { "value": "" }, "regionId": { "value": "southcentralus" }, "requestSource": { "value": "IbizaAIExtension" } } }
Then I adapted the JSON templet but left the "name" in the resouces:
{ "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "name-test": { "type": "string" }, "type": { "type": "string" }, "hockeyAppToken": { "type": "string" }, "hockeyAppId": { "type": "string" }, "regionId": { "type": "string" }, "requestSource": { "type": "string" } }, "resources": [ { "name": "[parameters('name-test')]", "type": "microsoft.insights/components", "location": "[parameters('regionId')]", "apiVersion": "2014-08-01", "properties": { "ApplicationId": "[parameters('name-test')]", "Application_Type": "[parameters('type')]", "HockeyAppToken": "[parameters('hockeyAppToken')]", "HockeyAppId": "[parameters('hockeyAppId')]", "Flow_Type": "Redfield", "Request_Source": "[parameters('requestSource')]" } } ] }
Again this seemed to work. Everywhere it says Name-Test has been changed from Name
@ravbhatnagar any update on this issue?
It would be a good enough solution to check this during the template validation and provide a meaningful error message.
I've also encountered this bug. Not sure why data inside a parameter of type Hashtable would conflict with a named parameter. Is this because "-TemplateParameterObject" has ValueFromPipelineByPropertyName on it? In the mean time, I guess I'll rename my parameter. I'd be interested in having a deeper understanding though.
What worked for me: don't have a parameters called "name", this will cause the prompt. Use something else, e.g. resourceName.
Agreed, @abatishchev , that is an easy fix. It is a bit strange though that the conflict is introduced when downloading the pre-created template from Azure.
FYI: This also fails (i.e. prompts for this nameFromTemplate parameter) when you pass it in by file -- which is makes no sense, because, it's obviously not conflicting with a cmdlet parameter.
And because of this behavior, some of the default Azure RM templates are broken (i.e. if you go to create a new Storage account and export the template there, it doesn't work -- it makes you pass in the nameFromTemplate parameter, even though it's stored right there in the auto generated .json file).