Hi,
Is it possible to pass the rgName as a parameter instead of hardcoding it in the rgDelegatedResourceManagement.parameters.json file? When I try with Powershell I receive the following error message:
New-AzDeployment: 10:09:00 - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The value for the template parameter 'rgName' at line '29' and column '39' is not provided. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
Code:
$resourceGroupName = "{rgName}";
$params = @{
Name = '{name}';
Location = '{location}';
TemplateUri = '{templateUri}';
TemplateParameterUri = '{parameterUri}';
}
New-AzSubscriptionDeployment @params -rgName $resourceGroupName -Verbose
If I omit '-rgName $resourceGroupName' I get prompted to enter the rgName but get the same error returned.
Thanks
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi there -
You should be able to call the template as you are doing and pass your own parameters - use $resourceGroupName = "rgName" and syntax such as the following:
$params =@{
Name = 'deployment1';
Location = 'westeurope';
TemplateUri = 'https...';
TemplateParameterUri = 'example'
}
Let us know if you run into further issues!
Hi,
That's what I'm doing but get the error message that says that the rgName parameter is not provided.
I have also tried the following:
$resourceGroupName = "{rgName}";
$params = @{
Name = '{name}';
Location = '{location}';
TemplateUri = '{templateUri}';
TemplateParameterUri = '{parameterUri}';
rgName = $resourceGroupName;
}
New-AzSubscriptionDeployment @params -Verbose
Which results in the same error.
Powershell Core 7.0
Az module version 3.6.1
Thanks @wadstromdev. To confirm, is your code using
$resourceGroupName = "rgName"
or
$resourceGroupName = "{rgName}"
If the latter, can you try it without the brackets, as well as the params format described above?
If I'm misunderstanding the issue please let me know.
Sorry for the late response. I'm running it without brackets, sorry for the confusion.
Perhaps this is a clearer example?
$resourceGroupName = "demo-rg";
$params = @{
Name = 'deployment1';
Location = 'westeurope';
TemplateUri = 'https://raw.githubusercontent.com.../rgDelegatedResourceManagement.json';
TemplateParameterUri = 'https://raw.githubusercontent.com.../rgDelegatedResourceManagement.parameters.json.';
rgName = $resourceGroupName;
}
New-AzSubscriptionDeployment @params -Verbose
@wadstromdev, I notice you have a '.' after .json in the TemplateParameterUri. Can you remove it and try again?
@krnese that's just a typo in the example, I'm running it without the dot after .json.
Which version of PowerShell are you using, and what is the version of the Az.Resources module?
I've tried Powershell Core 7.0 with Az.Resources 1.13.0 and Powershell 5.1 with Az.Resources 1.4.0.
I would also like to add that when I run it with local files it works as intended (exact same files, just locally instead of urls).
$resourceGroupName = "demo-rg";
$params = @{
Name = 'deployment1';
Location = 'westeurope';
TemplateFile = "C:\Users\...\rgDelegatedResourceManagement.json";
TemplateParameterFile = "C:\Users\...\rgDelegatedResourceManagement.parameters.json";
rgName = $resourceGroupName;
}
New-AzSubscriptionDeployment @params -Verbose
@mike-urnun-msft can you triage this over to the powershell team for a response? Doesn't seem to be an issue with the Lighthouse ARM template being used.
@MicrosoftDocs/azure-cxp-triage Can you move this Issue to Azure PowerShell per PMs request above?
@wadstromdev I've looked closer at your issue and believe I see the problem. You are using $params as splatting to the New-AzSubscriptionDeployment cmdlet, which is fine. However, rgName is a parameter of the Resource Manager template, not the cmdlet, so it can't be in the cmdlet hashtable used for splatting, but should be in a different hashtable to pass as parameters to the ARM template using the TemplateParameterObject parameter of New-AzSubscriptionDeployment. This parameter is used if you don't want to hardcode the values in a JSON file and pass that to the cmdlet with TemplateParameterFile (local file) or TemplateParameterUri (hosted file).
See this sample code for using TemplateParameterObject instead of the rgDelegatedResourceManagement.parameters.json file (fill in your values in $templateParams):
$cmdletParams = @{
Name = 'deployment1';
Location = 'westeurope';
TemplateFile = "C:\Users\...\rgDelegatedResourceManagement.json";
TemplateParameterFile = "C:\Users\...\rgDelegatedResourceManagement.parameters.json";
}
$templateParams = @{
mspOfferName = "<myOffer>";
mspOfferDescription = "<myOfferDesc>";
managedByTenantId = "<tenantId>";
authorizations = "[authorizationarray]";
rgName ="demo-rg";
}
New-AzSubscriptionDeployment @cmdletParams -TemplateParameterObject $templateParams -Verbose
Note that it's all or nothing moving to TemplateParameterObject as each method of passing template parameters are in a different parameter set in New-AzDeployment and can't be used together.
Also note that New-AzSubscriptionDeployment is an alias for New-AzDeployment, which is why the link I provided says New-AzDeployment instead.
Let us know if this solves the issue for you!
@MicrosoftDocs/azure-cxp-triage #in-progress
@wadstromdev As we believe we've answered your question, we are going to go ahead and close this issue. If you continue to have the same error, please let us know and we can re-open. For other issues with the docs, please post a new issue. Thanks!
@MicrosoftDocs/azure-cxp-triage #please-close