Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active August 27, 2019 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/c6a8785310b6bd128ef1b3caa1463e72 to your computer and use it in GitHub Desktop.
Save isaacabraham/c6a8785310b6bd128ef1b3caa1463e72 to your computer and use it in GitHub Desktop.
Example of an F# DSL designed for building ARM Templates
open ARM
let template =
{ Parameters = [
"environment"
"location"
"pricingTier"
]
Variables = [
"environment", "[toLower(parameters('environment'))]"
"prefix", "[concat('safe-', variables('environment'))]"
"appServicePlan", "[concat(variables('prefix'), '-web-host')]"
"web", "[concat(variables('prefix'), '-web')]"
"storage", "[concat('safe', variables('environment'), 'storage')]"
"insights", "[concat(variables('prefix'), '-insights')]"
]
Outputs = [
"webAppName", Variable "web"
"webAppPassword", WebSite.PUBLISHING_PASSWORD (Variable "web")
]
Resources = [
let appInsights = { Name = Variable "insights"; LinkedWebsite = Variable "web"; Location = Variable "location" }
let storage = { Name = Variable "storage"; Sku = Standard; Location = Variable "location" }
let serverFarm =
{ Sku = Parameter "pricingTier"
Name = Variable "appServicePlan"
Location = Parameter "location"
WebApps = [
{ Name = Variable "web"
AppSettings =
{ Settings = [
"public_path", Literal "./public"
"APPINSIGHTS_INSTRUMENTATIONKEY", Literal appInsights.InstrumentationKey
"STORAGE_CONNECTIONSTRING", Literal storage.Key
AppSettings.RUN_FROM_PACKAGE
AppSettings.WEBSITE_NODE_DEFAULT_VERSION "8.1.4"
]
Dependencies = [
StorageAccount storage
AppInsights appInsights
]
}
AppInsights = Some (Variable "insights")
Dependencies = [
StorageAccount storage
AppInsights appInsights
]
}
]
}
yield AppInsights appInsights
yield StorageAccount storage
yield ServerFarm serverFarm
]
}
let template = arm {
parameters [ "environment"; "location"; "pricingTier" ]
variable "environment" (toLower (Parameter "environment"))
variable "prefix" (concat [ Literal "safe-"; Variable "environment" ])
variable "appServicePlan" (withPostfix "-web-host")
variable "web" (withPostfix "-web")
variable "storage" (concat [ Literal "safe"; Variable "environment"; Literal "storage" ])
variable "insights" (withPostfix "-insights")
location (Parameter "location")
resource "storage" Standard
resource "web"
(webApp {
service_plan_name (Variable "appServicePlan")
sku (Parameter "pricingTier")
use_app_insights (Variable "insights")
run_from_package
website_node_default_version "8.1.4"
setting "public_path" "./public"
setting "STORAGE_CONNECTIONSTRING" (Storage.accountKey (Variable "storage"))
depends_on AStorageAccount (Variable "storage")
})
output "webAppName" (Variable "web")
output "webAppPassword" (WebSite.PUBLISHING_PASSWORD (Variable "web"))
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string"
},
"location": {
"type": "string"
},
"pricingTier": {
"type": "string"
}
},
"variables": {
"environment": "[toLower(parameters('environment'))]",
"prefix": "[concat('safe-', variables('environment'))]",
"appServicePlan": "[concat(variables('prefix'), '-web-host')]",
"web": "[concat(variables('prefix'), '-web')]",
"storage": "[concat('safe', variables('environment'), 'storage')]",
"insights": "[concat(variables('prefix'), '-insights')]"
},
"resources": [
{
"type": "Microsoft.Insights/components",
"kind": "web",
"name": "[variables('insights')]",
"location": "[parameters('location')]",
"apiVersion": "2014-04-01",
"scale": null,
"tags": {
"[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('web'))]": "Resource",
"displayName": "AppInsightsComponent"
},
"properties": {
"name": "[variables('insights')]"
}
},
{
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"name": "[variables('storage')]",
"apiVersion": "2017-10-01",
"location": "[parameters('location')]",
"tags": {}
},
{
"type": "Microsoft.Web/serverfarms",
"sku": {
"name": "[parameters('pricingTier')]"
},
"name": "[variables('appServicePlan')]",
"apiVersion": "2016-09-01",
"location": "[parameters('location')]",
"properties": {
"name": "[variables('appserviceplan')]",
"perSiteScaling": false,
"reserved": false
}
},
{
"type": "Microsoft.Web/sites",
"name": "[variables('web')]",
"apiVersion": "2016-08-01",
"location": "[parameters('location')]",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlan'))]",
"siteConfig": {
"appSettings": [
{
"name": "public_path",
"value": "./public"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(concat('Microsoft.Insights/components/', variables('insights'))).InstrumentationKey]"
},
{
"name": "STORAGE_CONNECTIONSTRING",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storage'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts/', variables('storage')), '2017-10-01').keys[0].value)]"
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "1"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.1.4"
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlan'))]",
"[resourceId('Microsoft.Storage/storageAccounts/', variables('storage'))]",
"[resourceId('Microsoft.Insights/components/', variables('insights'))]"
],
"resources": [
{
"apiVersion": "2016-08-01",
"name": "Microsoft.ApplicationInsights.AzureWebSites",
"type": "siteextensions",
"dependsOn": [
"[resourceId('Microsoft.Web/sites/', variables('web'))]"
],
"properties": {}
}
]
}
],
"outputs": {
"webAppName": {
"type": "string",
"value": "[variables('web')]"
},
"webAppPassword": {
"type": "string",
"value": "[list(resourceId('Microsoft.Web/sites/config', variables('web'), 'publishingcredentials'), '2014-06-01').properties.publishingPassword]"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment