Google Cloud Static Website
The Google Cloud Static Website template scaffolds a Pulumi project that stores site files in a Cloud Storage bucket configured for static website hosting and serves them through Cloud CDN, fronted by a Global Address for low-latency delivery and caching. The template ships with placeholder web content so the project deploys end to end out of the box.
Before you begin#
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
- A current version of Go installed locally
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
- A current version of .NET installed locally
For this walkthrough, you'll need:
- The Pulumi CLI
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
For this walkthrough, you'll need:
- A current version of the Pulumi CLI (Pulumi HCL requires no additional runtime)
- The gcloud CLI (optional, but recommended and used in this guide)
- Permission to manage Cloud Storage and load balancers
Create a new project#
Create a new project from the template:
mkdir my-site; cd my-sitepulumi new static-website-gcp-typescriptmkdir my-site; cd my-sitepulumi new static-website-gcp-typescriptmkdir my-site; cd my-sitepulumi new static-website-gcp-pythonmkdir my-site; cd my-sitepulumi new static-website-gcp-pythonmkdir my-site; cd my-sitepulumi new static-website-gcp-gomkdir my-site; cd my-sitepulumi new static-website-gcp-gomkdir my-site; cd my-sitepulumi new static-website-gcp-csharpmkdir my-site; cd my-sitepulumi new static-website-gcp-csharpmkdir my-site; cd my-sitepulumi new static-website-gcp-yamlmkdir my-site; cd my-sitepulumi new static-website-gcp-yamlmkdir my-site; cd my-sitepulumi new static-website-gcp-hclmkdir my-site; cd my-sitepulumi new static-website-gcp-hclThe pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.
This template’s settings include:
| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set indexDocument "<value>"pulumi config set errorDocument "<value>"| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set indexDocument "<value>"pulumi config set errorDocument "<value>"| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set indexDocument "<value>"pulumi config set errorDocument "<value>"| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set indexDocument "<value>"pulumi config set errorDocument "<value>"| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| indexDocument | The file to use for top-level pages | index.html |
| errorDocument | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set indexDocument <value>pulumi config set errorDocument <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set indexDocument "<value>"pulumi config set errorDocument "<value>"| Key | Description | Default |
|---|---|---|
| gcp:project | The Google Cloud project to deploy into | — |
| path | The path to the folder containing the website | www |
| index_document | The file to use for top-level pages | index.html |
| error_document | The file to use for error pages | error.html |
pulumi config set
:
pulumi config set gcp:project <value>pulumi config set path <value>pulumi config set index_document <value>pulumi config set error_document <value>pulumi config set gcp:project "<value>"pulumi config set path "<value>"pulumi config set index_document "<value>"pulumi config set error_document "<value>"For gcp:project, enter the ID of an existing Google Cloud project. gcloud config get-value project prints the one gcloud is using. Press Enter at the others to keep the defaults.
Review the code#
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the resources it declares.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfcontains the program code that declares your cloud resources.
Take a moment to open them up and have a look. Here’s what’s in index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tf:
import * as pulumi from "@pulumi/pulumi";import * as gcp from "@pulumi/gcp";import * as synced_folder from "@pulumi/synced-folder";
// Import the program's configuration settings.const config = new pulumi.Config();const path = config.get("path") || "www";const indexDocument = config.get("indexDocument") || "index.html";const errorDocument = config.get("errorDocument") || "error.html";
// Create a storage bucket and configure it as a website.const bucket = new gcp.storage.Bucket("bucket", { location: "US", website: { mainPageSuffix: indexDocument, notFoundPage: errorDocument, },});
// Create an IAM binding to allow public read access to the bucket.const bucketIamBinding = new gcp.storage.BucketIAMBinding("bucket-iam-binding", { bucket: bucket.name, role: "roles/storage.objectViewer", members: ["allUsers"],});
// Use a synced folder to manage the files of the website.const syncedFolder = new synced_folder.GoogleCloudFolder("synced-folder", { path: path, bucketName: bucket.name,});
// Enable the storage bucket as a CDN.const backendBucket = new gcp.compute.BackendBucket("backend-bucket", { bucketName: bucket.name, enableCdn: true,});
// Provision a global IP address for the CDN.const ip = new gcp.compute.GlobalAddress("ip", {});
// Create a URLMap to route requests to the storage bucket.const urlMap = new gcp.compute.URLMap("url-map", {defaultService: backendBucket.selfLink});
// Create an HTTP proxy to route requests to the URLMap.const httpProxy = new gcp.compute.TargetHttpProxy("http-proxy", {urlMap: urlMap.selfLink});
// Create a GlobalForwardingRule rule to route requests to the HTTP proxy.const httpForwardingRule = new gcp.compute.GlobalForwardingRule("http-forwarding-rule", { ipAddress: ip.address, ipProtocol: "TCP", loadBalancingScheme: "EXTERNAL", portRange: "80", target: httpProxy.selfLink,});
// Export the URLs and hostnames of the bucket and CDN.export const originURL = pulumi.interpolate`https://storage.googleapis.com/${bucket.name}/index.html`;export const originHostname = pulumi.interpolate`storage.googleapis.com/${bucket.name}`;export const cdnURL = pulumi.interpolate`http://${ip.address}`;export const cdnHostname = ip.address;import pulumiimport pulumi_gcp as gcpimport pulumi_synced_folder as synced_folder
# Import the program's configuration settings.config = pulumi.Config()path = config.get("path") or "www"index_document = config.get("indexDocument") or "index.html"error_document = config.get("errorDocument") or "error.html"
# Create a storage bucket and configure it as a website.bucket = gcp.storage.Bucket( "bucket", location="US", website={ "main_page_suffix": index_document, "not_found_page": error_document, },)
# Create an IAM binding to allow public read access to the bucket.bucket_iam_binding = gcp.storage.BucketIAMBinding( "bucket-iam-binding", bucket=bucket.name, role="roles/storage.objectViewer", members=["allUsers"],)
# Use a synced folder to manage the files of the website.synced_folder = synced_folder.GoogleCloudFolder( "synced-folder", path=path, bucket_name=bucket.name)
# Enable the storage bucket as a CDN.backend_bucket = gcp.compute.BackendBucket( "backend-bucket", bucket_name=bucket.name, enable_cdn=True)
# Provision a global IP address for the CDN.ip = gcp.compute.GlobalAddress("ip")
# Create a URLMap to route requests to the storage bucket.url_map = gcp.compute.URLMap("url-map", default_service=backend_bucket.self_link)
# Create an HTTP proxy to route requests to the URLMap.http_proxy = gcp.compute.TargetHttpProxy("http-proxy", url_map=url_map.self_link)
# Create a GlobalForwardingRule rule to route requests to the HTTP proxy.http_forwarding_rule = gcp.compute.GlobalForwardingRule( "http-forwarding-rule", ip_address=ip.address, ip_protocol="TCP", load_balancing_scheme="EXTERNAL", port_range="80", target=http_proxy.self_link,)
# Export the URLs and hostnames of the bucket and CDN.pulumi.export( "originURL", bucket.name.apply(lambda name: f"https://storage.googleapis.com/{name}/index.html"),)pulumi.export( "originHostname", bucket.name.apply(lambda name: f"storage.googleapis.com/{name}"))pulumi.export("cdnURL", ip.address.apply(lambda address: f"http://{address}"))pulumi.export("cdnHostname", ip.address)package main
import ( "github.com/pulumi/pulumi-gcp/sdk/v10/go/gcp/compute" "github.com/pulumi/pulumi-gcp/sdk/v10/go/gcp/storage" synced "github.com/pulumi/pulumi-synced-folder/sdk/go/synced-folder" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config")
func main() { pulumi.Run(func(ctx *pulumi.Context) error {
// Import the program's configuration settings. cfg := config.New(ctx, "") path := "www" if param := cfg.Get("path"); param != "" { path = param } indexDocument := "index.html" if param := cfg.Get("indexDocument"); param != "" { indexDocument = param } errorDocument := "error.html" if param := cfg.Get("errorDocument"); param != "" { errorDocument = param }
// Create a storage bucket and configure it as a website. bucket, err := storage.NewBucket(ctx, "bucket", &storage.BucketArgs{ Location: pulumi.String("US"), Website: &storage.BucketWebsiteArgs{ MainPageSuffix: pulumi.String(indexDocument), NotFoundPage: pulumi.String(errorDocument), }, }) if err != nil { return err }
// Create an IAM binding to allow public read access to the bucket. _, err = storage.NewBucketIAMBinding(ctx, "bucket-iam-binding", &storage.BucketIAMBindingArgs{ Bucket: bucket.Name, Role: pulumi.String("roles/storage.objectViewer"), Members: pulumi.StringArray{ pulumi.String("allUsers"), }, }) if err != nil { return err }
// Use a synced folder to manage the files of the website. _, err = synced.NewGoogleCloudFolder(ctx, "synced-folder", &synced.GoogleCloudFolderArgs{ Path: pulumi.String(path), BucketName: bucket.Name, }) if err != nil { return err }
// Enable the storage bucket as a CDN. backendBucket, err := compute.NewBackendBucket(ctx, "backend-bucket", &compute.BackendBucketArgs{ BucketName: bucket.Name, EnableCdn: pulumi.Bool(true), }) if err != nil { return err }
// Provision a global IP address for the CDN. ip, err := compute.NewGlobalAddress(ctx, "ip", nil) if err != nil { return err }
// Create a URLMap to route requests to the storage bucket. urlMap, err := compute.NewURLMap(ctx, "url-map", &compute.URLMapArgs{ DefaultService: backendBucket.SelfLink, }) if err != nil { return err }
// Create an HTTP proxy to route requests to the URLMap. httpProxy, err := compute.NewTargetHttpProxy(ctx, "http-proxy", &compute.TargetHttpProxyArgs{ UrlMap: urlMap.SelfLink, }) if err != nil { return err }
// Create a GlobalForwardingRule rule to route requests to the HTTP proxy. _, err = compute.NewGlobalForwardingRule(ctx, "http-forwarding-rule", &compute.GlobalForwardingRuleArgs{ IpAddress: ip.Address, IpProtocol: pulumi.String("TCP"), LoadBalancingScheme: pulumi.String("EXTERNAL"), PortRange: pulumi.String("80"), Target: httpProxy.SelfLink, }) if err != nil { return err }
// Export the URLs and hostnames of the bucket and CDN. ctx.Export("originURL", pulumi.Sprintf("https://storage.googleapis.com/%v/index.html", bucket.Name)) ctx.Export("originHostname", pulumi.Sprintf("storage.googleapis.com/%v", bucket.Name)) ctx.Export("cdnURL", pulumi.Sprintf("http://%v", ip.Address)) ctx.Export("cdnHostname", ip.Address) return nil })}using System.Collections.Generic;using Pulumi;using Gcp = Pulumi.Gcp;using SyncedFolder = Pulumi.SyncedFolder;
return await Deployment.RunAsync(() =>{ // Import the program's configuration settings. var config = new Config(); var path = config.Get("path") ?? "www"; var indexDocument = config.Get("indexDocument") ?? "index.html"; var errorDocument = config.Get("errorDocument") ?? "error.html";
// Create a storage bucket and configure it as a website. var bucket = new Gcp.Storage.Bucket("bucket", new() { Location = "US", Website = new Gcp.Storage.Inputs.BucketWebsiteArgs { MainPageSuffix = indexDocument, NotFoundPage = errorDocument, }, });
// Create an IAM binding to allow public read access to the bucket. var bucketIamBinding = new Gcp.Storage.BucketIAMBinding("bucket-iam-binding", new() { Bucket = bucket.Name, Role = "roles/storage.objectViewer", Members = new[] { "allUsers", }, });
// Use a synced folder to manage the files of the website. var syncedFolder = new SyncedFolder.GoogleCloudFolder("synced-folder", new() { Path = path, BucketName = bucket.Name, });
// Enable the storage bucket as a CDN. var backendBucket = new Gcp.Compute.BackendBucket("backend-bucket", new() { BucketName = bucket.Name, EnableCdn = true, });
// Provision a global IP address for the CDN. var ip = new Gcp.Compute.GlobalAddress("ip");
// Create a URLMap to route requests to the storage bucket. var urlMap = new Gcp.Compute.URLMap("url-map", new() { DefaultService = backendBucket.SelfLink, });
// Create an HTTP proxy to route requests to the URLMap. var httpProxy = new Gcp.Compute.TargetHttpProxy("http-proxy", new() { UrlMap = urlMap.SelfLink, });
// Create a GlobalForwardingRule rule to route requests to the HTTP proxy. var httpForwardingRule = new Gcp.Compute.GlobalForwardingRule("http-forwarding-rule", new() { IpAddress = ip.Address, IpProtocol = "TCP", LoadBalancingScheme = "EXTERNAL", PortRange = "80", Target = httpProxy.SelfLink, });
// Export the URLs and hostnames of the bucket and CDN. return new Dictionary<string, object?> { ["originURL"] = bucket.Name.Apply(name => $"https://storage.googleapis.com/{name}/index.html"), ["originHostname"] = bucket.Name.Apply(name => $"storage.googleapis.com/{name}"), ["cdnURL"] = ip.Address.Apply(address => $"http://{address}"), ["cdnHostname"] = ip.Address, };});name: my-projectdescription: A Pulumi YAML program to deploy a static website on Google Cloudruntime: yaml
# Import the program's configuration settings.config: path: type: string default: www indexDocument: type: string default: index.html errorDocument: type: string default: error.html
resources:
# Create a storage bucket and configure it as a website. bucket: type: gcp:storage:Bucket properties: location: US website: mainPageSuffix: ${indexDocument} notFoundPage: ${errorDocument}
# Create an IAM binding to allow public read access to the bucket. bucket-iam-binding: type: gcp:storage:BucketIAMBinding properties: bucket: ${bucket.name} role: roles/storage.objectViewer members: - allUsers
# Use a synced folder to manage the files of the website. synced-folder: type: synced-folder:index:GoogleCloudFolder properties: path: ${path} bucketName: ${bucket.name}
# Enable the storage bucket as a CDN. backend-bucket: type: gcp:compute:BackendBucket properties: bucketName: ${bucket.name} enableCdn: true
# Provision a global IP address for the CDN. ip: type: gcp:compute:GlobalAddress
# Create a URLMap to route requests to the storage bucket. url-map: type: gcp:compute:URLMap properties: defaultService: ${backend-bucket.selfLink}
# Create an HTTP proxy to route requests to the URLMap. http-proxy: type: gcp:compute:TargetHttpProxy properties: urlMap: ${url-map.selfLink}
# Create a GlobalForwardingRule rule to route requests to the HTTP proxy. http-forwarding-rule: type: gcp:compute:GlobalForwardingRule properties: ipAddress: ${ip.address} ipProtocol: TCP loadBalancingScheme: EXTERNAL portRange: "80" target: ${http-proxy.selfLink}
# Export the URLs and hostnames of the bucket and CDN.outputs: originURL: https://storage.googleapis.com/${bucket.name}/index.html originHostname: storage.googleapis.com/${bucket.name} cdnURL: http://${ip.address} cdnHostname: ${ip.address}terraform { required_providers { gcp = { source = "pulumi/gcp" } synced-folder = { source = "pulumi/synced-folder" } }}
variable "path" { description = "The path to the folder containing the website" type = string default = "www"}
variable "index_document" { description = "The file to use for top-level pages" type = string default = "index.html"}
variable "error_document" { description = "The file to use for error pages" type = string default = "error.html"}
# Create a storage bucket and configure it as a website.resource "gcp_storage_bucket" "bucket" { location = "US"
website = { main_page_suffix = var.index_document not_found_page = var.error_document }}
# Create an IAM binding to allow public read access to the bucket.resource "gcp_storage_bucket_i_a_m_binding" "bucket-iam-binding" { bucket = gcp_storage_bucket.bucket.name role = "roles/storage.objectViewer" members = ["allUsers"]}
# Use a synced folder to manage the files of the website.resource "synced-folder_google_cloud_folder" "synced-folder" { path = var.path bucket_name = gcp_storage_bucket.bucket.name}
# Enable the storage bucket as a CDN.resource "gcp_compute_backend_bucket" "backend-bucket" { bucket_name = gcp_storage_bucket.bucket.name enable_cdn = true}
# Provision a global IP address for the CDN.resource "gcp_compute_global_address" "ip" {}
# Create a URLMap to route requests to the storage bucket.resource "gcp_compute_u_r_l_map" "url-map" { default_service = gcp_compute_backend_bucket.backend-bucket.self_link}
# Create an HTTP proxy to route requests to the URLMap.resource "gcp_compute_target_http_proxy" "http-proxy" { url_map = gcp_compute_u_r_l_map.url-map.self_link}
# Create a GlobalForwardingRule rule to route requests to the HTTP proxy.resource "gcp_compute_global_forwarding_rule" "http-forwarding-rule" { ip_address = gcp_compute_global_address.ip.address ip_protocol = "TCP" load_balancing_scheme = "EXTERNAL" port_range = "80" target = gcp_compute_target_http_proxy.http-proxy.self_link}
# Export the URLs and hostnames of the bucket and CDN.output "origin_url" { value = "https://storage.googleapis.com/${gcp_storage_bucket.bucket.name}/${var.index_document}"}
output "origin_hostname" { value = "storage.googleapis.com/${gcp_storage_bucket.bucket.name}"}
output "cdn_url" { value = "http://${gcp_compute_global_address.ip.address}"}
output "cdn_hostname" { value = gcp_compute_global_address.ip.address}Deploy the project#
First, be sure to enable the Compute Engine API in your project:
gcloud services enable compute.googleapis.com --project $(pulumi config get gcp:project)gcloud services enable compute.googleapis.com --project $(pulumi config get gcp:project)Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.
pulumi uppulumi upPulumi adds a random suffix to most resource names, so the storage bucket bucket becomes something like bucket-4f8a2c1. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist:
- originHostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- originURL
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- cdnHostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.- cdnURL
The HTTP URL of the site, served through Cloud CDN.
- originHostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- originURL
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- cdnHostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.- cdnURL
The HTTP URL of the site, served through Cloud CDN.
- originHostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- originURL
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- cdnHostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.- cdnURL
The HTTP URL of the site, served through Cloud CDN.
- originHostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- originURL
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- cdnHostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.- cdnURL
The HTTP URL of the site, served through Cloud CDN.
- originHostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- originURL
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- cdnHostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.- cdnURL
The HTTP URL of the site, served through Cloud CDN.
- origin_url
The HTTPS URL of the site’s home page, served straight from the storage bucket.
- origin_hostname
The bucket’s host and path on Cloud Storage, like
storage.googleapis.com/bucket-4f8a2c1.- cdn_url
The HTTP URL of the site, served through Cloud CDN.
- cdn_hostname
The IP address of the load balancer in front of Cloud CDN. Point an
Arecord at it to use a custom domain.
Read one any time with pulumi stack output <name>, or pass it to another command. This opens the site in your browser:
open $(pulumi stack output cdnURL)xdg-open $(pulumi stack output cdnURL)Start-Process (pulumi stack output cdnURL)open $(pulumi stack output cdnURL)xdg-open $(pulumi stack output cdnURL)Start-Process (pulumi stack output cdnURL)open $(pulumi stack output cdnURL)xdg-open $(pulumi stack output cdnURL)Start-Process (pulumi stack output cdnURL)open $(pulumi stack output cdnURL)xdg-open $(pulumi stack output cdnURL)Start-Process (pulumi stack output cdnURL)open $(pulumi stack output cdnURL)xdg-open $(pulumi stack output cdnURL)Start-Process (pulumi stack output cdnURL)open $(pulumi stack output cdn_url)xdg-open $(pulumi stack output cdn_url)Start-Process (pulumi stack output cdn_url)A new load balancer can take a few minutes to start answering, so the CDN address may show an error at first. The bucket answers right away. Fetch the home page from it with curl; it prints the template’s placeholder page, which says Hello, world!:
curl -s $(pulumi stack output originURL)curl.exe -s (pulumi stack output originURL)curl -s $(pulumi stack output originURL)curl.exe -s (pulumi stack output originURL)curl -s $(pulumi stack output originURL)curl.exe -s (pulumi stack output originURL)curl -s $(pulumi stack output originURL)curl.exe -s (pulumi stack output originURL)curl -s $(pulumi stack output originURL)curl.exe -s (pulumi stack output originURL)curl -s $(pulumi stack output origin_url)curl.exe -s (pulumi stack output origin_url)Need help?
If pulumi up reports failed to load application credentials, sign in again:
gcloud auth application-default logingcloud auth application-default loginStill stuck? Let us know.
Customize the project#
Projects created with this template expose the following configuration settings:
- path
The path to the folder containing the files of the website. Defaults to
www, which is the name (and relative path) of the folder included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- path
The path to the folder containing the files of the website. Defaults to
www, which is the name (and relative path) of the folder included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- path
The path to the folder containing the files of the website. Defaults to
www, which is the name (and relative path) of the folder included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- path
The path to the folder containing the files of the website. Defaults to
www, which is the name (and relative path) of the folder included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- path
The path to the folder containing the files of the website. Defaults to
www, which is the name (and relative path) of the folder included with the template.- indexDocument
The file to use for top-level pages. Defaults to
index.html.- errorDocument
The file to use for error pages. Defaults to
error.html.
- path
The path to the folder containing the files of the website. Defaults to
www, which is the relative path of the folder included with the template.- index_document
The file to use for top-level pages. Defaults to
index.html.- error_document
The file to use for error pages. Defaults to
error.html.
All of these settings are optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing their values with pulumi config set.
Using your own web content#
If you already have a static website you’d like to deploy on Google Cloud with Pulumi, you can do so either by replacing placeholder content in the www folder or by configuring the stack to point to another folder on your computer with the path setting. Replace ../my-existing-website/build with the path to your site’s files:
pulumi config set path ../my-existing-website/buildpulumi uppulumi config set path ../my-existing-website/buildpulumi upChanging the error page#
The error page is what the site returns for a path it doesn’t have. Point it at the home page instead, then ask the CDN for a page that doesn’t exist. curl prints the home page, with Hello, world!, in place of the template’s Oops! That page wasn't found.:
pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output cdnURL)/no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdnURL)/no-such-page"pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output cdnURL)/no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdnURL)/no-such-page"pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output cdnURL)/no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdnURL)/no-such-page"pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output cdnURL)/no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdnURL)/no-such-page"pulumi config set errorDocument index.htmlpulumi upcurl -s $(pulumi stack output cdnURL)/no-such-pagepulumi config set errorDocument index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdnURL)/no-such-page"pulumi config set error_document index.htmlpulumi upcurl -s $(pulumi stack output cdn_url)/no-such-pagepulumi config set error_document index.htmlpulumi upcurl.exe -s "$(pulumi stack output cdn_url)/no-such-page"To see what else you can add, browse the Google Cloud provider in the Pulumi Registry.
Cleaning up#
You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:
pulumi destroypulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the Google Cloud provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest Google Cloud posts on the Pulumi blog.