-1

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

microset
  • 276
  • 1
  • 2
  • 12

1 Answers1

1

Two options I can think of:

  1. format the parameter as an object array - then no transform is needed in the template...
"parameters": {
    "Appsetting_For_Fun_App": {
        "type": "array",
        "defaultValue": [
            {
                "name": "client_id",
                "value": ""
            },
            {
                "name": "client_secret",
                "value": ""
            },
            {
                "name": "subscription_Id",
                "value": ""
            }                
        ]
    }

And then on the web app:

    "siteConfig": {
        "linuxFxVersion": "Python|3.9",
        "alwaysOn": true,
        "pythonVersion": "3.9",
        "appSettings": "[parameters('Appsettings_For_Fun_App')]"

but you can also do it via:

  1. 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')]"
    }
  }
}
bmoore-msft
  • 8,376
  • 20
  • 22
  • Thanks bmoore-msft , For the valuable response. Can you please give me the example of the statement of "format the parameter as an object array - then no transform is needed in the template." It would be helpful community as well me. – microset Dec 12 '22 at 04:44
  • Also getting below error message while applying your solution: Template validation failed: The template variable 'Var_Appsetting_For_Fun_App' is not valid: The template function 'items' is not valid. Please see https://aka.ms/arm-template-expressions for usage details.. Please see https://aka.ms/arm-template-expressions for usage details. – microset Dec 12 '22 at 04:59
  • 1
    I added a sample for the first option... re: the error, that sounds like you're using a tool that uses an old apiVersion to create the deployment. You can confirm by trying to deploy the snippet from #2 *or* copy/paste your template into the portal's customer deployment blade. If that doesn't help - post back with how you are deploying the template (and with what version of that "client") – bmoore-msft Dec 13 '22 at 15:51