-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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