forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
100 lines (90 loc) · 3.36 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as azure from "@pulumi/azure";
import * as pulumi from "@pulumi/pulumi";
import { CDNCustomDomainResource } from "./cdnCustomDomain";
/**
* The location where our resource group and the resources under it will be created.
*
* To externalize this value, and make this configurable across environments/stacks,
* learn more at https://www.pulumi.com/docs/intro/concepts/config/.
*/
const location = azure.Locations.WestUS;
// Create an Azure Resource Group
const resourceGroup = new azure.core.ResourceGroup("resourceGroup", {
location: location,
});
// Create an Azure resource (Storage Account) so we can point the CDN endpoint to it.
const storageAccount = new azure.storage.Account("storageAccount", {
resourceGroupName: resourceGroup.name,
accountTier: "Standard",
accountReplicationType: "LRS",
});
/**
* Create a Blob container in the storage account,
* to store any static files. The CDN endpoint will be pointed at the
* endpoint for this blob container.
*/
const blobContainer = new azure.storage.Container("blobContainer", {
storageAccountName: storageAccount.name,
// Make each "blob" in the container publicly accessible.
// DO NOT set this property if you are going to store sensitive files!
containerAccessType: "blob",
});
const cdnProfile = new azure.cdn.Profile("cdnProfile", {
resourceGroupName: resourceGroup.name,
// Choose an appropriate SKU to use.
// https://docs.microsoft.com/en-us/azure/cdn/cdn-features
sku: "Standard_Akamai",
});
const cdnEndpoint = new azure.cdn.Endpoint("cdnEndpoint", {
/**
* Specify a well-known name for the endpoint name,
* so you can add a CNAME record for your custom domain
* pointing to this CDN endpoint to it.
*
* For example, the URL for this CDN endpoint when it is created
* would be `my-cdn-endpoint.azureedge.net`.
*/
name: "my-cdn-endpoint",
resourceGroupName: resourceGroup.name,
profileName: cdnProfile.name,
isHttpsAllowed: true,
isHttpAllowed: false,
isCompressionEnabled: true,
originHostHeader: storageAccount.primaryBlobHost,
contentTypesToCompresses: [
"text/plain",
"text/html",
"text/css",
"text/javascript",
"application/x-javascript",
"application/javascript",
"application/json",
"application/xml",
"image/png",
"image/jpeg",
],
origins: [
{
name: "cdn-origin",
hostName: storageAccount.primaryBlobHost,
httpsPort: 443,
},
],
});
export const cdnEndpointUrl = pulumi.interpolate`https://${cdnEndpoint.hostName}`;
export const cdnCustomDomainResource = new CDNCustomDomainResource("cdnCustomDomain", {
resourceGroupName: resourceGroup.name,
// Ensure that there is a CNAME record for mycompany.com pointing to my-cdn-endpoint.azureedge.net.
// You would do that in your domain registrar's portal.
customDomainHostName: "mycompany.com",
profileName: cdnProfile.name,
endpointName: cdnEndpoint.name,
/**
* This will enable HTTPS through Azure's one-click
* automated certificate deployment. The certificate is
* fully managed by Azure from provisioning to automatic renewal
* at no additional cost to you.
*/
httpsEnabled: true,
}, { parent: cdnEndpoint });