Adding static website example for azure-nextgen
ADD
azure-nextgen-static-website/Pulumi.yaml
+name: azure-nextgen-ts-static-website
+runtime: nodejs
+description: An example of a static website hosted on Azure Blob Storage + Azure CDN.

ADD
azure-nextgen-static-website/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Static Website Using Azure Blob Storage and CDN
+Based on https://github.com/zemien/static-website-ARM-template
+
+
+This example configures [Static website hosting in Azure Storage](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website).
+
+In addition to the Storage itself, a CDN is configured to serve files from the Blob container origin. This may be useful if you need to serve files via HTTPS from a custom domain (not shown in the example).
+
+## Running the App
+
+1. Create a new stack:
+
+ ```
+ $ pulumi stack init dev
+ ```
+
+1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
+
+ ```
+ $ az login
+ ```
+
+1. Restore NPM dependencies:
+
+ ```
+ $ npm install
+ ```
+
+1. Run `pulumi up` to preview and deploy changes:
+
+ ```
+ $ pulumi up
+ Previewing changes:
+ ...
+
+ Performing changes:
+ ...
+ Resources:
+ + 9 created
+ Duration: 2m52s
+ ```
+
+1. Check the deployed website endpoint:
+
+ ```
+ $ pulumi stack output staticEndpoint
+ https://websitesbc90978a1.z20.web.core.windows.net/
+ $ curl "$(pulumi stack output staticEndpoint)"
+ <html>
+ <body>
+ <h1>This file is served from Blob Storage (courtesy of Pulumi!)</h1>
+ </body>
+ </html>
+ ```

ADD
azure-nextgen-static-website/index.ts
+// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
+
+import * as cdn from "@pulumi/azure-nextgen/cdn/latest";
+import * as resources from "@pulumi/azure-nextgen/resources/latest";
+import * as storage from "@pulumi/azure-nextgen/storage/latest";
+import * as pulumi from "@pulumi/pulumi";
+import * as random from "@pulumi/random";
+
+// TODO: Remove after autonaming support is added.
+const randomSuffix = new random.RandomString("random", {
+ length: 10,
+ special: false,
+ upper: false,
+});
+
+const resourceGroup = new resources.ResourceGroup("resourceGroup", {
+ resourceGroupName: pulumi.interpolate `rg${randomSuffix.result}`,
+ location: "westus",
+});
+
+const config = new pulumi.Config();
+const storageAccountName = config.get("storageAccountName") || pulumi.interpolate `site${randomSuffix.result}`;
+const cdnEndpointName = config.get("cdnEndpointName") || pulumi.interpolate `cdn-endpnt-${storageAccountName}`;
+const cdnProfileName = config.get("cdnProfileName") || pulumi.interpolate `cdn-profile-${storageAccountName}`;
+
+const profile = new cdn.Profile("profile", {
+ profileName: cdnProfileName,
+ resourceGroupName: resourceGroup.name,
+ sku: {
+ name: "Premium_Verizon",
+ },
+ tags: {},
+});
+
+const storageAccount = new storage.StorageAccount("storageAccount", {
+ accessTier: "Hot",
+ accountName: storageAccountName,
+ enableHttpsTrafficOnly: true,
+ encryption: {
+ keySource: "Microsoft.Storage",
+ services: {
+ blob: {
+ enabled: true,
+ },
+ file: {
+ enabled: true,
+ },
+ },
+ },
+ kind: storage.Kind.StorageV2,
+ networkRuleSet: {
+ bypass: "AzureServices",
+ defaultAction: "Allow",
+ ipRules: [],
+ virtualNetworkRules: [],
+ },
+ resourceGroupName: resourceGroup.name,
+ sku: {
+ name: "Standard_LRS",
+ },
+ tags: {},
+});
+
+const endpointOrigin = storageAccount.primaryEndpoints.apply(ep => ep.web.replace("https://", "").replace("/", ""));
+
+const endpoint = new cdn.Endpoint("CDNEndpoint", {
+ contentTypesToCompress: [],
+ endpointName: cdnEndpointName,
+ isCompressionEnabled: false,
+ isHttpAllowed: true,
+ isHttpsAllowed: true,
+ originHostHeader: endpointOrigin,
+ origins: [{
+ hostName: endpointOrigin,
+ httpPort: 80,
+ httpsPort: 443,
+ name: pulumi.interpolate `${cdnEndpointName}-origin-${randomSuffix.result}`,
+ }],
+ profileName: profile.name,
+ queryStringCachingBehavior: "NotSet",
+ resourceGroupName: resourceGroup.name,
+ tags: {},
+});
+
+// Enable static website support
+const staticWebsite = new storage.StorageAccountStaticWebsite("staticWebsite", {
+ accountName: storageAccount.name,
+ resourceGroupName: resourceGroup.name,
+ indexDocument: "index.html",
+ error404Document: "404.html",
+});
+
+// Upload the files
+["index.html", "404.html"].map(name =>
+ new storage.Blob(name, {
+ blobName: name,
+ resourceGroupName: resourceGroup.name,
+ accountName: storageAccount.name,
+ containerName: staticWebsite.containerName,
+ type: storage.BlobType.Block,
+ source: new pulumi.asset.FileAsset(`./wwwroot/${name}`),
+ contentType: "text/html",
+ }),
+);
+
+// Web endpoint to the website
+export const staticEndpoint = storageAccount.primaryEndpoints.web;
+
+// CDN endpoint to the website.
+// Allow it some time after the deployment to get ready.
+export const cdnEndpoint = pulumi.interpolate`https://${endpoint.hostName}/`;

ADD
azure-nextgen-static-website/package.json
+{
+ "name": "azure-ts-static-website",
+ "devDependencies": {
+ "@types/node": "^8.0.0"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "^2.0.0",
+ "@pulumi/random": "^3.0.2",
+ "@pulumi/azure-nextgen": "^0.6.1"
+ }
+}

ADD
azure-nextgen-static-website/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es2016",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts",
+ "staticWebsite.ts"
+ ]
+}

ADD
azure-nextgen-static-website/wwwroot/404.html
+<html>
+ <body>
+ <h1>That's a 404! Still, from the Blob Storage.</h1>
+ </body>
+</html>

ADD
azure-nextgen-static-website/wwwroot/index.html
+<html>
+ <body>
+ <h1>This file is served from Blob Storage (courtesy of Pulumi!)</h1>
+ </body>
+</html>

Adding static website example for azure-nextgen