Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Setup ACM. #3

Merged
merged 1 commit into from
Feb 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Terraform configuration

terraform {
required_version = ">= 0.10.0"
required_version = "~> 0.10"
backend "s3" {
bucket = "mazgi-sakemeshi-aws-terraform"
key = "global/tfstate"
Expand All @@ -13,6 +13,7 @@ terraform {
}

provider "aws" {
version = "~> 1.9.0"
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1" # N. Virginia
Expand Down Expand Up @@ -45,6 +46,43 @@ resource "aws_route53_record" "sakemeshi-love" {
}
}

# --------------------------------
# ACM: sakemeshi.love, *.sakemeshi.love
# Need AWS provider v1.9 or more.
# see: https://github.com/terraform-providers/terraform-provider-aws/pull/2813

resource "aws_acm_certificate" "sakemeshi-love" {
domain_name = "sakemeshi.love"
subject_alternative_names = ["*.sakemeshi.love"]
validation_method = "DNS"
}

# for 'sakemeshi.love'
resource "aws_route53_record" "certificate-validation-sakemeshi-love" {
name = "${aws_acm_certificate.sakemeshi-love.domain_validation_options.0.resource_record_name}"
type = "${aws_acm_certificate.sakemeshi-love.domain_validation_options.0.resource_record_type}"
zone_id = "${aws_route53_zone.sakemeshi-love.zone_id}"
records = ["${aws_acm_certificate.sakemeshi-love.domain_validation_options.0.resource_record_value}"]
ttl = 60
}

## for '*.sakemeshi.love'
#resource "aws_route53_record" "certificate-validation-_-sakemeshi-love" {
# name = "${aws_acm_certificate.sakemeshi-love.domain_validation_options.1.resource_record_name}"
# type = "${aws_acm_certificate.sakemeshi-love.domain_validation_options.1.resource_record_type}"
# zone_id = "${aws_route53_zone.sakemeshi-love.zone_id}"
# records = ["${aws_acm_certificate.sakemeshi-love.domain_validation_options.1.resource_record_value}"]
# ttl = 60
#}

resource "aws_acm_certificate_validation" "sakemeshi-love" {
certificate_arn = "${aws_acm_certificate.sakemeshi-love.arn}"
validation_record_fqdns = [
"${aws_route53_record.certificate-validation-sakemeshi-love.fqdn}",
"${aws_route53_record.certificate-validation-sakemeshi-love.fqdn}"
]
}

# --------------------------------
# S3 buckets: sakemeshi.love

Expand Down Expand Up @@ -138,6 +176,7 @@ resource "aws_cloudfront_distribution" "sakemeshi-love-website-prod-distribution
}

viewer_certificate {
cloudfront_default_certificate = true
acm_certificate_arn = "${aws_acm_certificate.sakemeshi-love.arn}"
ssl_support_method = "sni-only"
}
}