Provides resources to deploy infrastructure for a static website on Google Cloud using Terraform.
gcloud projects create gcp-terraform-demo
gcloud config set project gcp-terraform-demo
gcloud services enable storage.googleapis.com
gcloud storage buckets create gs://gcp-terraform-demo-tfstate --location=EU
git clone https://github.com/localdotcom/gcp-terraform-demo.git
The code is modular, allowing users to create any number of static sites by simply adding a new entry under lb.domains
in tfvars.json
:
}
"lb": {
"domains": [
"gcp-terraform-demo-one.site",
"gcp-terraform-demo-two.site",
...
"gcp-terraform-demo-five.site"
]
}
}
NOTE: Execute all commands under the project's directory using script called terraform
.
./terraform plan gcs --project gcp-terraform-demo --region europe-west1
./terraform apply gcs --project gcp-terraform-demo --region europe-west1
./terraform plan iam --project gcp-terraform-demo --region europe-west1
./terraform apply iam --project gcp-terraform-demo --region europe-west1
./terraform plan lb --project gcp-terraform-demo --region europe-west1
./terraform apply lb --project gcp-terraform-demo --region europe-west1
-
- Go to Google Cloud Console > Cloud DNS > Zones.
- Select your DNS zone.
- Note the four nameservers listed under NS records (they'll look something like
ns-cloud-a1.googledomains.com
,ns-cloud-a2.googledomains.com
, etc.). - Log into your account at your domain registrar (e.g., GoDaddy, Namecheap, or any other registrar).
- Go to the DNS settings or Nameserver settings for your domain
- Find the section where you can update your nameservers (this is often labeled "Custom Nameservers" or similar).
- Enter the four GCP nameservers from your DNS zone. Be sure to add all of them.
- Save or apply the changes.