Skip to content

Commit

Permalink
Add CDN with storage account example (#1030)
Browse files Browse the repository at this point in the history
* Add CDN with storage account example

* Update main.bicep

* Update main.bicep

* Fix typo and rebuild main.json
  • Loading branch information
MCKLMT authored Nov 30, 2020
1 parent 9bc21c5 commit 6baaaeb
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/examples/201/cdn-with-storage-account/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
param location string = resourceGroup().location

var storageAccountName = 'storage${uniqueString(resourceGroup().id)}'
var endPointName = 'endpoint-${uniqueString(resourceGroup().id)}'
var profileName = 'CdnProfile1'
var storageAccountHostName = replace(replace(storageAccount.properties.primaryEndpoints.blob, 'https://', ''), '/', '')

resource storageAccount 'Microsoft.Storage/storageAccounts@2020-08-01-preview' = {
location: location
name: storageAccountName
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}

resource cdnProfile 'Microsoft.Cdn/profiles@2020-04-15' = {
location: location
name: profileName
sku: {
name: 'Standard_Akamai'
}
}

resource endpoint 'Microsoft.Cdn/profiles/endpoints@2020-04-15' = {
location: location
name: endPointName
properties: {
originHostHeader: storageAccountHostName
isHttpAllowed: true
isHttpsAllowed: true
queryStringCachingBehavior: 'IgnoreQueryString'
contentTypesToCompress: [
'text/plain'
'text/html'
'text/css'
'application/x-javascript'
'text/javascript'
]
isCompressionEnabled: true
origins: [
{
name: 'origin1'
properties: {
hostName: storageAccountHostName
}
}
]
}
}

output hostName string = endpoint.properties.hostName
output originHostHeader string = endpoint.properties.originHostHeader
78 changes: 78 additions & 0 deletions docs/examples/201/cdn-with-storage-account/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"functions": [],
"variables": {
"storageAccountName": "[format('storage{0}', uniqueString(resourceGroup().id))]",
"endPointName": "[format('endpoint-{0}', uniqueString(resourceGroup().id))]",
"profileName": "CdnProfile1"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2020-08-01-preview",
"location": "[parameters('location')]",
"name": "[variables('storageAccountName')]",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS"
}
},
{
"type": "Microsoft.Cdn/profiles",
"apiVersion": "2020-04-15",
"location": "[parameters('location')]",
"name": "[variables('profileName')]",
"sku": {
"name": "Standard_Akamai"
}
},
{
"type": "Microsoft.Cdn/profiles/endpoints",
"apiVersion": "2020-04-15",
"location": "[parameters('location')]",
"name": "[variables('endPointName')]",
"properties": {
"originHostHeader": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))).primaryEndpoints.blob, 'https://', ''), '/', '')]",
"isHttpAllowed": true,
"isHttpsAllowed": true,
"queryStringCachingBehavior": "IgnoreQueryString",
"contentTypesToCompress": [
"text/plain",
"text/html",
"text/css",
"application/x-javascript",
"text/javascript"
],
"isCompressionEnabled": true,
"origins": [
{
"name": "origin1",
"properties": {
"hostName": "[replace(replace(reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))).primaryEndpoints.blob, 'https://', ''), '/', '')]"
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
]
}
],
"outputs": {
"hostName": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Cdn/profiles/endpoints', split(variables('endPointName'), '/')[0], split(variables('endPointName'), '/')[1])).hostName]"
},
"originHostHeader": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Cdn/profiles/endpoints', split(variables('endPointName'), '/')[0], split(variables('endPointName'), '/')[1])).originHostHeader]"
}
}
}

0 comments on commit 6baaaeb

Please sign in to comment.