1. Answers
  2. Redirecting HTTP To HTTPS On Azure CDN Endpoint

Redirecting HTTP to HTTPS on Azure CDN Endpoint

In this solution, we will set up an Azure CDN Endpoint and configure it to redirect HTTP traffic to HTTPS using Pulumi in TypeScript. The key services involved in this solution are Azure CDN and Pulumi. Azure CDN is a content delivery network service that provides high-bandwidth content delivery, while Pulumi is an infrastructure as code tool that allows you to define and manage cloud resources using programming languages.

Introduction

In this solution, we will set up an Azure CDN Endpoint and configure it to redirect HTTP traffic to HTTPS using Pulumi in TypeScript. The key services involved in this solution are Azure CDN and Pulumi. Azure CDN is a content delivery network service that provides high-bandwidth content delivery, while Pulumi is an infrastructure as code tool that allows you to define and manage cloud resources using programming languages.

Step-by-Step Explanation

Step 1: Create an Azure Resource Group

First, we need to create an Azure Resource Group to hold our resources. This can be done using the azure-native:resources:ResourceGroup resource in Pulumi.

Step 2: Create an Azure CDN Profile

Next, we create an Azure CDN Profile using the azure-native:cdn:Profile resource. The CDN Profile defines the pricing tier and other settings for the CDN.

Step 3: Create an Azure CDN Endpoint

After creating the CDN Profile, we create an Azure CDN Endpoint using the azure-native:cdn:Endpoint resource. The CDN Endpoint represents the specific configuration for delivering content, including the origin and caching rules.

Step 4: Configure HTTP to HTTPS Redirect

Finally, we configure the CDN Endpoint to redirect HTTP traffic to HTTPS. This can be done by setting the isHttpAllowed property to false and the isHttpsAllowed property to true in the CDN Endpoint configuration.

Key Points

  • Azure CDN is used to deliver high-bandwidth content efficiently.
  • Pulumi allows us to define and manage cloud resources using TypeScript.
  • We create an Azure Resource Group, CDN Profile, and CDN Endpoint.
  • We configure the CDN Endpoint to redirect HTTP traffic to HTTPS by setting the appropriate properties.

Conclusion

In this solution, we successfully set up an Azure CDN Endpoint and configured it to redirect HTTP traffic to HTTPS using Pulumi in TypeScript. By leveraging Azure CDN and Pulumi, we can efficiently deliver content and manage our cloud resources using code.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as azureNative from "@pulumi/azure-native";

// Create an Azure Resource Group
const resourceGroup = new azureNative.resources.ResourceGroup("resourceGroup", {
    resourceGroupName: "myResourceGroup",
    location: "WestUS",
});

// Create an Azure CDN Profile
const cdnProfile = new azureNative.cdn.Profile("cdnProfile", {
    resourceGroupName: resourceGroup.name,
    profileName: "myCdnProfile",
    location: resourceGroup.location,
    sku: {
        name: "Standard_Microsoft",
    },
});

// Create an Azure CDN Endpoint
const cdnEndpoint = new azureNative.cdn.Endpoint("cdnEndpoint", {
    resourceGroupName: resourceGroup.name,
    profileName: cdnProfile.name,
    endpointName: "myCdnEndpoint",
    location: resourceGroup.location,
    isHttpAllowed: false, // Disable HTTP
    isHttpsAllowed: true, // Enable HTTPS
    origins: [{
        name: "origin1",
        hostName: "www.example.com",
    }],
});

export const resourceGroupName = resourceGroup.name;
export const cdnProfileName = cdnProfile.name;
export const cdnEndpointName = cdnEndpoint.name;

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up