This is a Terraform module that I use to configure push-to-deploy (GitOps) Hugo sites. It requires the Google Cloud SDK to be installed locally and an existing Firebase project. The module provisions:
- A Cloud Source Repository to store your Hugo site
- A Cloud Build trigger that will push the site to Firebase Hosting
- GCP project APIs and IAM policies needed to perform the above functions
To get started:
-
Install the Google Cloud SDK, Terraform, and Git.
-
Create a Firebase project with the Blaze Plan.
-
Add the following
firebase.json
file at the top of the Hugo site directory:{ "hosting": { "public": "public", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ] } }
-
Add the following
.firebaserc
file at the top of the Hugo site directory, replacingPROJECTID
with your Firebase project ID.{ "projects": { "default": "PROJECTID" } }
-
Add the following
main.tf
file at the top of the Hugo site directory, replacingPROJECTID
with your Firebase project ID andNAME
with your site's directory name:terraform { required_version = ">=0.13" } provider "google" { project = "PROJECTID" } module "hugo_site" { source = "zombiezen/hugo-site/google" version = "0.3.3" repository_name = "NAME" cloud_build_trigger = true } output "origin_url" { value = module.hugo_site.repository_url }
-
Run
git init && git add . && git commit -m "first"
at the top of the Hugo site directory. This creates your initial commit. -
Run
terraform init && terraform apply
at the top of the Hugo site directory. This will provision the resources for your site. -
Run
git remote add origin $(terraform output origin_url)"
at the top of the Hugo site directory. This configures your local Git repository to push to the newly created Cloud Source Repository. You may need to follow the steps in Cloning Repositories to get your SSH key set up. -
Run
git push -u origin main
to deploy your website. Enjoy!
You may also want to connect a custom domain.