1

I am using Azure CLI (Linux host) to deploy Infra as code, I am having different deployment files and parameter files,

My goal is to avoid duplicate input parameters,

main_parameters.json:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    "artifactLocation": {
        "value": "xxxx_xxxx_path"
    }
    }
}

main.deploy:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "artifactLocation": {
            "type": "string",
            "metadata": {
                "description": "artifactLocation path"
            }   
        }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "linkedTemplate",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri":"[parameters('artifactLocation')]",
          "contentVersion":"1.0.0.0"
        }
      }
    }
  ],
  "outputs": {
  }
}

sub_parameters.json:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    "artifactLocation": {
        "value": "xxxx_xxxx_path"
    },
    "customName": {
        "value": "Name"
    }
    }
}

sub_deploy.json:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "artifactLocation": {
              "type": "string",
              "metadata": {
                  "description": "artifactLocation path"
              }   
          },
          "customName": {
              "type": "string",
              "metadata": {
                  "description": "some name"
              }   
          }
    },
    "variables": {},
    "resources": [
      {
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2019-10-01",
        "name": "[parameters('customName')]",
        "properties": {
          "mode": "Incremental",
          "templateLink": {
            "uri":"[parameters('artifactLocation')]",
            "contentVersion":"1.0.0.0"
          }
        }
      }
    ],
    "outputs": {
    }
  }

Both main.parameters and sub.parameters has input parameter "artifactLocation", Is there a way i Can import parameters from main_parameters to sub_deploy.json. so that I will avoid adding same parameters in multiple parameter files.

I am fine to create resources main_deploy and sub_deploy together, but I want to keep main_deploy and sub_deploy files separately for easy readability

Chamberlain
  • 881
  • 5
  • 17
Vidya
  • 547
  • 1
  • 10
  • 26
  • There is no way to import the parameter, but you can use common parameters file for both the template but it is not best practice to do so. – Jagrati Modi Jun 19 '20 at 07:49
  • You can merge the parameter files with Powershell and use the newly created file. Please find some information here: https://stackoverflow.com/questions/52107054/merge-concatenate-multiple-json-files-using-powershell – Markus Meyer Oct 04 '20 at 04:42

0 Answers0