Azure-docs: ARM template examples for rules engine

Created on 12 Nov 2019  Â·  5Comments  Â·  Source: MicrosoftDocs/azure-docs

Please could you add some examples for setting these rules up in ARM templates? Redirect http to https and redirect www to root domain are common ones that would be good examples.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri2 assigned-to-author azure-cdsvc doc-enhancement triaged

Most helpful comment

@bhp15973 I couldn't find any, hence the question. I ended up with the following (for Standard_Microsoft CDN):

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environmentName": {
      "type": "string",
      "metadata": {
        "description": "The name of the environment to provision."
      }
    },
    "baseName": {
      "defaultValue": "[concat('melplashciderfest', parameters('environmentName'))]",
      "type": "string"
    },
    "storageAccountSku": {
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Standard_ZRS",
        "Premium_LRS",
        "Premium_ZRS",
        "Standard_GZRS",
        "Standard_RAGZRS"
      ],
      "type": "string",
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "cdnProfileSku": {
      "defaultValue": "Standard_Microsoft",
      "allowedValues": [
        "Standard_Microsoft",
        "Standard_Akamai",
        "Standard_Verizon",
        "Premium_Verizon"
      ],
      "type": "string"
    },
    "cdnWWWHostName": {
      "defaultValue": "[concat('www.', parameters('environmentName'), '.melplashciderfestival.org')]",
      "type": "string"
    }
  },
  "variables": {
    "storageAccount": {
      "apiVersion": "2019-06-01",
      "name": "[parameters('baseName')]",
      "hostName": "[concat(parameters('baseName'), '.z35.web.core.windows.net')]"
    },
    "cdn": {
      "apiVersion": "2019-04-15",
      "location": "global",
      "profile": {
        "name": "[concat(parameters('baseName'), '-cdn')]",
        "endpoint": {
          "name": "[concat(parameters('baseName'), '-endpoint')]",
          "originHostName": "[variables('storageAccount').hostName]",
          "customDomain": {
            "wwwName": "[concat('www-', parameters('baseName'), '-custom-domain')]",
            "wwwHostName": "[concat(parameters('cdnWWWHostName'))]"
          }
        }
      }
    }
  },
  "resources": [
    {
      "name": "[variables('storageAccount').name]",
      "type": "Microsoft.Storage/storageAccounts",
      "kind": "StorageV2",
      "location": "[resourceGroup().location]",
      "apiVersion": "[variables('storageAccount').apiVersion]",
      "sku": {
        "name": "[parameters('storageAccountSku')]"
      },
      "properties": {
        "supportsHttpsTrafficOnly": false
      }
    },
    {
      "type": "Microsoft.Cdn/profiles",
      "apiVersion": "[variables('cdn').apiVersion]",
      "location": "[variables('cdn').location]",
      "name": "[variables('cdn').profile.name]",
      "sku": {
        "name": "[parameters('cdnProfileSku')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccount').name)]"
      ],
      "resources": [
        {
          "type": "endpoints",
          "apiVersion": "[variables('cdn').apiVersion]",
          "location": "[variables('cdn').location]",
          "name": "[variables('cdn').profile.endpoint.name]",
          "dependsOn": [
            "[variables('cdn').profile.name]"
          ],
          "properties": {
            "originHostHeader": "[variables('cdn').profile.endpoint.originHostName]",
            "isHttpAllowed": true,
            "isHttpsAllowed": true,
            "queryStringCachingBehavior": "IgnoreQueryString",
            "isCompressionEnabled": true,
            "contentTypesToCompress": [
              "text/plain",
              "text/html",
              "text/css",
              "text/javascript",
              "application/x-javascript",
              "application/javascript",
              "application/json",
              "application/xml"
            ],
            "optimizationType": "GeneralWebDelivery",
            "origins": [
              {
                "name": "[variables('cdn').profile.endpoint.name]",
                "properties": {
                  "hostName": "[variables('cdn').profile.endpoint.originHostName]",
                  "httpPort": 80,
                  "httpsPort": 443
                }
              }
            ],
            "deliveryPolicy": {
              "rules": [
                {
                  "name": "RedirectToHttps",
                  "order": "1",
                  "conditions": [
                    {
                      "name": "RequestScheme",
                      "parameters": {
                        "@odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleRequestSchemeConditionParameters",
                        "operator": "Equal",
                        "matchValues": [
                          "HTTP"
                        ]
                      }
                    }
                  ],
                  "actions": [
                    {
                      "name": "UrlRedirect",
                      "parameters": {
                        "@odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRedirectActionParameters",
                        "redirectType": "Moved",
                        "destinationProtocol": "Https"
                      }
                    }
                  ]
                }
              ]
            }
          },
          "resources": [
            {
              "type": "customDomains",
              "apiVersion": "[variables('cdn').apiVersion]",
              "name": "[variables('cdn').profile.endpoint.customDomain.wwwName]",
              "dependsOn": [
                "[variables('cdn').profile.endpoint.name]"
              ],
              "properties": {
                "hostName": "[variables('cdn').profile.endpoint.customDomain.wwwHostName]"
              }
            }
          ]
        }
      ]
    }
  ],
  "outputs": {
    "outStorageAccountName": {
      "type": "string",
      "value": "[variables('storageAccount').name]"
    },
    "outStorageAccountHostName": {
      "type": "string",
      "value": "[variables('storageAccount').hostName]"
    },
    "outCdnWWWCustomDomainName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.customDomain.wwwName]"
    },
    "outCdnCustomDomainWWWHostName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.customDomain.wwwHostName]"
    },
    "outCdnEndpointName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.name]"
    },
    "outCdnProfileName": {
      "type": "string",
      "value": "[variables('cdn').profile.name]"
    }
  }
}

