The module is designed to deploy and manage a Google Cloud Storage bucket optimized for static website hosting. It provides configurable multi-regional storage class and location, support for SPA (Single-page application) virtual routing, bucket versioning control, customizable CORS policies and creates a set of website DNS records.

Static website in GCP Cloud Storage

The module manages static website in GCP Cloud Storage
$350
BUY
Log in to Corewide IaC registry

Once you have a Corewide Solutions Portal account, this one-time action will use your browser session to retrieve credentials:

 shellterraform login solutions.corewide.com
Provision instructions

Initialize mandatory providers:

Copy and paste into your Terraform configuration and insert the variables:

 hclmodule "tf_gcp_static_website" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-static-website/google"
  version = "~> 1.0.0"

  # specify module inputs here or try one of the examples below
  ...
}

Initialize the setup:

 shellterraform init
Define update strategy

Corewide DevOps team strictly follows Semantic Versioning Specification to provide our clients with products that have predictable upgrades between versions. We recommend pinning patch versions of our modules using pessimistic constraint operator (~>) to prevent breaking changes during upgrades.

To get new features during the upgrades (without breaking compatibility), use ~> 1.0 and run terraform init -upgrade

For the safest setup, use strict pinning with version = "1.0.0"

v1.0.0 released 1 month, 2 weeks ago

Setup with custom region, versioning disabled and force destroy for the bucket enabled, STANDARD storage class, multi-domain CORS rules configuration, custom error document, list of custom static website domain names:

 hcldata "google_dns_managed_zone" "website" {
  name = "example"
}

module "static_website" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-static-website/google"
  version = "~> 1.0"

  bucket_name           = "static-website"
  dns_zone_name         = data.google_dns_managed_zone.website.name
  region                = "EU"
  storage_class         = "STANDARD"
  error_document        = "404.html"
  versioning_enabled    = false
  force_destroy_enabled = true

  domains = [
    "web.example.com",
    "www.example.com",
    "frontend.example.com",
  ]

  cors_rules = [
    {
      origin          = ["https://example.com", "https://staging.example.com"]
      method          = ["GET", "HEAD", "PUT", "POST", "DELETE"]
      response_header = ["*"]
      max_age_seconds = 3600
    },
    {
      origin          = ["https://api.example.com"]
      method          = ["GET"]
      response_header = ["Content-Type"]
      max_age_seconds = 7200
    },
  ]
}

Minimal setup with mandatory parameters:

 hcldata "google_dns_managed_zone" "website" {
  name = "example"
}

module "static_website" {
  source  = "solutions.corewide.com/google-cloud/tf-gcp-static-website/google"
  version = "~> 1.0"

  bucket_name   = "static-website"
  dns_zone_name = data.google_dns_managed_zone.website.name
}
Variable Description Type Default Required Sensitive
bucket_name Google Cloud Storage bucket name. Must be globally unique string yes no
dns_zone_name DNS zone name for custom domains configuration string yes no
error_document The name of the error document to use when serving the static site string yes no
cors_rules CORS configuration for the bucket list(object) [] no no
cors_rules[*].max_age_seconds The value, in seconds, to return in the Access-Control-Max-Age header used in preflight responses number yes no
cors_rules[*].method The list of HTTP methods on which to include CORS response headers list(string) yes no
cors_rules[*].origin The list of Origins eligible to receive CORS response headers list(string) yes no
cors_rules[*].response_header The list of HTTP headers list(string) yes no
domains Custom domain names for the website Load balancer. If not provided, a root zone record will be configured as a site domain set(string) [] no no
force_destroy_enabled Allows removal of the storage bucket and all contained objects if enabled bool false no no
index_document The name of the index document to use when serving the static site string index.html no no
region The location of the bucket. Possible values: ASIA, EU, US string US no no
storage_class The Storage Class of the bucket. Possible values: STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE string MULTI_REGIONAL no no
versioning_enabled Enable versioning for the bucket bool true no no
Output Description Type Sensitive
bucket All attributes of the created storage bucket resource no
website_urls List of static website URLs computed no
Dependency Version Kind
terraform >= 1.3 CLI
hashicorp/google ~> 6.5 provider

Not sure where to start?
Let's find your perfect match.