-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure CloudFront proxy for Tilegarden #629
Changes from 4 commits
964e02e
568ac4a
6ae1364
ed49193
101efe3
271592b
8dd69b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,7 @@ data "template_file" "pfb_app_https_ecs_task" { | |
batch_analysis_job_definition_name_revision = "${var.batch_analysis_job_definition_name_revision}" | ||
batch_tilemaker_job_queue_name = "${var.batch_tilemaker_job_queue_name}" | ||
batch_tilemaker_job_definition_name_revision = "${var.batch_tilemaker_job_definition_name_revision}" | ||
tilegarden_root = "https://${aws_cloudfront_distribution.tilegarden.domain_name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that we should map the CloudFront distribution domain to a public DNS record that we control via an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Does using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think that's been our rough convention. |
||
} | ||
} | ||
|
||
|
@@ -197,6 +198,7 @@ data "template_file" "pfb_app_async_queue_ecs_task" { | |
batch_analysis_job_definition_name_revision = "${var.batch_analysis_job_definition_name_revision}" | ||
batch_tilemaker_job_queue_name = "${var.batch_tilemaker_job_queue_name}" | ||
batch_tilemaker_job_definition_name_revision = "${var.batch_tilemaker_job_definition_name_revision}" | ||
tilegarden_root = "https://${aws_cloudfront_distribution.tilegarden.domain_name}" | ||
} | ||
} | ||
|
||
|
@@ -235,6 +237,7 @@ data "template_file" "pfb_app_management_ecs_task" { | |
batch_analysis_job_definition_name_revision = "${var.batch_analysis_job_definition_name_revision}" | ||
batch_tilemaker_job_queue_name = "${var.batch_tilemaker_job_queue_name}" | ||
batch_tilemaker_job_definition_name_revision = "${var.batch_tilemaker_job_definition_name_revision}" | ||
tilegarden_root = "https://${aws_cloudfront_distribution.tilegarden.domain_name}" | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
resource "aws_cloudfront_distribution" "tilegarden" { | ||
origin { | ||
custom_origin_config { | ||
http_port = 80 | ||
https_port = 443 | ||
origin_protocol_policy = "https-only" | ||
origin_ssl_protocols = ["TLSv1.2", "TLSv1.1", "TLSv1"] | ||
} | ||
|
||
domain_name = "${var.tilegarden_api_gateway_domain_name}" | ||
origin_path = "/latest" | ||
origin_id = "tilegardenOrigin${title(var.environment)}EastId" | ||
hectcastro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
custom_header { | ||
name = "Accept" | ||
value = "image/png" | ||
} | ||
} | ||
|
||
price_class = "PriceClass_100" | ||
hectcastro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
enabled = true | ||
is_ipv6_enabled = true | ||
comment = "${var.project} (${var.environment})" | ||
|
||
default_cache_behavior { | ||
allowed_methods = ["GET", "HEAD", "OPTIONS"] | ||
cached_methods = ["GET", "HEAD"] | ||
target_origin_id = "tilegardenOrigin${title(var.environment)}EastId" | ||
|
||
forwarded_values { | ||
query_string = true | ||
|
||
cookies { | ||
forward = "none" | ||
} | ||
} | ||
|
||
viewer_protocol_policy = "redirect-to-https" | ||
min_ttl = 0 | ||
default_ttl = "300" # Five minutes | ||
max_ttl = "86400" # One day | ||
} | ||
|
||
restrictions { | ||
"geo_restriction" { | ||
restriction_type = "none" | ||
} | ||
} | ||
|
||
viewer_certificate { | ||
cloudfront_default_certificate = true | ||
minimum_protocol_version = "TLSv1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifying |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,3 +157,5 @@ variable "aws_cloudwatch_logs_policy_arn" { | |
variable "pfb_app_alb_ingress_cidr_block" { | ||
type = "list" | ||
} | ||
|
||
variable "tilegarden_api_gateway_domain_name" {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Claudia creates the API Gateway resource for Tilegarden separately from Terraform, we need to specify this value as an input variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this interact with "it's best to finish these steps before you deploy a new stack with Terraform"? Seems like there's a bit of circularity here that would require bootstrapping, i.e. the process for creating a new stack would need to be "batch, terraform, tilegarden, terraform"? (Or would it be "batch, tilegarden, terraform, tilegarden"? Or is there actually a linear way to do it?)
Tilegarden isn't good for much without access to a database, at least not on this project. I might rephrase this to "For example, to give Tilegarden access to the database, set..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent point. It's possible you could get away with doing it linearly (
Batch -> Tilegarden -> Terraform
) if you used an existing VPC, but we're not doing that here, so realistically this is implying that you'll have to doBatch -> Terraform -> Tilegarden -> Terraform
.I think we could make the setup easier if we were at least explicit about this workflow, and gave the user some guidance in doing it. My expectation is that if you were to set the
tilegarden_api_gateway_domain_name
variable to some bogus value on the first Terraform run, the resources will build properly, but the CDN won't return tiles properly; then if you adjust the variable again after setting up Tilegarden things should wire up correctly on the secondterraform apply
.I don't love this workflow, but it's the best I can think of given the constraints we're under, where the Lambda function and the CDN are interdependent but each has to be configured and managed from a separate source of truth. If you can think of a way around it, let me know!