All 5 comments

@simonvane , Thank you for your feedback. We will take a look and get back to you.

@msrini-MSFT Any update on this?

@mdgattuso , Can you please take a look?

@simonvane @msrini-MSFT
Could you please add some link where can I find arm template examples which can solve redirect http to https?

@bhp15973 I couldn't find any, hence the question. I ended up with the following (for Standard_Microsoft CDN):

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environmentName": {
      "type": "string",
      "metadata": {
        "description": "The name of the environment to provision."
      }
    },
    "baseName": {
      "defaultValue": "[concat('melplashciderfest', parameters('environmentName'))]",
      "type": "string"
    },
    "storageAccountSku": {
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Standard_ZRS",
        "Premium_LRS",
        "Premium_ZRS",
        "Standard_GZRS",
        "Standard_RAGZRS"
      ],
      "type": "string",
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "cdnProfileSku": {
      "defaultValue": "Standard_Microsoft",
      "allowedValues": [
        "Standard_Microsoft",
        "Standard_Akamai",
        "Standard_Verizon",
        "Premium_Verizon"
      ],
      "type": "string"
    },
    "cdnWWWHostName": {
      "defaultValue": "[concat('www.', parameters('environmentName'), '.melplashciderfestival.org')]",
      "type": "string"
    }
  },
  "variables": {
    "storageAccount": {
      "apiVersion": "2019-06-01",
      "name": "[parameters('baseName')]",
      "hostName": "[concat(parameters('baseName'), '.z35.web.core.windows.net')]"
    },
    "cdn": {
      "apiVersion": "2019-04-15",
      "location": "global",
      "profile": {
        "name": "[concat(parameters('baseName'), '-cdn')]",
        "endpoint": {
          "name": "[concat(parameters('baseName'), '-endpoint')]",
          "originHostName": "[variables('storageAccount').hostName]",
          "customDomain": {
            "wwwName": "[concat('www-', parameters('baseName'), '-custom-domain')]",
            "wwwHostName": "[concat(parameters('cdnWWWHostName'))]"
          }
        }
      }
    }
  },
  "resources": [
    {
      "name": "[variables('storageAccount').name]",
      "type": "Microsoft.Storage/storageAccounts",
      "kind": "StorageV2",
      "location": "[resourceGroup().location]",
      "apiVersion": "[variables('storageAccount').apiVersion]",
      "sku": {
        "name": "[parameters('storageAccountSku')]"
      },
      "properties": {
        "supportsHttpsTrafficOnly": false
      }
    },
    {
      "type": "Microsoft.Cdn/profiles",
      "apiVersion": "[variables('cdn').apiVersion]",
      "location": "[variables('cdn').location]",
      "name": "[variables('cdn').profile.name]",
      "sku": {
        "name": "[parameters('cdnProfileSku')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccount').name)]"
      ],
      "resources": [
        {
          "type": "endpoints",
          "apiVersion": "[variables('cdn').apiVersion]",
          "location": "[variables('cdn').location]",
          "name": "[variables('cdn').profile.endpoint.name]",
          "dependsOn": [
            "[variables('cdn').profile.name]"
          ],
          "properties": {
            "originHostHeader": "[variables('cdn').profile.endpoint.originHostName]",
            "isHttpAllowed": true,
            "isHttpsAllowed": true,
            "queryStringCachingBehavior": "IgnoreQueryString",
            "isCompressionEnabled": true,
            "contentTypesToCompress": [
              "text/plain",
              "text/html",
              "text/css",
              "text/javascript",
              "application/x-javascript",
              "application/javascript",
              "application/json",
              "application/xml"
            ],
            "optimizationType": "GeneralWebDelivery",
            "origins": [
              {
                "name": "[variables('cdn').profile.endpoint.name]",
                "properties": {
                  "hostName": "[variables('cdn').profile.endpoint.originHostName]",
                  "httpPort": 80,
                  "httpsPort": 443
                }
              }
            ],
            "deliveryPolicy": {
              "rules": [
                {
                  "name": "RedirectToHttps",
                  "order": "1",
                  "conditions": [
                    {
                      "name": "RequestScheme",
                      "parameters": {
                        "@odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleRequestSchemeConditionParameters",
                        "operator": "Equal",
                        "matchValues": [
                          "HTTP"
                        ]
                      }
                    }
                  ],
                  "actions": [
                    {
                      "name": "UrlRedirect",
                      "parameters": {
                        "@odata.type": "#Microsoft.Azure.Cdn.Models.DeliveryRuleUrlRedirectActionParameters",
                        "redirectType": "Moved",
                        "destinationProtocol": "Https"
                      }
                    }
                  ]
                }
              ]
            }
          },
          "resources": [
            {
              "type": "customDomains",
              "apiVersion": "[variables('cdn').apiVersion]",
              "name": "[variables('cdn').profile.endpoint.customDomain.wwwName]",
              "dependsOn": [
                "[variables('cdn').profile.endpoint.name]"
              ],
              "properties": {
                "hostName": "[variables('cdn').profile.endpoint.customDomain.wwwHostName]"
              }
            }
          ]
        }
      ]
    }
  ],
  "outputs": {
    "outStorageAccountName": {
      "type": "string",
      "value": "[variables('storageAccount').name]"
    },
    "outStorageAccountHostName": {
      "type": "string",
      "value": "[variables('storageAccount').hostName]"
    },
    "outCdnWWWCustomDomainName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.customDomain.wwwName]"
    },
    "outCdnCustomDomainWWWHostName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.customDomain.wwwHostName]"
    },
    "outCdnEndpointName": {
      "type": "string",
      "value": "[variables('cdn').profile.endpoint.name]"
    },
    "outCdnProfileName": {
      "type": "string",
      "value": "[variables('cdn').profile.name]"
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamesDLD picture JamesDLD  Â·  3Comments

mrdfuse picture mrdfuse  Â·  3Comments

varma31 picture varma31  Â·  3Comments

paulmarshall picture paulmarshall  Â·  3Comments

jharbieh picture jharbieh  Â·  3Comments