Example of Linked ARM template

Main Template:

It has the usual template structure with the following tabs.

  1. schema
  2. contentVersion
  3. parameters
  4. resources
  5. outputs

You can find the description of these in my previous blog about ARM templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
   //main template parameters
    "StorageContainerSASToken": {
      "type": "string",
      "metadata": {
        "description": "SASToken here Dynamically generated by AzureFileCopyTask"
      }
    },
    "StorageContainerURI": {
      "type": "string",
      "metadata": {
        "description": "Retrieve Azure Storage Container URI"
      }
    },
    "applicationinsight-template-file": {
      "type": "string",
      "metadata": {
        "description": "Specifies Application Insight ARM template file name"
      }
    },
    //Application Insight tempalte parameters
    "AppInsights_name": {
      "type": "string",
      "metadata": {
        "description": "Name of Application Insight"
      }
    },
    "type": {
      "type": "string",
      "metadata": {
        "description": "Type of Application Insight"
      }
    },
    "location": {
      "type": "string",
      "metadata": {
        "description": "location of Application Insight"
      }
    }
  },
  "variables": {
  },
  "resources": [
    {
      "apiVersion": "2015-05-01",
      "name": "linkedTemplate_ApplicationInsight",
      "dependsOn": [
      ],
      "properties": {
        "templateLink": {
          "contentVersion": "1.0.0.0",
          "uri": "[concat(parameters('StorageContainerURI'), parameters('applicationinsight-template-file'), parameters('StorageContainerSASToken'))]"
        },
        "parameters": {
          "type": {
            "value": "[parameters('type')]"
          },
          "AppInsights_name": {
            "value": "[parameters('AppInsights_name')]"
          },
          "location": {
            "value": "[parameters('location')]"
          }
        },
        "mode": "Incremental"
      },
      "type": "Microsoft.Resources/deployments"
    }
  ],
  "outputs": {
    "APPINSIGHTS_INSTRUMENTATIONKEY": {
      "value": "[reference('linkedTemplate_ApplicationInsight').outputs.APPINSIGHTS_INSTRUMENTATIONKEY.value]",
      "type": "string"
    },
    "App_Id": {
      "type": "string",
      "value": "[reference('linkedTemplate_ApplicationInsight').outputs.App_Id.value]"
    }
  }
}

Note: i will update about the storage container SAS token, Storage container uri parameters soon in my next blog.

Main Parameter:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    //common paramters
    "StorageContainerURI": {
      "value": ""   
    },
    "applicationinsight-template-file": {
      "value": "NameOfApplicationInsightTemplateFile"
    },
    "location": {
      "value": "West Europe"
    },
    //application insight parameters
    "AppInsights_name": {
      "value": "ExampleOfLinkedTemplate"
    },
    "type": {
      "value": "other"
    }
  }
}

Linked Template:

Below is the template for creating application insight.

{
 "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
  "AppInsights_name": {
   "type": "string",
   "defaultValue": "YourApplicationInsightName"
   },
  "location": {
   "type": "string"
   },
  "type": {
   "type": "string"
   }
  },
  "variables": {
  },
  "resources": [
  {
    "name": "[parameters('AppInsights_name')]",
    "type": "microsoft.insights/components",
    "location": "[parameters('location')]",
    "apiVersion": "2015-05-01",
    "properties": {
    "ApplicationId": "[parameters('AppInsights_name')]",
    "Application_Type": "[parameters('type')]",
    "Flow_Type": "Redfield",    
    }
   }
  ],
  "outputs": {
   "APPINSIGHTS_INSTRUMENTATIONKEY": {
    "value": "[reference(resourceId('microsoft.insights/components/', parameters('AppInsights_name')), '2015-05-01').InstrumentationKey]",
    "type": "string"
    },
   "App_Id": {
    "type": "string",
    "value": "[reference(resourceId('Microsoft.Insights/components/', parameters('AppInsights_name')), '2015-05-01').AppId]"
   }
  }
 }

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s