Piers Karsenbarg

Setting Up Cloudfront

Posted at — Apr 27, 2019

This one’s going to take a while. It takes quite a long time to set up a CloudFront distribution, just because it takes a while for it to be deployed globally.

resource "aws_acm_certificate" "default" {
  domain_name       = "${aws_route53_zone.primary.name}"
  validation_method = "DNS"
  subject_alternative_names = ["*.${var.root_domain_name}"]
}

resource "aws_route53_record" "validation" {
  name    = "${aws_acm_certificate.default.domain_validation_options.0.resource_record_name}"
  type    = "${aws_acm_certificate.default.domain_validation_options.0.resource_record_type}"
  zone_id = "${aws_route53_zone.primary.zone_id}"
  records = ["${aws_acm_certificate.default.domain_validation_options.0.resource_record_value}"]
  ttl     = "3600"
}

resource "aws_acm_certificate_validation" "default" {
  certificate_arn = "${aws_acm_certificate.default.arn}"

  validation_record_fqdns = [
    "${aws_route53_record.validation.*.fqdn}",
  ]
}