Skip to content

Commit 5ea987b

Browse files
committed
Support transit gateway vpc attachments for subnet-group module
1 parent 03f8a7d commit 5ea987b

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.31.1
1+
0.32.0

modules/subnet-group/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This module creates following resources.
4141
| [aws_db_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_subnet_group) | resource |
4242
| [aws_dms_replication_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dms_replication_subnet_group) | resource |
4343
| [aws_docdb_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/docdb_subnet_group) | resource |
44+
| [aws_ec2_transit_gateway_vpc_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_vpc_attachment) | resource |
4445
| [aws_elasticache_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
4546
| [aws_memorydb_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/memorydb_subnet_group) | resource |
4647
| [aws_neptune_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/neptune_subnet_group) | resource |
@@ -75,6 +76,7 @@ This module creates following resources.
7576
| <a name="input_shares"></a> [shares](#input\_shares) | (Optional) A list of resource shares via RAM (Resource Access Manager). | <pre>list(object({<br> name = optional(string)<br><br> permissions = optional(set(string), ["AWSRAMDefaultPermissionSubnet"])<br><br> external_principals_allowed = optional(bool, false)<br> principals = optional(set(string), [])<br><br> tags = optional(map(string), {})<br> }))</pre> | `[]` | no |
7677
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
7778
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | (Optional) How long to wait for the subnet group to be created/deleted. | <pre>object({<br> create = optional(string, "10m")<br> delete = optional(string, "20m")<br> })</pre> | `{}` | no |
79+
| <a name="input_transit_gateway_attachments"></a> [transit\_gateway\_attachments](#input\_transit\_gateway\_attachments) | (Optional) A list of configurations for Transit Gateway VPC attachments. Each block of `transit_gateway_attachments` as defined below.<br> (Required) `name` - The name of the Transit Gateway VPC attachment.<br> (Required) `transit_gateway` - The ID of the Transit Gateway.<br> (Optional) `appliance_mode_enabled` - Whether Appliance Mode support is enabled. If enabled, a traffic flow between a source and destination uses the same Availability Zone for the VPC attachment for the lifetime of that flow. Defaults to `false`.<br> (Optional) `dns_support_enabled` - Whether to enable Domain Name System resolution for VPCs attached to this transit gateway. Defaults to `true`.<br> (Optional) `ipv6_enabled` - Whether to enable IPv6 support. Defaults to `false`.<br> (Optional) `default_association_route_table_enabled` - Whether to automatically associate transit gateway attachments with this transit gateway's default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways. Defaults to `false`.<br> (Optional) `default_propagation_route_table_enabled` - Whether to automatically propagate transit gateway attachments with this transit gateway's default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways. Defaults to `false`.<br> (Optional) `tags` - A map of tags to add to the vpc association. | <pre>list(object({<br> name = string<br> transit_gateway = string<br> appliance_mode_enabled = optional(bool, false)<br> dns_support_enabled = optional(bool, true)<br> ipv6_enabled = optional(bool, false)<br> default_association_route_table_enabled = optional(bool, false)<br> default_propagation_route_table_enabled = optional(bool, false)<br><br> tags = optional(map(string), {})<br> }))</pre> | `[]` | no |
7880

7981
## Outputs
8082

@@ -104,5 +106,6 @@ This module creates following resources.
104106
| <a name="output_sharing"></a> [sharing](#output\_sharing) | The configuration for sharing of subnets in the subnet group.<br> `status` - An indication of whether subnets are shared with other AWS accounts, or was shared with the current account by another AWS account. Sharing is configured through AWS Resource Access Manager (AWS RAM). Values are `NOT_SHARED`, `SHARED_BY_ME` or `SHARED_WITH_ME`.<br> `shares` - The list of resource shares via RAM (Resource Access Manager). |
105107
| <a name="output_subnets"></a> [subnets](#output\_subnets) | A list of subnets of the subnet group. |
106108
| <a name="output_subnets_by_az"></a> [subnets\_by\_az](#output\_subnets\_by\_az) | A map of subnets of the subnet group which are grouped by availability zone id. |
109+
| <a name="output_transit_gateway_attachments"></a> [transit\_gateway\_attachments](#output\_transit\_gateway\_attachments) | The configuration of Transit Gateway VPC attachments. |
107110
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | The ID of the VPC which the subnet group belongs to. |
108111
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/subnet-group/integrations.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
###################################################
2+
# VPC Attachments for Transit Gateway
3+
###################################################
4+
5+
resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
6+
for_each = {
7+
for attachment in var.transit_gateway_attachments :
8+
attachment.name => attachment
9+
}
10+
11+
vpc_id = var.vpc_id
12+
subnet_ids = values(aws_subnet.this)[*].id
13+
14+
transit_gateway_id = each.value.transit_gateway
15+
16+
appliance_mode_support = each.value.appliance_mode_enabled ? "enable" : "disable"
17+
dns_support = each.value.dns_support_enabled ? "enable" : "disable"
18+
ipv6_support = each.value.ipv6_enabled ? "enable" : "disable"
19+
transit_gateway_default_route_table_association = each.value.default_association_route_table_enabled
20+
transit_gateway_default_route_table_propagation = each.value.default_propagation_route_table_enabled
21+
22+
tags = merge(
23+
{
24+
"Name" = each.key
25+
},
26+
local.module_tags,
27+
var.tags,
28+
each.value.tags,
29+
)
30+
}
31+
32+
133
###################################################
234
# Subnet Group for DAX
335
###################################################

modules/subnet-group/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ output "dns_config" {
111111
}
112112
}
113113

114+
output "transit_gateway_attachments" {
115+
description = <<EOF
116+
The configuration of Transit Gateway VPC attachments.
117+
EOF
118+
value = {
119+
for name, attachment in aws_ec2_transit_gateway_vpc_attachment.this :
120+
name => {
121+
name = name
122+
transit_gateway = attachment.transit_gateway_id
123+
124+
appliance_mode_enabled = attachment.appliance_mode_support == "enable"
125+
dns_support_enabled = attachment.dns_support == "enable"
126+
ipv6_enabled = attachment.ipv6_support == "enable"
127+
default_association_route_table_enabled = attachment.transit_gateway_default_route_table_association
128+
default_propagation_route_table_enabled = attachment.transit_gateway_default_route_table_propagation
129+
}
130+
}
131+
}
132+
114133
output "dax_subnet_group" {
115134
description = <<EOF
116135
The configuration of DAX Subnet Group.

modules/subnet-group/variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,41 @@ variable "dns_config" {
131131
}
132132
}
133133

134+
variable "transit_gateway_attachments" {
135+
description = <<EOF
136+
(Optional) A list of configurations for Transit Gateway VPC attachments. Each block of `transit_gateway_attachments` as defined below.
137+
(Required) `name` - The name of the Transit Gateway VPC attachment.
138+
(Required) `transit_gateway` - The ID of the Transit Gateway.
139+
(Optional) `appliance_mode_enabled` - Whether Appliance Mode support is enabled. If enabled, a traffic flow between a source and destination uses the same Availability Zone for the VPC attachment for the lifetime of that flow. Defaults to `false`.
140+
(Optional) `dns_support_enabled` - Whether to enable Domain Name System resolution for VPCs attached to this transit gateway. Defaults to `true`.
141+
(Optional) `ipv6_enabled` - Whether to enable IPv6 support. Defaults to `false`.
142+
(Optional) `default_association_route_table_enabled` - Whether to automatically associate transit gateway attachments with this transit gateway's default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways. Defaults to `false`.
143+
(Optional) `default_propagation_route_table_enabled` - Whether to automatically propagate transit gateway attachments with this transit gateway's default route table. This cannot be configured or perform drift detection with Resource Access Manager shared EC2 Transit Gateways. Defaults to `false`.
144+
(Optional) `tags` - A map of tags to add to the vpc association.
145+
EOF
146+
type = list(object({
147+
name = string
148+
transit_gateway = string
149+
appliance_mode_enabled = optional(bool, false)
150+
dns_support_enabled = optional(bool, true)
151+
ipv6_enabled = optional(bool, false)
152+
default_association_route_table_enabled = optional(bool, false)
153+
default_propagation_route_table_enabled = optional(bool, false)
154+
155+
tags = optional(map(string), {})
156+
}))
157+
default = []
158+
nullable = false
159+
160+
validation {
161+
condition = alltrue([
162+
for attachment in var.transit_gateway_attachments :
163+
startswith(attachment.transit_gateway, "tgw-")
164+
])
165+
error_message = "Valid value for `transit_gateway` must be the ID of the Transit Gateway."
166+
}
167+
}
168+
134169
variable "dax_subnet_group" {
135170
description = <<EOF
136171
(Optional) A configuration of DAX Subnet Group. `dax_subnet_group` as defined below.

0 commit comments

Comments
 (0)