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
// | |
// main.swift | |
// DutchGrammar | |
// | |
// Created by Velarde Robles, David on 05/02/2018. | |
// Copyright © 2018 Velarde Robles, David. All rights reserved. | |
// | |
import Foundation |
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
terraform { | |
backend "http" { | |
} | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "3.74.0" | |
} | |
cloudflare = { |
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
resource "aws_acm_certificate" "certificate" { | |
domain_name = "example.com" | |
validation_method = "DNS" | |
} |
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
data "cloudflare_zone" "zone" { | |
name = "example.com" | |
} | |
resource "cloudflare_record" "records" { | |
for_each = { | |
for dvo in aws_acm_certificate.certificate.domain_validation_options : dvo.domain_name => { | |
name = dvo.resource_record_name | |
record = dvo.resource_record_value |
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
resource "aws_acm_certificate_validation" "validation" { | |
certificate_arn = aws_acm_certificate.certificate.arn | |
validation_record_fqdns = [for record in cloudflare_record.records : record.hostname] | |
} |
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
resource "aws_s3_bucket" "website" { | |
bucket = "example.com" | |
acl = "private" | |
force_destroy = true | |
lifecycle { | |
prevent_destroy = false | |
} | |
} |
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
resource "aws_cloudfront_origin_access_identity" "oai" { | |
comment = "Cloudfront Origin Access Identity" | |
} |
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
data "aws_iam_policy_document" "s3_policy" { | |
statement { | |
actions = ["s3:GetObject"] | |
resources = ["${aws_s3_bucket.website.arn}/*"] | |
principals { | |
type = "AWS" | |
identifiers = [aws_cloudfront_origin_access_identity.oai.iam_arn] | |
} | |
} |
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
locals { | |
s3_origin_id = "example.com_origin" | |
} | |
resource "aws_cloudfront_distribution" "s3_distribution" { | |
origin { | |
domain_name = aws_s3_bucket.website.bucket_regional_domain_name | |
origin_id = local.s3_origin_id |
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
resource "cloudflare_record" "records" { | |
zone_id = data.cloudflare_zone.zone.id | |
name = "example.com" | |
value = aws_cloudfront_distribution.s3_distribution.domain_name | |
type = "CNAME" | |
ttl = 1 | |
allow_overwrite = true | |
} |