1
votes

I am using PowerShell ISE to recreate an existing database using the script generated in the Azure Portal for the resource. I discovered that PS, does not use the script path, so I added these lines at the top:

Write-Host $PSScriptRoot
Push-Location $PSScriptRoot
Write-Host "Path: $(get-location)"

I added some testing code to make sure the template.json and parameters.json are present and that is working:

# Start the deployment
Write-Host "Starting deployment...";
Write-Host "Testing: $templateFilePath"
if(Test-Path $templateFilePath) {
    Write-Host "FOUND: $templateFilePath"

    if(Test-Path $parametersFilePath) {
        Write-Host "FOUND: $parametersFilePath"
        New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath;
    } else {
        New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath;
    }

}

However, the script is still ignoring the defaultValue parameters in template.json:

"advisors_DropIndex_name": {
    "defaultValue": "DropIndex",
    "type": "String"
},

parameters.json:

"advisors_DropIndex_name": {
    "value": null
},

The script returns the following:

New-AzureRmResourceGroupDeployment : 5:17:30 PM - Error: Code=InvalidDeploymentParameterValue; Message=The value of deployment parameter 'keys_ServiceManaged_name' is null. Please specify the value or use the parameter reference. See https://aka.ms/arm-deploy/#parameter-file for details. At C:\Users\longoj\Downloads\ExportedTemplate-DEEAResourceGroup\deploy.ps1:110 char:9 + New-AzureRmResourceGroupDeployment -ResourceGroupName $resour ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

If set the value in parameters.json:

"advisors_DropIndex_name": {
    "value": "DropIndex"
},

the script validation moves on to the next parameter, and there are a lot of them. So it looks like the template.json file's defaultvalue parameter is being ignored.

I am using:

Version           : 5.1.2
Name              : Azure
Author            : Microsoft Corporation
PowerShellVersion : 3.0

What am I doing wrong ?

1

1 Answers

1
votes

The defaultValue will be used in case there is no value provided during deployment (e.g. parameters.json).

In your case, you are providing that parameter value, which is null and it is invalid per error message (e.g. InvalidDeploymentParameterValue).

Remove the entire following code from the parameters.json file if you want the default value to be applied.

"advisors_DropIndex_name": {
    "value": null
},

Find more details at https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-parameters.