From f3e5844251c1c37b8c7b59cf29c6034c18abf7cf Mon Sep 17 00:00:00 2001 From: Amey Parulekar Date: Sun, 19 May 2019 20:18:55 -0700 Subject: [PATCH] Add terraform configuration. --- .gitignore | 2 + cloudflare.tf | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ codebuild.tf | 22 +++++++++ pipeline.tf | 65 ++++++++++++++++++++++++++ policy.tf | 69 ++++++++++++++++++++++++++++ providers.tf | 16 +++++++ s3.tf | 64 ++++++++++++++++++++++++++ variables.tf | 27 +++++++++++ webhooks.tf | 29 ++++++++++++ 9 files changed, 419 insertions(+) create mode 100644 .gitignore create mode 100644 cloudflare.tf create mode 100644 codebuild.tf create mode 100644 pipeline.tf create mode 100644 policy.tf create mode 100644 providers.tf create mode 100644 s3.tf create mode 100644 variables.tf create mode 100644 webhooks.tf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59d0a88 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.tfvars +.terraform \ No newline at end of file diff --git a/cloudflare.tf b/cloudflare.tf new file mode 100644 index 0000000..bfafadc --- /dev/null +++ b/cloudflare.tf @@ -0,0 +1,125 @@ +// Zone overrides + +resource "cloudflare_zone_settings_override" "root" { + name = "${var.root_domain_name}" + settings { + always_online = "on" + always_use_https = "on" + automatic_https_rewrites = "on" + brotli = "on" + http2 = "on" + ip_geolocation = "on" + ipv6 = "on" + opportunistic_encryption = "on" + opportunistic_onion = "on" + ssl = "flexible" + tls_1_3 = "on" + websockets = "on" + } +} + +// DNS records + +resource "cloudflare_record" "cname-mail" { + domain = "${var.root_domain_name}" + name = "mail.${var.root_domain_name}" + value = "ghs.googlehosted.com" + proxied = true + type = "CNAME" +} + +resource "cloudflare_record" "cname-root" { + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "${var.root_domain_name}.s3-website-${var.region}.amazonaws.com" + proxied = true + type = "CNAME" +} + +resource "cloudflare_record" "cname-www" { + domain = "${var.root_domain_name}" + name = "${var.www_domain_name}" + value = "${var.www_domain_name}.s3-website-${var.region}.amazonaws.com" + proxied = true + type = "CNAME" +} + +resource "cloudflare_record" "txt-google" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "google-site-verification=${var.google_txt_verification}" + proxied = false + priority = 10 + type = "TXT" +} + +resource "cloudflare_record" "mx-aspmx-l" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "aspmx.l.google.com" + proxied = false + priority = 10 + type = "MX" +} + +resource "cloudflare_record" "mx-alt1" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "alt1.aspmx.l.google.com" + proxied = false + priority = 20 + type = "MX" +} + +resource "cloudflare_record" "mx-alt2" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "alt2.aspmx.l.google.com" + proxied = false + priority = 20 + type = "MX" +} + +resource "cloudflare_record" "mx-aspmx2" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "aspmx2.googlemail.com" + proxied = false + priority = 30 + type = "MX" +} + +resource "cloudflare_record" "mx-aspmx3" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "aspmx3.googlemail.com" + proxied = false + priority = 30 + type = "MX" +} + +resource "cloudflare_record" "mx-aspmx4" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "aspmx4.googlemail.com" + proxied = false + priority = 30 + type = "MX" +} + +resource "cloudflare_record" "mx-aspmx5" { + count = "${var.use_google_apps_email}" + domain = "${var.root_domain_name}" + name = "${var.root_domain_name}" + value = "aspmx5.googlemail.com" + proxied = false + priority = 30 + type = "MX" +} diff --git a/codebuild.tf b/codebuild.tf new file mode 100644 index 0000000..f4f741e --- /dev/null +++ b/codebuild.tf @@ -0,0 +1,22 @@ +resource "aws_codebuild_project" "hugo" { + name = "${var.project_name}_codebuild" + description = "CodeBuild project to build a hugo site." + build_timeout = "5" + service_role = "${aws_iam_role.hugo.arn}" + + artifacts { + type = "CODEPIPELINE" + } + + source { + type = "CODEPIPELINE" + buildspec = "buildspec.yml" + } + + environment { + compute_type = "BUILD_GENERAL1_SMALL" + image = "${var.codebuild_docker_image}" + image_pull_credentials_type = "SERVICE_ROLE" + type = "LINUX_CONTAINER" + } +} diff --git a/pipeline.tf b/pipeline.tf new file mode 100644 index 0000000..ca53a67 --- /dev/null +++ b/pipeline.tf @@ -0,0 +1,65 @@ +resource "aws_codepipeline" "hugo" { + name = "${var.project_name}_codepipeline" + role_arn = "${aws_iam_role.hugo.arn}" + + artifact_store { + location = "${aws_s3_bucket.hugo.bucket}" + type = "S3" + } + + stage { + name = "Source" + + action { + name = "Source" + category = "Source" + owner = "ThirdParty" + provider = "GitHub" + version = "1" + output_artifacts = ["source_output"] + + configuration { + Owner = "${var.github_organization}" + Repo = "${var.github_source_repo_name}" + Branch = "${var.github_source_repo_branch}" + OAuthToken = "${var.github_oauth_secret}" + } + } + } + + stage { + name = "Build" + + action { + name = "Build" + category = "Build" + owner = "AWS" + provider = "CodeBuild" + input_artifacts = ["source_output"] + output_artifacts = ["build_output"] + version = "1" + + configuration { + ProjectName = "${aws_codebuild_project.hugo.name}" + } + } + } + + stage { + name = "Deploy" + + action { + name = "Deploy" + category = "Deploy" + owner = "AWS" + provider = "S3" + input_artifacts = ["build_output"] + version = "1" + + configuration { + BucketName = "${aws_s3_bucket.hugo_root.bucket}" + Extract = "true" + } + } + } +} diff --git a/policy.tf b/policy.tf new file mode 100644 index 0000000..9bba895 --- /dev/null +++ b/policy.tf @@ -0,0 +1,69 @@ +resource "aws_iam_role" "hugo" { + name = "${var.project_name}_role" + + assume_role_policy = <