-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove r53 and s3 web files from terraform (now in Amplify)
- Loading branch information
Showing
5 changed files
with
1 addition
and
266 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
data "aws_route53_zone" "main" { | ||
name = var.www_domain_name | ||
} | ||
|
||
resource "aws_route53_record" "wkspc_www-a" { | ||
zone_id = data.aws_route53_zone.main.zone_id | ||
name = "${local.site_name}.${var.www_domain_name}" | ||
type = "A" | ||
|
||
alias { | ||
name = aws_cloudfront_distribution.wkspc_www_s3_distribution.domain_name | ||
zone_id = aws_cloudfront_distribution.wkspc_www_s3_distribution.hosted_zone_id | ||
evaluate_target_health = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +0,0 @@ | ||
locals { | ||
# a local to determine if our workspace is "prod" | ||
is_prod = terraform.workspace == "prod" | ||
|
||
# set the_files to and empty map in the non-prod workspace | ||
# and to a map of files in the prod workspace | ||
files = local.is_prod ? { | ||
"index.html" = "text/html" | ||
"script.js" = "application/javascript" | ||
"custom.js" = "application/javascript" | ||
"styles.css" = "text/css" | ||
"images/storyteller.png" = "image/png" | ||
"images/download.png" = "image/png" | ||
"images/background.png" = "image/png" | ||
"images/infobutton.png" = "image/png" | ||
"dropzone.css" = "text/css" | ||
|
||
# favicon resources | ||
"favicon/android-chrome-192x192.png" = "image/png" | ||
"favicon/android-chrome-512x512.png" = "image/png" | ||
"favicon/apple-touch-icon.png" = "image/png" | ||
"favicon/favicon-16x16.png" = "image/png" | ||
"favicon/favicon-32x32.png" = "image/png" | ||
"favicon/favicon.ico" = "image/x-icon" | ||
"favicon/site.webmanifest" = "application/manifest+json" | ||
} : {} | ||
} | ||
|
||
resource "aws_s3_object" "wkspc_botc_www_files" { | ||
depends_on = [ | ||
aws_s3_bucket_policy.wkspc_www_bucket_policy, | ||
] | ||
for_each = local.files | ||
|
||
bucket = aws_s3_bucket.wkspc_www_bucket.id | ||
key = each.key | ||
source = "../www/${each.key}" | ||
content_type = each.value | ||
acl = "public-read" | ||
etag = filemd5("../www/${each.key}") | ||
|
||
tags = { | ||
"BelongsToDist" = aws_cloudfront_distribution.wkspc_www_s3_distribution.id | ||
} | ||
} | ||
|
||
# we need to create an s3 file/object (const.js) that contains the API Gateway | ||
# URL so that the web page can call the API Gateway | ||
resource "aws_s3_object" "botc_www_const_js" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? length(local.files) : 0 | ||
|
||
depends_on = [ | ||
aws_s3_bucket_policy.wkspc_www_bucket_policy, | ||
aws_api_gateway_stage.api_stage, | ||
] | ||
bucket = aws_s3_bucket.wkspc_www_bucket.id | ||
key = "const.js" | ||
content = <<EOF | ||
/* generated by terraform */ | ||
const API_GATEWAY_URL = "${aws_api_gateway_stage.api_stage.invoke_url}"; | ||
EOF | ||
content_type = "application/javascript" | ||
acl = "public-read" | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,183 +0,0 @@ | ||
# a bucket for the $workspace files to be stored in | ||
|
||
resource "aws_s3_bucket" "wkspc_www_bucket" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? length(local.files) : 0 | ||
|
||
bucket = "${local.site_name}.${var.www_bucket_name}" | ||
} | ||
|
||
resource "aws_s3_bucket_ownership_controls" "wkspc_www_bucket_ownership_controls" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? length(local.files) : 0 | ||
|
||
bucket = aws_s3_bucket.wkspc_www_bucket[count.index].id | ||
|
||
rule { | ||
object_ownership = "BucketOwnerPreferred" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "wkspc_www_bucket_acl" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
depends_on = [ | ||
aws_s3_bucket_ownership_controls.wkspc_www_bucket_ownership_controls, | ||
] | ||
bucket = aws_s3_bucket.wkspc_www_bucket[count.index].id | ||
acl = "public-read" | ||
} | ||
|
||
resource "aws_s3_bucket_policy" "wkspc_www_bucket_policy" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
depends_on = [ | ||
aws_s3_bucket_acl.wkspc_www_bucket_acl, | ||
] | ||
bucket = aws_s3_bucket.wkspc_www_bucket.id | ||
policy = templatefile("templates/s3-policy.json", { bucket = "${local.site_name}.${var.www_bucket_name}" }) | ||
} | ||
|
||
resource "aws_s3_bucket_cors_configuration" "wkspc_www_bucket_cors" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
bucket = aws_s3_bucket.wkspc_www_bucket[count.index].id | ||
|
||
cors_rule { | ||
allowed_headers = ["Authorization", "Content-Length"] | ||
allowed_methods = ["GET", "POST"] | ||
allowed_origins = ["https://${local.site_name}.${var.www_domain_name}"] | ||
max_age_seconds = 3000 | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_website_configuration" "wkspc_www_bucket_website" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
bucket = aws_s3_bucket.wkspc_www_bucket[count.index].id | ||
|
||
index_document { | ||
suffix = "index.html" | ||
} | ||
error_document { | ||
key = "404.html" | ||
} | ||
} | ||
|
||
|
||
|
||
resource "aws_cloudfront_distribution" "wkspc_www_s3_distribution" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
origin { | ||
domain_name = aws_s3_bucket.wkspc_www_bucket.bucket_regional_domain_name | ||
origin_id = "S3-${local.site_name}.${var.www_bucket_name}" | ||
|
||
custom_origin_config { | ||
http_port = 80 | ||
https_port = 443 | ||
origin_protocol_policy = "http-only" | ||
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"] | ||
} | ||
} | ||
|
||
enabled = true | ||
is_ipv6_enabled = true | ||
default_root_object = "index.html" | ||
|
||
aliases = ["${local.site_name}.${var.www_domain_name}"] | ||
|
||
custom_error_response { | ||
error_caching_min_ttl = 0 | ||
error_code = 404 | ||
response_code = 200 | ||
response_page_path = "/404.html" | ||
} | ||
|
||
default_cache_behavior { | ||
allowed_methods = ["GET", "HEAD"] | ||
cached_methods = ["GET", "HEAD"] | ||
target_origin_id = "S3-${local.site_name}.${var.www_bucket_name}" | ||
|
||
forwarded_values { | ||
query_string = false | ||
|
||
cookies { | ||
forward = "none" | ||
} | ||
} | ||
|
||
viewer_protocol_policy = "redirect-to-https" | ||
min_ttl = 31536000 | ||
default_ttl = 31536000 | ||
max_ttl = 31536000 | ||
compress = true | ||
} | ||
|
||
restrictions { | ||
geo_restriction { | ||
restriction_type = "none" | ||
} | ||
} | ||
|
||
viewer_certificate { | ||
#acm_certificate_arn = aws_acm_certificate_validation.cert_validation.certificate_arn | ||
acm_certificate_arn = data.aws_acm_certificate.star_domain.arn | ||
ssl_support_method = "sni-only" | ||
minimum_protocol_version = "TLSv1.1_2016" | ||
} | ||
} | ||
|
||
# we don't want to have to manually invalidate the cache every time we update the site | ||
resource "aws_s3_bucket_notification" "bucket_notification" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? length(local.files) : 0 | ||
|
||
bucket = aws_s3_bucket.wkspc_www_bucket.id | ||
|
||
lambda_function { | ||
lambda_function_arn = "arn:aws:lambda:eu-west-2:436158765452:function:invalidate-cache" | ||
events = ["s3:ObjectCreated:*"] | ||
filter_prefix = "" | ||
filter_suffix = "" | ||
} | ||
} | ||
|
||
# Add permission for S3 bucket to trigger Lambda function | ||
resource "aws_lambda_permission" "allow_bucket" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? length(local.files) : 0 | ||
|
||
statement_id = "AllowS3BucketToTriggerLambda-${local.site_name}-${terraform.workspace}" | ||
action = "lambda:InvokeFunction" | ||
function_name = data.aws_lambda_function.invalidate_cache.function_name | ||
principal = "s3.amazonaws.com" | ||
source_arn = aws_s3_bucket.wkspc_www_bucket.arn | ||
} | ||
|
||
# Add permission for S3 bucket to trigger Lambda function | ||
resource "aws_lambda_permission" "apigw_invoke_function" { | ||
|
||
# only create objects if we are in the prod workspace | ||
count = local.is_prod ? 1 : 0 | ||
|
||
statement_id = "AllowApiGatewayToInvokeFunction-${local.site_name}-${terraform.workspace}" | ||
action = "lambda:InvokeFunction" | ||
function_name = data.aws_lambda_function.api_render_pdf.function_name | ||
principal = "apigateway.amazonaws.com" | ||
source_arn = "${data.aws_api_gateway_rest_api.json2pdf_api.execution_arn}/*/*" | ||
} | ||