Skip to content

Instantly share code, notes, and snippets.

@lgs
Forked from cliffano/s3staticsite_route53a.tf
Created August 25, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgs/dcc5a23c04c1698eecac4716b8d7fc51 to your computer and use it in GitHub Desktop.
Save lgs/dcc5a23c04c1698eecac4716b8d7fc51 to your computer and use it in GitHub Desktop.
Terraform configuration for setting up S3 static site bucket with a Route53 A record.
variable "bucket_site" {}
variable "region" {}
variable "route53_domain_name" {}
variable "route53_domain_zoneid" {}
variable "route53_domain_alias_name" {}
variable "route53_domain_alias_zoneid" {}
provider "aws" {
region = "${var.region}"
}
resource "aws_s3_bucket" "site" {
bucket = "${var.bucket_site}"
acl = "public-read"
policy = <<EOF
{
"Id": "bucket_policy_site",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "bucket_policy_site_main",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::${var.bucket_site}/*",
"Principal": "*"
}
]
}
EOF
website {
index_document = "index.html"
error_document = "404.html"
}
tags {
}
force_destroy = true
}
resource "aws_route53_record" "domain" {
name = "${var.route53_domain_name}"
zone_id = "${var.route53_domain_zoneid}"
type = "A"
alias {
name = "${var.route53_domain_alias_name}"
zone_id = "${var.route53_domain_alias_zoneid}"
evaluate_target_health = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment