1
votes

I am trying to deploy azure resources using Linked ARM template, for which i places the parameters file and template file on blob storage. Link for parameter file and blob storage i need to pass as parameter while executing the azure command from CLI. Below is my sample masterazuredeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {
    "templateBaseUrl": "[parameters('templateBaseUrl')]",
    "parameterBaseUrl": "[parameters('parameterBaseUrl')]",
    "keyVaultDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'keyvaultdeploy.json')]"
  },
  "resources": [
    {
      "apiVersion": "[variables('apiVersionResourceDeployment')]",
      "name": "keyVaultDeployment",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('keyVaultDeployTemplateUrl')]"
        },
        "parametersLink": {
          "uri": "[variables('keyVaultparameterFileUrl')]"
        }
      }
    }

  ]
}

To execute this i am giving following CLI command:

az group deployment create --resource-group abc-devops-test --template-file .\masterazuredeploy.json  --parameters templateBaseUrl="https://test.blob.core
.windows.net/azurestackautomationtest/resourcetemplates/"  parameterBaseUrl="https://test.blob.core.windows.net/azurestackautomationtest/parameters/dev/" --verbose

While executing i am getting following error:

unrecognized template parameter 'templateBaseUrl'. Allowed parameters:
command ran in 1.918 seconds.

I tried parameter values without inverted quotes, with single quotes. Still not working. Where exactly i am missing.

Also tried the another approach, placed both parameters in global.parameters.json as below,

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "templateBaseUrl": {
      "value": "https://test.blob.core.windows.net/azurestackautomation/resourcetemplates/"
    },
    "parameterBaseUrl": {
      "value": "https://test.blob.core.windows.net/azurestackautomation/parameters/dev/"
    }
  }
}

and uploaded this file to blob storage, and given path of blob storage as parameter

az group deployment create --resource-group abc-devops-test --template-file .\masterazuredeploy.json  --parameters https://test.blob.core.windows.net/azur
estackautomationtest/parameters/dev/global.parameters.json  --verbose

But getting below error:

400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/XXXX-xx-x-x-x--x-x/resourcegroups/abc-devops-test/providers/Microsoft.Resources/deployments/masterazuredeploy?api-version=2018-05-01
command ran in 5.646 seconds.
1
Do you change lines when you input the url as the parameter? - Charles Xu
no, its in single line, and its continuation - KCS

1 Answers

3
votes

As I see in your template, you miss setting the parameters, what you did is to input the parameter values to the parameters in the template, no matter the both CLI command you have provided. But you did not set parameters so that no parameters you can use. I suggest you change the template into below:

    {
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "templateBaseUrl": {
            "type": "string"
        },
        "parameterBaseUrl": {
            "type": "string"
        }
    },
    "variables": {
      "keyVaultDeployTemplateUrl": "[uri(parameters('templateBaseUrl'), 'keyvaultdeploy.json')]"
    },
    "resources": [
      {
        "apiVersion": "[variables('apiVersionResourceDeployment')]",    #1
        "name": "keyVaultDeployment",
        "type": "Microsoft.Resources/deployments",
        "properties": {
          "mode": "Incremental",
          "templateLink": {
            "uri": "[variables('keyVaultDeployTemplateUrl')]"
          },
          "parametersLink": {
            "uri": "[variables('keyVaultparameterFileUrl')]"     #2
          }
        }
      }

    ]
  }

And you also miss setting the variables apiVersionResourceDeployment and keyVaultparameterFileUrl. You can use both parameter and variable as you like.