Skip to content

Commit 4e6084a

Browse files
committed
fix(vpc): support only one route53 resolver profile association
1 parent d0a0655 commit 4e6084a

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

modules/vpc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This module creates following resources.
8080
| <a name="input_network_address_usage_metrics_enabled"></a> [network\_address\_usage\_metrics\_enabled](#input\_network\_address\_usage\_metrics\_enabled) | (Optional) Whether NAU (Network Address Usage) metrics are enabled for the VPC. Defaults to `false`. | `bool` | `false` | no |
8181
| <a name="input_region"></a> [region](#input\_region) | (Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region. | `string` | `null` | no |
8282
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | (Optional) A configurations of Resource Group for this module. `resource_group` as defined below.<br/> (Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.<br/> (Optional) `name` - The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. If not provided, a name will be generated using the module name and instance name.<br/> (Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`. | <pre>object({<br/> enabled = optional(bool, true)<br/> name = optional(string, "")<br/> description = optional(string, "Managed by Terraform.")<br/> })</pre> | `{}` | no |
83-
| <a name="input_route53_resolver"></a> [route53\_resolver](#input\_route53\_resolver) | (Optional) A configuration for Route53 Resolver in the VPC. `route53_resolver` as defined below.<br/> (Optional) `enabled` - Whether DNS resolution through the Route53 Resolver (the Amazon DNS server) is supported for the VPC. Defaults to `true`.<br/> (Optional) `private_hosted_zones` - A set of private Hosted Zone IDs to associate with the VPC.<br/> (Optional) `profile_associations` - A list of configurations for Route53 Profile associations with the VPC. Each block of `profile_associations` as defined below.<br/> (Required) `name` - The name of the resource association with the Route53 profile.<br/> (Required) `profile` - The ID of the Route53 profile to associate with.<br/> (Optional) `tags` - A map of tags to add to the Route53 Profile association resource.<br/> (Optional) `autodefined_reverse_dns_resolution_enabled` - Whether to enable the autodefined reverse DNS resolution for the VPC. Defaults to `true`.<br/> (Optional) `dnssec_validation` - The configuration for DNSSEC validation in the VPC. `dnssec_validation` as defined below.<br/> (Optional) `enabled` - Whether to use DNSSEC validation to check DNSSEC cryptographic signatures to ensure that a DNS response was not tampered with. Defaults to `false`. | <pre>object({<br/> enabled = optional(bool, true)<br/> private_hosted_zones = optional(set(string), [])<br/> profile_associations = optional(list(object({<br/> name = string<br/> profile = string<br/> tags = optional(map(string), {})<br/> })), [])<br/> autodefined_reverse_dns_resolution_enabled = optional(bool, true)<br/> dnssec_validation = optional(object({<br/> enabled = optional(bool, false)<br/> }), {})<br/> })</pre> | `{}` | no |
83+
| <a name="input_route53_resolver"></a> [route53\_resolver](#input\_route53\_resolver) | (Optional) A configuration for Route53 Resolver in the VPC. `route53_resolver` as defined below.<br/> (Optional) `enabled` - Whether DNS resolution through the Route53 Resolver (the Amazon DNS server) is supported for the VPC. Defaults to `true`.<br/> (Optional) `private_hosted_zones` - A set of private Hosted Zone IDs to associate with the VPC.<br/> (Optional) `profile_association` - A configuration for Route53 Profile association with the VPC. `profile_association` as defined below.<br/> (Required) `name` - The name of the resource association with the Route53 profile.<br/> (Required) `profile` - The ID of the Route53 profile to associate with.<br/> (Optional) `tags` - A map of tags to add to the Route53 Profile association resource.<br/> (Optional) `autodefined_reverse_dns_resolution_enabled` - Whether to enable the autodefined reverse DNS resolution for the VPC. Defaults to `true`.<br/> (Optional) `dnssec_validation` - The configuration for DNSSEC validation in the VPC. `dnssec_validation` as defined below.<br/> (Optional) `enabled` - Whether to use DNSSEC validation to check DNSSEC cryptographic signatures to ensure that a DNS response was not tampered with. Defaults to `false`. | <pre>object({<br/> enabled = optional(bool, true)<br/> private_hosted_zones = optional(set(string), [])<br/> profile_association = optional(object({<br/> name = string<br/> profile = string<br/> tags = optional(map(string), {})<br/> }))<br/> autodefined_reverse_dns_resolution_enabled = optional(bool, true)<br/> dnssec_validation = optional(object({<br/> enabled = optional(bool, false)<br/> }), {})<br/> })</pre> | `{}` | no |
8484
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
8585
| <a name="input_tenancy"></a> [tenancy](#input\_tenancy) | (Optional) A tenancy option for instances launched into the VPC. Valid values are `DEFAULT` and `DEDICATED`. Defaults to `DEFAULT`.<br/> `DEFAULT` - Ensure that EC2 instances launched in this VPC use the EC2 instance tenancy attribute specified when the EC2 instance is launched<br/> `DEDICATED` - Ensure that EC2 instances launched in this VPC are run on dedicated tenancy instances regardless of the tenancy attribute specified at launch. This has a dedicated per region fee of $2 per hour, plus an hourly per instance usage fee. | `string` | `"DEFAULT"` | no |
8686
| <a name="input_vpn_gateway"></a> [vpn\_gateway](#input\_vpn\_gateway) | (Required) The configuration for a virtual private gateway of the VPC. A virtual private gateway is the VPN concentrator on the Amazon side of the site-to-site VPN connection. `vpn_gateway` as defined below.<br/> (Optional) `enabled` - Whether to create a new VPN Gateway resource and attach it to the VPC. Defaults to `false`.<br/> (Optional) `name` - The name of the VPN Gateway. Defaults to same name of the VPC.<br/> (Optional) `asn` - The Autonomous System Number (ASN) for the Amazon side of the gateway. Defaults to `64512`. | <pre>object({<br/> enabled = optional(bool, false)<br/> name = optional(string)<br/> asn = optional(number, 64512)<br/> })</pre> | `{}` | no |

modules/vpc/outputs.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,18 @@ output "route53_resolver" {
144144
value = {
145145
enabled = aws_vpc.this.enable_dns_support
146146
private_hosted_zones = values(aws_route53_zone_association.this)[*].zone_id
147-
profile_associations = [
148-
for name, assoc in aws_route53profiles_association.this : {
149-
id = assoc.id
150-
arn = assoc.arn
151-
name = name
147+
profile_association = (length(aws_route53profiles_association.this) > 0
148+
? {
149+
id = aws_route53profiles_association.this[0].id
150+
arn = aws_route53profiles_association.this[0].arn
151+
name = aws_route53profiles_association.this[0].name
152152
profile = {
153-
id = assoc.profile_id
153+
id = aws_route53profiles_association.this[0].profile_id
154154
}
155-
status = assoc.status
155+
status = aws_route53profiles_association.this[0].status
156156
}
157-
]
157+
: null
158+
)
158159
autodefined_reverse_dns_resolution = aws_route53_resolver_config.this.autodefined_reverse_flag == "ENABLE"
159160
dnssec_validation = {
160161
enabled = var.route53_resolver.dnssec_validation.enabled

modules/vpc/route53.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@ resource "aws_route53_zone_association" "this" {
1717
###################################################
1818

1919
resource "aws_route53profiles_association" "this" {
20-
for_each = {
21-
for assoc in var.route53_resolver.profile_associations :
22-
assoc.name => assoc
23-
}
20+
count = var.route53_resolver.profile_association != null ? 1 : 0
2421

2522
region = aws_vpc.this.region
2623

2724
resource_id = aws_vpc.this.id
2825

29-
name = each.key
30-
profile_id = each.value.profile
26+
name = var.route53_resolver.profile_association.name
27+
profile_id = var.route53_resolver.profile_association.profile
3128

3229
tags = merge(
3330
{
34-
"Name" = "${local.metadata.name}/${each.key}"
31+
"Name" = "${local.metadata.name}/${var.route53_resolver.profile_association.name}"
3532
},
3633
local.module_tags,
3734
var.tags,
38-
each.value.tags,
35+
var.route53_resolver.profile_association.tags,
3936
)
4037
}
4138

modules/vpc/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ variable "route53_resolver" {
113113
(Optional) A configuration for Route53 Resolver in the VPC. `route53_resolver` as defined below.
114114
(Optional) `enabled` - Whether DNS resolution through the Route53 Resolver (the Amazon DNS server) is supported for the VPC. Defaults to `true`.
115115
(Optional) `private_hosted_zones` - A set of private Hosted Zone IDs to associate with the VPC.
116-
(Optional) `profile_associations` - A list of configurations for Route53 Profile associations with the VPC. Each block of `profile_associations` as defined below.
116+
(Optional) `profile_association` - A configuration for Route53 Profile association with the VPC. `profile_association` as defined below.
117117
(Required) `name` - The name of the resource association with the Route53 profile.
118118
(Required) `profile` - The ID of the Route53 profile to associate with.
119119
(Optional) `tags` - A map of tags to add to the Route53 Profile association resource.
@@ -124,11 +124,11 @@ variable "route53_resolver" {
124124
type = object({
125125
enabled = optional(bool, true)
126126
private_hosted_zones = optional(set(string), [])
127-
profile_associations = optional(list(object({
127+
profile_association = optional(object({
128128
name = string
129129
profile = string
130130
tags = optional(map(string), {})
131-
})), [])
131+
}))
132132
autodefined_reverse_dns_resolution_enabled = optional(bool, true)
133133
dnssec_validation = optional(object({
134134
enabled = optional(bool, false)

0 commit comments

Comments
 (0)