Home > OS >  How to use parameter value inside the siteconfig in ARM template?
How to use parameter value inside the siteconfig in ARM template?

Time:12-10

I have below code for the create function app :

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "parameters": {
        "storage_account_name": {
            "type": "string",
            "defaultValue": "test"
        },
        "location": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string"
        },
        "App_Plan_Name": {
            "type": "string",
            "defaultValue": "test1"
        },
        "Function_App_Name": {
            "type": "string",
            "defaultValue": "funapwp11"
        },
        "AI_Name": {
            "type": "string",
            "defaultValue": "appinsiwghts"
        },
        "Appsetting_For_Fun_App": {
            "type": "object",
            "defaultValue": {
                "client_id": "",
                "client_secret": "",
                "subscription_id": "",
                "tenant_id": "",
                "FUNCTIONS_EXTENSION_VERSION": "~4",
                "FUNCTIONS_WORKER_RUNTIME": "python"

            }
        }
    },
    "variables": {
        "unique_Storage_Name": "[concat(parameters('storage_account_name'),uniqueString(resourceGroup().id))]",
        //"Unique_App_Service_Name": "[concat(parameters('App_Service_Name'),uniqueString(resourceGroup().id))]",
        "Unique_App_Plan_Name": "[concat(parameters('App_Plan_Name'),uniqueString(resourceGroup().id))]",
        "Unique_Fun_App_Name": "[concat(parameters('Function_App_Name'),uniqueString(resourceGroup().id))]",
        "Unique_AI_Name": "[concat(parameters('AI_Name'),uniqueString(resourceGroup().id))]"

    },
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2022-03-01",
            "location": "[parameters('location')]",
            "name": "[variables('Unique_Fun_App_Name')]",
            "kind": "functionapp",
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', variables('Unique_App_Plan_Name'))]",
                "[resourceId('Microsoft.Storage/storageAccounts',variables('unique_Storage_Name'))]",
                "[resourceId('Microsoft.Insights/components',variables('Unique_AI_Name'))]"
            ],
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms',variables('Unique_App_Plan_Name'))]",
                "httpsOnly": true,
                "enabled": true,
                "adminEnabled": true,
                "sku": "Basic",
                "siteProperties": {
                    "properties": [
                        {
                            "name": "LinuxFxVersion",
                            "value": "Python|3.9"
                        },
                        {
                            "name": "WindowsFxVersion",
                            "value": null
                        }
                    ]
                },
                "siteConfig": {
                    "linuxFxVersion": "Python|3.9",
                    "alwaysOn": true,
                    "pythonVersion": "3.9",
                    "appSettings": [
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId('Microsoft.Insights/components', variables('Unique_AI_Name'))).InstrumentationKey]"
                        },
                        {
                            "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
                            "value": "[reference(resourceId('Microsoft.Insights/components',variables('Unique_AI_Name')),'2020-02-02-preview').ConnectionString]"

                        },
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[format('DefaultEndpointsProtocol=https;AccountName={0};EndpointSuffix={1};AccountKey={2}', variables('Unique_Storage_Name'), environment().suffixes.storage, listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Unique_Storage_Name')), '2021-08-01').keys[0].value)]"
                        }


                    ]
                }
            }
        }
    ]

}

I want use Appsetting_For_Fun_App parameter inside the properties >> siteConfig >> appSettings.

Parameter:

"Appsetting_For_Fun_App": {
                "type": "object",
                "defaultValue": {
                    "client_id": "",
                    "client_secret": "",
                    "subscription_id": "",
                    "tenant_id": "",
                    "FUNCTIONS_EXTENSION_VERSION": "~4",
                    "FUNCTIONS_WORKER_RUNTIME": "python"
    
                }
            }

I need like that

"appSettings": [
                    {
                        "name": "[parameters('Appsetting_For_Fun_App')]",
                        "value": "[parameters('Appsetting_For_Fun_App')]"
                    },

I have tried multiple way but no luck. You can refer the question: Azure resource manager template website app settings

CodePudding user response:

Two options I can think of:

  1. format the parameter as an object array - then no transform is needed in the template... but you can also do it via:
  2. transform in the template, simplest to illustrate using a variable:
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "myValues": {
      "type": "object",
      "defaultValue": {
        "setting1": "value1",
        "setting2": "value2",
        "setting3": "value3"
      }
    }
  },
  "variables": {
    "copy": [
      {
        "name": "foo",
        "count": "[length(items(parameters('myValues')))]",
        "input": {
          "name": "[items(parameters('myValues'))[copyIndex('foo')].key]",
          "value": "[items(parameters('myValues'))[copyIndex('foo')].value]"
        }
      }
    ]
  },
  "resources": [],
  "outputs": {
    "bar": {
      "type": "array",
      "value": "[variables('foo')]"
    }
  }
}

CodePudding user response:

here in this image your answerenter image description here

  • Related