๐น The Idea: Simplicity + Reproducibility
Instead of manually spinning up a Netlify project, I wanted a fully automated pipeline:
-
Terraform provisions everything:
- Creates a GitHub repo for the static site.
- Configures Netlify hosting.
- Manages infrastructure and state remotely in HCP Terraform.
Push changes to GitHub โ Netlify auto-deploys.
This setup means anyone can clone the Terraform code, set a few variables, and spin up their own live siteโno manual clicks in the UI.
๐น Architecture Overview
- Terraform: Core IaC engine, manages all resources declaratively.
- HCP Terraform (Terraform Cloud): Stores remote Terraform state, ensuring collaboration and state locking.
- GitHub: Hosts both the Terraform code and the deployed static site.
- Netlify: Automatically builds and serves the site from GitHub.
Workflow looks like this:
Terraform Code โ HCP Terraform (remote state) โ GitHub Repo โ Netlify โ Live Site
Live Site: https://curious-pasca-da123e.netlify.app/
๐น Why Itโs Unique
No manual configuration: Terraform does the heavy lifting.
-
Secure Secrets Management:
- Netlify tokens stored as sensitive HCP workspace variables, not in the repo.
Re-runnable: Run
terraform init/plan/apply
with fresh creds, and everything just works.
๐น Step-by-Step Setup
Hereโs the high-level setup (full code is in the repo, not here):
- Prerequisites
- Terraform CLI installed
- Netlify & GitHub accounts
- HCP Terraform org + workspace (CLI-driven)
- HCP Terraform Remote Backend
-
terraform { cloud { organization = "your-org" ... } }
block points Terraform to HCP. - State stored remotely, enabling team collaboration.
- Secrets in HCP Workspace
-
github_token
andnetlify_token
set as sensitive variables in the workspace. - No secrets are ever committed.
- Terraform Code
-
Declares:
- GitHub repo for the site.
- Netlify site linked to that repo.
- Simple HTML page and
netlify.toml
.
- Deploy
terraform init
terraform plan
terraform apply
Terraform provisions the repo, uploads files, links Netlify, and your site is live instantly.
๐น Lessons Learned
- Terraform + Netlify is underrated: You can treat front-end hosting as IaC.
- HCP Terraform simplifies collaboration: State locking and workspace variables make teamwork painless.
- Small IaC projects are great for practice: Even a static site helps you practice production-grade workflows.
๐น Next Steps
- Improve the site design and make it dynamic with environment variables via Terraform.
- Explore integrating GitHub Actions for CI/CD to trigger Terraform runs.
- Scale this pattern to multi-env (staging/prod) setups.
๐ Links
- ๐ Live Site: https://curious-pasca-da123e.netlify.app/
- ๐ Terraform Repo: https://github.com/pojava/hcp-netlify-terraform
๐ Thanks & Tagging
Thanks to HashiCorp User Group (HUG) Ibadan for the challenge!
๐ Tagging: HUG Ibadan LinkedIn Page
๐ก This post shows how easy it is to use Terraform to automate frontend hosting as if it were backend infra.
Would love feedback from the communityโhow would you extend this setup?
Top comments (0)