Skip to content

Latest commit

 

History

History

aws_static_site

Infrastructure

The infrastructure is created in AWS.

To create it we use Terraform which allows us to automate resource creation by defining them programmatically.

For more information on how Terraform works visit the Getting Started guide and the documentation. For more specific information about how it interacts with AWS check out the AWS Provider Documentation.

Requirements

Overview

Infrastructure overview

We use various AWS services:

  • Amazon S3 for asset storage
  • Cloudfront as an asset cache to optimise asset distribution
  • Route53 to manage our DNS and link the domain to our Cloudfront distribution

Folder structure

infrastructure/
├── resources/
│   ├── buckets.tf
│   ├── cloudfront.tf
│   ├── domain.tf
│   └── variables.tf
├── main.tf
├── outputs.tf
├── README.md
├── terraform.tfvars
└── variables.tf
  • variables.tf: This file defines the variables required to create the infrastructure

  • main.tf: This is where everything starts, this file defines the minimum Terraform version, the providers and the modules we have

  • terraform.tfvars: The value for the variables defined above, DO NOT COMMIT THIS TO THE REPOSITORY

  • outputs.tf: After running terraform apply this will print the configured outputs to the console

  • resources/: This folder is a Terraform module, it holds all the resources needed for a static site

    • variables.tf: The variables required by the module
    • buckets.tf: Create the S3 buckets with the policies already configured.
    • cloudfront.tf: Creates the Cloudfront that uses the S3 as the source
    • domain.tf: Creates the domain record in Route53 and point it to the Cloudfront

Usage

Rename the terraform.tfvars.example file to be terraform.tfvars:

mv terraform.tfvars.example terraform.tfvars

Modify the file to use your specific credentials:

aws_access_key = "your access key"
aws_secret_key = "your secret key"

Initialize terraform

terraform init

If everything is correct the following command should output an execution plan

terraform plan

If everything looks good to go you can apply the changes with

terraform apply