
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.
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
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
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"
All notable changes to this project are documented here.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
First stable version
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 |