-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DNS records for environment (#23)
Forward to API Gateway and use the DNS endpoint for tests. I've weighted 100% to eu-west-1 for now because multi-region signatures aren't well supported yet (i.e. you need to know which region you're signing for) and all our traffic originates in eu-west-1, but we should really take a proper look at this for future reliability. #minor
- Loading branch information
Showing
13 changed files
with
201 additions
and
11 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
locals { | ||
domain_name = var.is_production ? data.aws_route53_zone.service.name : "*.${data.aws_route53_zone.service.name}" | ||
} | ||
|
||
data "aws_route53_zone" "service" { | ||
name = "lpa-store.api.opg.service.justice.gov.uk" | ||
provider = aws.management | ||
} | ||
|
||
resource "aws_acm_certificate" "environment" { | ||
domain_name = local.domain_name | ||
validation_method = "DNS" | ||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
|
||
provider = aws.region | ||
} | ||
|
||
resource "aws_route53_record" "validation" { | ||
name = sort(aws_acm_certificate.environment.domain_validation_options[*].resource_record_name)[0] | ||
type = sort(aws_acm_certificate.environment.domain_validation_options[*].resource_record_type)[0] | ||
zone_id = data.aws_route53_zone.service.id | ||
records = [sort(aws_acm_certificate.environment.domain_validation_options[*].resource_record_value)[0]] | ||
ttl = 60 | ||
allow_overwrite = true | ||
provider = aws.management | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
terraform { | ||
required_version = ">= 1.4.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
configuration_aliases = [ | ||
aws.region, | ||
aws.management, | ||
] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
variable "is_production" { | ||
description = "Whether this is a production environment" | ||
type = bool | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module "eu_west_1" { | ||
source = "./region" | ||
|
||
is_production = local.account.is_production | ||
|
||
providers = { | ||
aws.region = aws.eu_west_1 | ||
aws.management = aws.management_eu_west_1 | ||
} | ||
} | ||
|
||
module "eu_west_2" { | ||
source = "./region" | ||
|
||
is_production = local.account.is_production | ||
|
||
providers = { | ||
aws.region = aws.eu_west_2 | ||
aws.management = aws.management_eu_west_2 | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
locals { | ||
a_record = terraform.workspace == "production" ? data.aws_route53_zone.service.name : var.environment_name | ||
domain_name = terraform.workspace == "production" ? data.aws_route53_zone.service.name : "${local.a_record}.${data.aws_route53_zone.service.name}" | ||
} | ||
|
||
data "aws_route53_zone" "service" { | ||
name = "lpa-store.api.opg.service.justice.gov.uk" | ||
provider = aws.management | ||
} | ||
|
||
data "aws_acm_certificate" "root" { | ||
domain = terraform.workspace == "production" ? data.aws_route53_zone.service.name : "*.${data.aws_route53_zone.service.name}" | ||
provider = aws.region | ||
} | ||
|
||
resource "aws_route53_record" "environment_record" { | ||
name = local.a_record | ||
type = "A" | ||
zone_id = data.aws_route53_zone.service.id | ||
set_identifier = data.aws_region.current.name | ||
|
||
weighted_routing_policy { | ||
weight = var.dns_weighting | ||
} | ||
|
||
alias { | ||
evaluate_target_health = true | ||
name = aws_api_gateway_domain_name.lpa_store.regional_domain_name | ||
zone_id = aws_api_gateway_domain_name.lpa_store.regional_zone_id | ||
} | ||
|
||
provider = aws.management | ||
} | ||
|
||
resource "aws_api_gateway_domain_name" "lpa_store" { | ||
domain_name = local.domain_name | ||
regional_certificate_arn = data.aws_acm_certificate.root.arn | ||
security_policy = "TLS_1_2" | ||
|
||
endpoint_configuration { | ||
types = ["REGIONAL"] | ||
} | ||
|
||
provider = aws.region | ||
} |
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,3 +1,3 @@ | ||
output "base_url" { | ||
value = aws_api_gateway_stage.current.invoke_url | ||
value = "https://${local.domain_name}" | ||
} |
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