Hosting a Static Website with Hugo and Terraform

December 22, 2021 ยท 2 minutes

In 2018, I created an article on how to create a static website on AWS.

In 2019, I created an article on how to create a static website on AWS using CloudFormation.

Now, in the final days of 2021, the final chapter has been written: how to create a static website on AWS using Terraform.

Hugo

Hugo is a static site generator. The purpose of a static website generator is to render content into HTML files before the request for the content is made - increasing performance and reducing load time. To achieve this, Hugo uses a source directory of files and templates as input to create a complete website.

To get started with Hugo, refer to their Getting Started documentation.

Terraform

Overview

Hosting a static website on AWS requires the following resources:

Prerequisites

First, you must purchase a domain name through Amazon. This can be done through the AWS Management Console.

Creating the Terraform module

This article uses a public Terraform module maintained by Infrable.io:

To use this module the following files are required:

An example Terraform module can be found here.

Deploying the Terraform module

Initialize the Terraform module:

terraform init

To see the speculative execution plan, run:

terraform plan

If you are satisfied with the output, create the infrastructure:

terraform apply

Publishing content

This can be accomplished with a simple script. See publish in nickolashkraus/static-website-com.

The exact steps provided in this article were used to deploy static-website.com!

Conclusion

You might haved noticed that the process for creating a static website on AWS using Terraform is far less cumbersome. This is due to the ease of creating and sharing Terraform modules.