Add azure-nextgen-cs-static-website example
ADD
azure-nextgen-cs-static-website/MyStack.cs
+using System;
+using Pulumi;
+using AzureNextGen = Pulumi.AzureNextGen;
+using Cdn = Pulumi.AzureNextGen.Cdn.Latest;
+using Resources = Pulumi.AzureNextGen.Resources.Latest;
+using Storage = Pulumi.AzureNextGen.Storage.Latest;
+using Pulumi.Random;
+
+class MyStack : Stack
+{
+ public MyStack()
+ {
+ // TODO: Remove after autonaming support is added.
+ var randomSuffix = new RandomString("randomSuffix", new RandomStringArgs
+ {
+ Length = 10,
+ Special = false,
+ Upper = false,
+ });
+
+ var config = new Config();
+ var storageAccountName = config.Get("storageAccountName") != null ? Output.Create(config.Get("storageAccountName")!) : randomSuffix.Result.Apply(result => $"site{result}");
+ var cdnEndpointName = config.Get("cdnEndpointName") != null ? Output.Create(config.Get("cdnEndpointName")!) : storageAccountName.Apply(result => $"cdn-endpnt-{result}");
+ var cdnProfileName = config.Get("cdnProfileName") != null ? Output.Create(config.Get("cdnProfileName")!) : storageAccountName.Apply(result => $"cdn-profile-{result}");
+
+ var resourceGroup = new Resources.ResourceGroup("resourceGroup", new Resources.ResourceGroupArgs
+ {
+ ResourceGroupName = randomSuffix.Result.Apply(result => $"rg{result}"),
+ });
+
+ var profile = new Cdn.Profile("profile", new Cdn.ProfileArgs
+ {
+ ProfileName = cdnProfileName,
+ ResourceGroupName = resourceGroup.Name,
+ Sku = new Cdn.Inputs.SkuArgs
+ {
+ Name = Cdn.SkuName.Standard_Microsoft,
+ },
+ });
+
+ var storageAccount = new Storage.StorageAccount("storageAccount", new Storage.StorageAccountArgs
+ {
+ AccessTier = Storage.AccessTier.Hot,
+ AccountName = storageAccountName,
+ EnableHttpsTrafficOnly = true,
+ Encryption = new Storage.Inputs.EncryptionArgs
+ {
+ KeySource = Storage.KeySource.Microsoft_Storage,
+ Services = new Storage.Inputs.EncryptionServicesArgs
+ {
+ Blob = new Storage.Inputs.EncryptionServiceArgs
+ {
+ Enabled = true,
+ },
+ File = new Storage.Inputs.EncryptionServiceArgs
+ {
+ Enabled = true,
+ },
+ },
+ },
+ Kind = Storage.Kind.StorageV2,
+ NetworkRuleSet = new Storage.Inputs.NetworkRuleSetArgs
+ {
+ Bypass = Storage.Bypass.AzureServices,
+ DefaultAction = Storage.DefaultAction.Allow,
+ },
+ ResourceGroupName = resourceGroup.Name,
+ Sku = new Storage.Inputs.SkuArgs
+ {
+ Name = Storage.SkuName.Standard_LRS,
+ },
+ });
+
+ var endpointOrigin = storageAccount.PrimaryEndpoints.Apply(pe => pe.Web.Replace("https://", "").Replace("/", ""));
+
+ var endpoint = new Cdn.Endpoint("endpoint", new Cdn.EndpointArgs
+ {
+ ContentTypesToCompress = { },
+ EndpointName = cdnEndpointName,
+ IsCompressionEnabled = false,
+ IsHttpAllowed = false,
+ IsHttpsAllowed = true,
+ OriginHostHeader = endpointOrigin,
+ Origins =
+ {
+ new Cdn.Inputs.DeepCreatedOriginArgs
+ {
+ HostName = endpointOrigin,
+ HttpsPort = 443,
+ Name = Output.Tuple(randomSuffix.Result, cdnEndpointName).Apply(t => $"{t.Item2}-origin-{t.Item1}"),
+ },
+ },
+ ProfileName = profile.Name,
+ QueryStringCachingBehavior = Cdn.QueryStringCachingBehavior.NotSet,
+ ResourceGroupName = resourceGroup.Name,
+ });
+
+ // Enable static website support
+ var staticWebsite = new Storage.StorageAccountStaticWebsite("staticWebsite", new Storage.StorageAccountStaticWebsiteArgs
+ {
+ AccountName = storageAccount.Name,
+ ResourceGroupName = resourceGroup.Name,
+ IndexDocument = "index.html",
+ Error404Document = "404.html",
+ });
+
+ var index_html = new Storage.Blob("index_html", new Storage.BlobArgs
+ {
+ BlobName = "index.html",
+ ResourceGroupName = resourceGroup.Name,
+ AccountName = storageAccount.Name,
+ ContainerName = staticWebsite.ContainerName,
+ Type = Storage.BlobType.Block,
+ Source = new FileAsset("./wwwroot/index.html"),
+ ContentType = "text/html",
+ });
+ var notfound_html = new Storage.Blob("notfound_html", new Storage.BlobArgs
+ {
+ BlobName = "404.html",
+ ResourceGroupName = resourceGroup.Name,
+ AccountName = storageAccount.Name,
+ ContainerName = staticWebsite.ContainerName,
+ Type = Storage.BlobType.Block,
+ Source = new FileAsset("./wwwroot/404.html"),
+ ContentType = "text/html",
+ });
+
+ // Web endpoint to the website
+ this.StaticEndpoint = storageAccount.PrimaryEndpoints.Apply(primaryEndpoints => primaryEndpoints.Web);
+
+ // CDN endpoint to the website.
+ // Allow it some time after the deployment to get ready.
+ this.CdnEndpoint = endpoint.HostName.Apply(hostName => $"https://{hostName}");
+ }
+
+ [Output("staticEndpoint")]
+ public Output<string> StaticEndpoint { get; set; }
+ [Output("cdnEndpoint")]
+ public Output<string> CdnEndpoint { get; set; }
+}

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

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

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

Add azure-nextgen-cs-static-website example (#920)