0
votes

I have some arm template where creation of subnet resource is dependent on creation of VNet. Below is the code:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Virtual Network"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "metadata": {
        "description": "The IP Address pool for the virtual network in CIDR format."
      }
    },
    "subnetPrefix": {
      "type": "string",
      "metadata": {
        "description": "The IP Address pool for the Subnet in CIDR format."
      }
    },
    "subnetName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Subnet"
      }
    }
  },
  "variables": {
    "templateBaseUrl": "[deployment().properties.templateLink.uri]",
    "virtualNetworkTemplateUrl": "[uri(variables('templateBaseUrl'), 'VirtualNetwork.json')]",
    "subnetTemplateUrl": "[uri(variables('templateBaseUrl'), 'Subnet.json')]",
    "parametersUrl": "[uri(variables('templateBaseUrl'), 'networksubnetnsgtest.parameters.json')]"
  },
  "resources": [
    {
      "apiVersion": "2017-05-10",
      "name": "VnetDeployment",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('virtualNetworkTemplateUrl')]"
        },
        "parameters": {
          "uri": {
            "value": "[variables('parametersUrl')]"
          }
        }
      }
    },
    {
      "apiVersion": "2017-05-10",
      "name": "SubnetDeployment",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[variables('subnetTemplateUrl')]"
        },
        "parameters": {
          "uri": {
            "value": "[variables('parametersUrl')]"
          }
        }
      },
      "dependsOn": [
        "VnetDeployment"
      ]
    }
  ],
  "outputs": {
    "returnedVnetName": {
      "type": "string",
      "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
    },
    "returnedVnetAddressPrefix": {
      "type": "string",
      "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetAddressPrefix'))]"
    }
  }
}

Few parameters are saved in parameter file referred by parameterUrl variable, as you can see. But apart from this, i need to pass additional parameters say like password or any required parameter , which i may be reading from external sources like vault, and need to pass from commandline. How will i pass this in parameters section within resources.

Command i am using to deploy azure template is below:

az group deployment create --resource-group testrg --template-file ${WORKSPACE}/azuredeploy.json --parameters @${WORKSPACE}/networksubnetnsgtest.parameters.json --parameters DBMasterUserPassword=${DBMasterUserPassword}
1
Hi, just want to check whether 4c74356b41's last suggestion is useful for you? If not, feel free to leave comment below. Then we could continue to help for solving this issue.Merlin Liang - MSFT
@MerlinLiang-MSFT I am still in doubt. In above json , i have 2 resources, 1 VNetDeployment and 2) SubnetDeployment. Now SubNetDeployment requires 2 type of parameters. 1) Mentioned in networksubnetnsgtest.parameters.json file which i am passing as "uri": { "value": "[variables('parametersUrl')]" } 2) On some password, which i am passing as --parameter <credentialname>=<credentialvalue> during CLI command execution. Now how will i pass <credentialname>=<credentialvalue> as parameter to SubnetDeployment resource in parameter {} section. Or i need not to pass in parameter {} section.KCS

1 Answers

0
votes

excerpt from official documentation:

az group deployment create -g MyResourceGroup --template-file azuredeploy.json \
    --parameters @params.json --parameters https://mysite/params.json --parameters MyValue=This [email protected]

https://docs.microsoft.com/en-us/cli/azure/group/deployment?view=azure-cli-latest#examples