SOLVED

How to pass ARM Variable as parameter of PowerShell in ARM

Brass Contributor

Hi There,

 

I am working on a ARM template and it is working fine however I want to pass ARM variable(s) should be passed in the argument rather hardcoding. Like same storage account name should be used in the arguments.

 

I want to pass the same variable storage account name in the line number 192 -storageaccount

 

Here is the ARM 

 

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "functionAppName": {
      "type": "string",
      "defaultValue": "[format('func-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the Azure Function app."
      }
    },
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "functionWorkerRuntime": {
      "type": "string",
      "defaultValue": "node",
      "allowedValues": [
        "dotnet",
        "node",
        "python",
        "java"
      ],
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    },
    "functionPlanOS": {
      "type": "string",
      "defaultValue": "Windows",
      "allowedValues": [
        "Windows",
        "Linux"
      ],
      "metadata": {
        "description": "Specifies the OS used for the Azure Function hosting plan."
      }
    },
    "functionAppPlanSku": {
      "type": "string",
      "defaultValue": "S1",
      "allowedValues": [
        "S1",
        "S2",
        "S3"
      ],
      "metadata": {
        "description": "Specifies the Azure Function hosting plan SKU."
      }
    },
    "createfunctionkey": {
      "type": "string"
    },
    "apimanagementkey": {
      "type": "securestring",
      "defaultValue": "[base64(newGuid())]"
    },
    "linuxFxVersion": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "Only required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.9'"
      }
    },
    "useridentity": {
    "type": "string"
  },
  "scriptname": {
    "type": "string"
  }
  },
  
  "variables": {
    "hostingPlanName": "[parameters('functionAppName')]",
    "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunctions')]",
    "functionhostkey": "[parameters('apimanagementkey')]",
    "isReserved": "[if(equals(parameters('functionPlanOS'), 'Linux'), true(), false())]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-02-01",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage"
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2021-02-01",
      "name": "[variables('hostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "tier": "Standard",
        "name": "[parameters('functionAppPlanSku')]",
        "family": "S",
        "capacity": 1
      },
      "properties": {
        "reserved": "[variables('isReserved')]"
      }
    },
    {
    "condition": "[equals(parameters('createfunctionkey'), 'yes')]",
    "type": "Microsoft.Web/sites/host/functionkeys",
    "apiVersion": "2020-06-01",
    "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
          ],
    "name": "[concat(parameters('functionAppName'),'/default/apiManagementKey')]",
    "properties": {
        "name": "apiManagementKey",
        "value": "[variables('functionhostkey')]"
       }
     },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2021-02-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "[if(variables('isReserved'), 'functionapp,linux', 'functionapp')]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ],
      "properties": {
        "reserved": "[variables('isReserved')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
        "siteConfig": {
          "alwaysOn": true,
          "linuxFxVersion": "[if(variables('isReserved'), parameters('linuxFxVersion'), json('null'))]",
          "appSettings": [
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[parameters('functionWorkerRuntime')]"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "~14"
            },
            {
              "name": "WEBSITE_RUN_FROM_PACKAGE",
              "value": "1"
            }
          ]
        }
      }
    },
     {
      "type": "Microsoft.Resources/deploymentScripts",
      "name": "[parameters('scriptname')]",
      "apiVersion": "2020-10-01",
      "location": "[parameters('location')]",
      "kind": "AzurePowerShell",
      "identity": {
        "type": "UserAssigned",
        "userAssignedIdentities": {
          "[parameters('useridentity')]": {
          }
        }
      },
      "properties": {
        "azPowerShellVersion": "3.0",
        "primaryScriptUri":
        "https://raw.githubusercontent.com/INGourav/Azure-Resources/master/KeyVaultSecretUsingSAS.ps1",
        "arguments": "-azsub 'Goukumar' -rg 'pstest' -keyvault 'pstestk' -storageaccount 'pstests' -secretname 'secretarm333'",
        "timeout": "PT30M",
        "forceUpdateTag": "utcNow()",
        "retentionInterval": "PT1H",
        "cleanupPreference": "OnSuccess"
      }
    }
  ]
}

 

1 Reply
best response confirmed by GouravIN (Brass Contributor)
Solution

@GouravIN 

You can use concat function to dynamically frame the arguments. You can replace Line 192 with the below code.

 

"arguments":"[concat('-azsub ''Goukumar''',' -rg ''pstest''',' -keyvault ''pstestk''',' -storageaccount ''',variables('storageAccountName'),'''',' -secretname ''secretarm333''')]",

 

Please note the escape sequence is single quote.

 

Thanks,

Praveen Sreeram

https://praveenkumarsreeram.com/  

1 best response

Accepted Solutions
best response confirmed by GouravIN (Brass Contributor)
Solution

@GouravIN 

You can use concat function to dynamically frame the arguments. You can replace Line 192 with the below code.

 

"arguments":"[concat('-azsub ''Goukumar''',' -rg ''pstest''',' -keyvault ''pstestk''',' -storageaccount ''',variables('storageAccountName'),'''',' -secretname ''secretarm333''')]",

 

Please note the escape sequence is single quote.

 

Thanks,

Praveen Sreeram

https://praveenkumarsreeram.com/  

View solution in original post