1
votes

I have to deploy 2 resources and I have an ARM Template as follows:

Template.json

{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "name": "Resource1",
  "properties": {
    "templateLink": {
      "uri": "Test.json"
    },
    "parameters": {
        "secretA": { "value": "" },
        "secretB": { "value": "" }
    }
  }
},
{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "name": "Resource2",
  "properties": {
    "templateLink": {
      "uri": "Test.json"
    },
    "parameters": {
        "secretC": { "value": "" },
        "secretD": { "value": "" },
        "secretE": { "value": "" }
    }
  }
}

Test.json looks as follows:

Test.json

  "resources": 
   {
      "apiVersion": "2018-02-01",
      "type": "Microsoft.Web/sites",
      "name": "",
      "properties": {        
        "appSettings": {  
            //set secrets in this section
        }        
    }
  

I need to set (i) secretA, secretB in appSettings for Resource1 (ii) secretC, secretD, secretE in appsettings for Resource2.

How do I update the above ARM templates to deploy both Resource1 and Resource2 with correct secrets in appSettings?

eg:

Resource1 appSettings should look like this:

"appSettings": {
    {
      "name": "secretA",
      "value": ""
    },
    {
      "name": "secretB",
      "value": ""
    }
}

Resource2 appSettings should look like this:

"appSettings": {
    {
      "name": "secretC",
      "value": ""
    },
    {
      "name": "secretD",
      "value": ""
    },
    {
      "name": "secretE",
      "value": ""
    }
}
1
Yes. You need to check out linked arm templates. - mslot
You already have secret A,B,C or you need to create them in the template? - Tony Ju
I already have secrets available. I need to pass right secrets to appSettings based on Resource. - user989988
Templates are declarative, so when you set the appSettings property with only a subset of the secrets that's what you'll get... so Resource2 will replace Resource1's settings. If you want to "add" within the same deployment you need to set all the appSettings each time you deploy test.json - is that your scenario? - bmoore-msft
Please help me understand - what do you mean by set all the appSettings each time you deploy test.json? - user989988

1 Answers

1
votes

You can add an array parameter. For example

parameters for resource1 as follows

"parameters": {
    "secretSettings": {
        "value": [
            {
                "name": "secretA",
                "value": "",
                "slotSetting": false
            },
            {
                "name": "secretB",
                "value": "",
                "slotSetting": false
            }
        ]
    }
}

parameters for resource2 as follows

"parameters": {
    "secretSettings": {
        "value": [
            {
                "name": "secretC",
                "value": "",
                "slotSetting": false
            },
            {
                "name": "secretD",
                "value": "",
                "slotSetting": false
            }
        ]
    }
}

Then you can refer to the parameter in the resource template.

"appSettings": "[parameters('secretSettings')]"

Please help me understand - what do you mean by set all the appSettings each time you deploy test.json?

This means that the new appSettings will override the existing appSettings, you should add all the appSettings you need in the parameter each time you deploy.