buildo / terraform-aws-website

Terraform module for creating static websites hosted on S3 and served via CloudFront

Home Page:https://registry.terraform.io/modules/buildo/website/aws/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

website Terraform module

This is a Terraform module designed to automate the deploy of a static website.

This modules creates the following resources:

  • two S3 buckets, one for the content (www.example.com), one for redirecting from the naked domain to www (named example.com)
  • two CloudFront distribution, one per bucket, that also redirect from HTTP to HTTPS
  • two Route53 alias records, one per CloudFront distribution

Usage

Prerequisites

You have to create a SSL certificate for both domains (www and naked) on AWS. This step can't be automated, due to limitations of the AWS API.

Follow this instructions:

  • Access the Certificate Manager on the AWS console
  • Switch to the us-east-1 (N. Virginia) region.
    • 🚨 This is CRUCIAL, as AWS requires certificates for CloudFront to be issued in this region
  • Click on "Request a certificate"
  • Enter as a primary domain name the domain you want with www, for example: www.buildo.io
  • Enter the naked domain as an additional domain name, for example buildo.io

You should be in this situation:

image

NOTE: ⚠️ the order is important, the www domain must come first!

  • Follow the steps for verifying the domain

Using the module

Using the module is as simple as:

provider "aws" {
  region = "eu-west-1" // The region for the S3 buckets and the CloudFront distribution
}

module "website" {
  source = "buildo/website/aws"
  domain = "mysite.com" // no www here

  # optional: enable health check on www.mysite.com
  enable_health_check = true
  health_check_alarm_sns_topics = [
    "<arn of a topic to notify for health check alarms>"
  ]
}

About

Terraform module for creating static websites hosted on S3 and served via CloudFront

https://registry.terraform.io/modules/buildo/website/aws/

License:Apache License 2.0


Languages

Language:HCL 100.0%