Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a Terraform module that sets up a static website:


  1. Install Terraform
  2. Create a file with a .tf extension (say, in a folder of your choosing. Paste the configuration below into it.
  3. Run terraform init and then terraform apply.

Terraform configuration


module "static-site" {
  source                    = "git::"
  project_name              = "awesome-website"

  // Your root domain
  root_domain_name          = ""
  // The "www" subdomain for your website
  www_domain_name           = ""
  // The name of your domain on Cloudflare. Typically the same as your root domain.
  cloudflare_zone           = ""

  // Your github username
  github_organization       = "username"
  // Name of the repo containing your hugo source
  github_source_repo_name   = ""
  // The branch to build of the above repo
  github_source_repo_branch = "master"
  github_oauth_secret       = "abcdefgh5678"
  github_webhook_secret     = "ijklmnop1234"

provider "aws" {
  version    = "~> 2.10"
  region     = "us-east-1"
  // Your AWS access key
  access_key = "aws1234"
  // Your AWS secret key
  secret_key = "aws5678"

provider "github" {
  version      = "~> 2.0"
  // Your Github username
  organization = "username"
  token        = "abcdefgh5678"

provider "cloudflare" {
  version = "~> 1.14"
  // Your Cloudflare email
  email   = ""
  token   = "qrstuvwx9012"


In addition to the above configuration, you can add the following variables to the module section for additional customization:

module "static-site" {

  // The docker image used for transforming your hugo content to static assets.
  // You can use my image or specify your own on Docker Hub.
  codebuild_docker_image    = "ameypar/hugo-alpine:latest"

  // Whether you want to set up MX records in Cloudflare for Google Apps email.
  use_google_apps_email     = true

  google_txt_verification   = "google1234"

Build spec

This should go into buildspec.yml in the root of your hugo source repository. This file tells the AWS CodeBuild step in the pipeline how to build your repository using hugo and what files should be uploaded to AWS S3.

version: 0.2

      - hugo -v

  type: zip
    - '**/*'
  base-directory: 'public'
  discard-paths: no

Best practices

  1. Although the template above is written with ease of use in mind, it's recommended that you don't put your secrets into the root file if you intend to check it into version control. Instead, declare variables in the file and create a terraform.tfvars file with the actual secrets. Guide here:
  2. For AWS, instead of using your root user, I recommend creating an IAM user with Administrator access specifically for use with Terraform. Once you're done applying the Terraform plan, you can delete the IAM user if desired.
  3. Instead of storing your terraform state locally, pick one of the existing terraform backends. If you choose the S3 backend and create a bucket named my-terraform-state, you would put the following block into your file and then run terraform init.
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "state"
    region = "us-east-1"
You can’t perform that action at this time.