Skip to content

Commit c538ee8

Browse files
authored
feat: Add optional hosted_zone_id input. (WRSAT-238) (#45)
1 parent a060caa commit c538ee8

5 files changed

Lines changed: 15 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ this module offers three ways to define the current image version:
8888
> now to avoid unexpected changes in the future.
8989
9090
| Name | Description | Type | Default | Required |
91-
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ----------- | ----------- |
91+
|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|----------------|-------------|-------------|
9292
| logging_key_id | KMS key to use for log encryption. | `string` | n/a | yes |
9393
| private_subnets | List of private subnet CIDR blocks. | `list` | n/a | yes |
9494
| project | Name of the project. | `string` | n/a | yes |
@@ -115,6 +115,7 @@ this module offers three ways to define the current image version:
115115
| force_new_deployment | Force a new task deployment of the service. | `bool` | `false` | no |
116116
| health_check_grace_period | Time, in seconds, after a container comes into service before health checks must pass. | `number` | `300` | no |
117117
| health_check_path | Application path to use for health checks. | `string` | `"/health"` | no |
118+
| hosted_zone_id | ID of the hosted zone for the domain, leave empty to have this module look it up. | `string` | `null` | no |
118119
| image_tag | Tag of the container image to be deployed. | `string` | `"latest"` | no |
119120
| image_tags_mutable | Whether the container repository allows tags to be mutated. | `bool` | `false` | no |
120121
| ingress_cidrs | List of additional CIDR blocks to allow traffic from. | `list` | `[]` | no |

alb.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ resource "aws_route53_record" "endpoint" {
8989

9090
name = local.fqdn
9191
type = "A"
92-
zone_id = data.aws_route53_zone.domain["this"].zone_id
92+
zone_id = local.hosted_zone_id
9393

9494
alias {
9595
name = module.alb["this"].dns_name
@@ -112,7 +112,7 @@ resource "aws_route53_record" "endpoint_validation" {
112112
records = [each.value.record]
113113
ttl = 60
114114
type = each.value.type
115-
zone_id = data.aws_route53_zone.domain["this"].zone_id
115+
zone_id = local.hosted_zone_id
116116
}
117117

118118
resource "aws_acm_certificate_validation" "endpoint" {

data.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data "aws_partition" "current" {}
55
data "aws_region" "current" {}
66

77
data "aws_route53_zone" "domain" {
8-
for_each = var.create_endpoint ? toset(["this"]) : toset([])
8+
for_each = var.create_endpoint && var.hosted_zone_id == null ? toset(["this"]) : toset([])
99

1010
name = var.domain
1111
}

local.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
locals {
22
fqdn = var.subdomain != "" ? "${var.subdomain}.${var.domain}" : var.domain
3+
hosted_zone_id = (!var.create_endpoint
4+
? null
5+
: (var.hosted_zone_id == null ? data.aws_route53_zone.domain["this"].zone_id : var.hosted_zone_id)
6+
)
37
image_url = var.create_repository ? module.ecr["this"].repository_url : var.image_url
48
prefix = join("-", compact([var.project, var.environment, var.service]))
59
prefix_short = join("-", compact([var.project_short, var.environment, var.service_short]))

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ variable "health_check_path" {
100100
default = "/health"
101101
}
102102

103+
variable "hosted_zone_id" {
104+
type = string
105+
description = "ID of the hosted zone for the domain, leave empty to have this module look it up."
106+
default = null
107+
}
108+
103109
variable "image_tag" {
104110
type = string
105111
description = "Tag for the image to be deployed."

0 commit comments

Comments
 (0)