Skip to content

Commit 896ea01

Browse files
committed
feat: Add support for security group referencing
1 parent 9b7a970 commit 896ea01

File tree

4 files changed

+74
-62
lines changed

4 files changed

+74
-62
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,29 @@ No modules.
8585
| Name | Description | Type | Default | Required |
8686
|------|-------------|------|---------|:--------:|
8787
| <a name="input_amazon_side_asn"></a> [amazon\_side\_asn](#input\_amazon\_side\_asn) | The Autonomous System Number (ASN) for the Amazon side of the gateway. By default the TGW is created with the current default Amazon ASN | `string` | `null` | no |
88-
| <a name="input_create"></a> [create](#input\_create) | Controls if TGW should be created (it affects almost all resources) | `bool` | `true` | no |
88+
| <a name="input_auto_accept_shared_attachments"></a> [auto\_accept\_shared\_attachments](#input\_auto\_accept\_shared\_attachments) | Whether resource attachment requests are automatically accepted | `bool` | `false` | no |
89+
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (it affects almost all resources) | `bool` | `true` | no |
8990
| <a name="input_create_flow_log"></a> [create\_flow\_log](#input\_create\_flow\_log) | Whether to create flow log resource(s) | `bool` | `true` | no |
91+
| <a name="input_default_route_table_association"></a> [default\_route\_table\_association](#input\_default\_route\_table\_association) | Whether resource attachments are automatically associated with the default association route table | `bool` | `false` | no |
92+
| <a name="input_default_route_table_propagation"></a> [default\_route\_table\_propagation](#input\_default\_route\_table\_propagation) | Whether resource attachments automatically propagate routes to the default propagation route table | `bool` | `false` | no |
9093
| <a name="input_description"></a> [description](#input\_description) | Description of the EC2 Transit Gateway | `string` | `null` | no |
91-
| <a name="input_enable_auto_accept_shared_attachments"></a> [enable\_auto\_accept\_shared\_attachments](#input\_enable\_auto\_accept\_shared\_attachments) | Whether resource attachment requests are automatically accepted | `bool` | `false` | no |
92-
| <a name="input_enable_default_route_table_association"></a> [enable\_default\_route\_table\_association](#input\_enable\_default\_route\_table\_association) | Whether resource attachments are automatically associated with the default association route table | `bool` | `false` | no |
93-
| <a name="input_enable_default_route_table_propagation"></a> [enable\_default\_route\_table\_propagation](#input\_enable\_default\_route\_table\_propagation) | Whether resource attachments automatically propagate routes to the default propagation route table | `bool` | `false` | no |
94-
| <a name="input_enable_dns_support"></a> [enable\_dns\_support](#input\_enable\_dns\_support) | Should be true to enable DNS support in the TGW | `bool` | `true` | no |
95-
| <a name="input_enable_multicast_support"></a> [enable\_multicast\_support](#input\_enable\_multicast\_support) | Whether multicast support is enabled | `bool` | `false` | no |
94+
| <a name="input_dns_support"></a> [dns\_support](#input\_dns\_support) | Should be true to enable DNS support in the TGW | `bool` | `true` | no |
9695
| <a name="input_enable_ram_share"></a> [enable\_ram\_share](#input\_enable\_ram\_share) | Whether to share your transit gateway with other accounts | `bool` | `false` | no |
97-
| <a name="input_enable_vpn_ecmp_support"></a> [enable\_vpn\_ecmp\_support](#input\_enable\_vpn\_ecmp\_support) | Whether VPN Equal Cost Multipath Protocol support is enabled | `bool` | `true` | no |
9896
| <a name="input_flow_logs"></a> [flow\_logs](#input\_flow\_logs) | Flow Logs to create for Transit Gateway or attachments | <pre>map(object({<br/> deliver_cross_account_role = optional(string)<br/> destination_options = optional(object({<br/> file_format = optional(string, "parquet")<br/> hive_compatible_partitions = optional(bool, false)<br/> per_hour_partition = optional(bool, true)<br/> }))<br/> iam_role_arn = optional(string)<br/> log_destination = optional(string)<br/> log_destination_type = optional(string)<br/> log_format = optional(string)<br/> max_aggregation_interval = optional(number, 30)<br/> traffic_type = optional(string, "ALL")<br/> tags = optional(map(string), {})<br/><br/> enable_transit_gateway = optional(bool, true)<br/> # The following can be provided when `enable_transit_gateway` is `false`<br/> vpc_attachment_key = optional(string)<br/> peering_attachment_key = optional(string)<br/> }))</pre> | `{}` | no |
99-
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | `""` | no |
97+
| <a name="input_multicast_support"></a> [multicast\_support](#input\_multicast\_support) | Whether multicast support is enabled | `bool` | `false` | no |
98+
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as the identifier | `string` | `""` | no |
10099
| <a name="input_peering_attachments"></a> [peering\_attachments](#input\_peering\_attachments) | Map of Transit Gateway peering attachments to create | <pre>map(object({<br/> peer_account_id = string<br/> peer_region = string<br/> peer_transit_gateway_id = string<br/> tags = optional(map(string), {})<br/><br/> accept_peering_attachment = optional(bool, false)<br/> }))</pre> | `{}` | no |
101100
| <a name="input_ram_allow_external_principals"></a> [ram\_allow\_external\_principals](#input\_ram\_allow\_external\_principals) | Indicates whether principals outside your organization can be associated with a resource share | `bool` | `false` | no |
102101
| <a name="input_ram_name"></a> [ram\_name](#input\_ram\_name) | The name of the resource share of TGW | `string` | `""` | no |
103102
| <a name="input_ram_principals"></a> [ram\_principals](#input\_ram\_principals) | A list of principals to share TGW with. Possible values are an AWS account ID, an AWS Organizations Organization ARN, or an AWS Organizations Organization Unit ARN | `set(string)` | `[]` | no |
104103
| <a name="input_ram_tags"></a> [ram\_tags](#input\_ram\_tags) | Additional tags for the RAM | `map(string)` | `{}` | no |
104+
| <a name="input_security_group_referencing_support"></a> [security\_group\_referencing\_support](#input\_security\_group\_referencing\_support) | Whether security group referencing is enabled | `bool` | `false` | no |
105105
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
106106
| <a name="input_tgw_tags"></a> [tgw\_tags](#input\_tgw\_tags) | Additional tags for the TGW | `map(string)` | `{}` | no |
107107
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the transit gateway | `map(string)` | `{}` | no |
108108
| <a name="input_transit_gateway_cidr_blocks"></a> [transit\_gateway\_cidr\_blocks](#input\_transit\_gateway\_cidr\_blocks) | One or more IPv4 or IPv6 CIDR blocks for the transit gateway. Must be a size /24 CIDR block or larger for IPv4, or a size /64 CIDR block or larger for IPv6 | `list(string)` | `[]` | no |
109-
| <a name="input_vpc_attachments"></a> [vpc\_attachments](#input\_vpc\_attachments) | Map of VPC route table attachments to create | <pre>map(object({<br/> vpc_id = string<br/> subnet_ids = list(string)<br/> dns_support = optional(bool, true)<br/> ipv6_support = optional(bool, false)<br/> appliance_mode_support = optional(bool, false)<br/> transit_gateway_default_route_table_association = optional(bool, false)<br/> transit_gateway_default_route_table_propagation = optional(bool, false)<br/> tags = optional(map(string), {})<br/><br/> accept_peering_attachment = optional(bool, false)<br/> }))</pre> | `{}` | no |
109+
| <a name="input_vpc_attachments"></a> [vpc\_attachments](#input\_vpc\_attachments) | Map of VPC route table attachments to create | <pre>map(object({<br/> appliance_mode_support = optional(bool, false)<br/> dns_support = optional(bool, true)<br/> ipv6_support = optional(bool, false)<br/> security_group_referencing_support = optional(bool, false)<br/> subnet_ids = list(string)<br/> tags = optional(map(string), {})<br/> transit_gateway_default_route_table_association = optional(bool, false)<br/> transit_gateway_default_route_table_propagation = optional(bool, false)<br/> vpc_id = string<br/><br/> accept_peering_attachment = optional(bool, false)<br/> }))</pre> | `{}` | no |
110+
| <a name="input_vpn_ecmp_support"></a> [vpn\_ecmp\_support](#input\_vpn\_ecmp\_support) | Whether VPN Equal Cost Multipath Protocol support is enabled | `bool` | `true` | no |
110111

111112
## Outputs
112113

examples/complete/main.tf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ locals {
2323
module "transit_gateway" {
2424
source = "../../"
2525

26-
name = local.name
27-
description = "Example Transit Gateway connecting multiple VPCs"
28-
amazon_side_asn = 64532
29-
transit_gateway_cidr_blocks = ["10.99.0.0/24"]
26+
name = local.name
27+
description = "Example Transit Gateway connecting multiple VPCs"
28+
amazon_side_asn = 64532
29+
security_group_referencing_support = true
30+
transit_gateway_cidr_blocks = ["10.99.0.0/24"]
3031

3132
# flow_logs = {
3233
# tgw = {
@@ -60,14 +61,16 @@ module "transit_gateway" {
6061

6162
vpc_attachments = {
6263
vpc1 = {
63-
vpc_id = module.vpc1.vpc_id
64-
subnet_ids = module.vpc1.private_subnets
65-
ipv6_support = true
64+
vpc_id = module.vpc1.vpc_id
65+
security_group_referencing_support = true
66+
subnet_ids = module.vpc1.private_subnets
67+
ipv6_support = true
6668
}
6769

6870
vpc2 = {
69-
vpc_id = module.vpc2.vpc_id
70-
subnet_ids = module.vpc2.private_subnets
71+
vpc_id = module.vpc2.vpc_id
72+
security_group_referencing_support = true
73+
subnet_ids = module.vpc2.private_subnets
7174
}
7275
}
7376

main.tf

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ locals {
1313
resource "aws_ec2_transit_gateway" "this" {
1414
count = var.create ? 1 : 0
1515

16-
description = var.description
17-
amazon_side_asn = var.amazon_side_asn
18-
default_route_table_association = var.enable_default_route_table_association ? "enable" : "disable"
19-
default_route_table_propagation = var.enable_default_route_table_propagation ? "enable" : "disable"
20-
auto_accept_shared_attachments = var.enable_auto_accept_shared_attachments ? "enable" : "disable"
21-
multicast_support = var.enable_multicast_support ? "enable" : "disable"
22-
vpn_ecmp_support = var.enable_vpn_ecmp_support ? "enable" : "disable"
23-
dns_support = var.enable_dns_support ? "enable" : "disable"
24-
transit_gateway_cidr_blocks = var.transit_gateway_cidr_blocks
16+
amazon_side_asn = var.amazon_side_asn
17+
auto_accept_shared_attachments = var.auto_accept_shared_attachments ? "enable" : "disable"
18+
default_route_table_association = var.default_route_table_association ? "enable" : "disable"
19+
default_route_table_propagation = var.default_route_table_propagation ? "enable" : "disable"
20+
description = var.description
21+
dns_support = var.dns_support ? "enable" : "disable"
22+
multicast_support = var.multicast_support ? "enable" : "disable"
23+
security_group_referencing_support = var.security_group_referencing_support ? "enable" : "disable"
24+
transit_gateway_cidr_blocks = var.transit_gateway_cidr_blocks
25+
vpn_ecmp_support = var.vpn_ecmp_support ? "enable" : "disable"
2526

2627
timeouts {
2728
create = try(var.timeouts.create, null)
@@ -33,7 +34,7 @@ resource "aws_ec2_transit_gateway" "this" {
3334
}
3435

3536
resource "aws_ec2_tag" "this" {
36-
for_each = { for k, v in local.tgw_tags : k => v if var.create && var.enable_default_route_table_association }
37+
for_each = { for k, v in local.tgw_tags : k => v if var.create && var.default_route_table_association }
3738

3839
resource_id = aws_ec2_transit_gateway.this[0].association_default_route_table_id
3940
key = each.key
@@ -47,15 +48,15 @@ resource "aws_ec2_tag" "this" {
4748
resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
4849
for_each = { for k, v in var.vpc_attachments : k => v if var.create }
4950

50-
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
51-
vpc_id = each.value.vpc_id
52-
subnet_ids = each.value.subnet_ids
53-
51+
appliance_mode_support = each.value.appliance_mode_support ? "enable" : "disable"
5452
dns_support = each.value.dns_support ? "enable" : "disable"
5553
ipv6_support = each.value.ipv6_support ? "enable" : "disable"
56-
appliance_mode_support = each.value.appliance_mode_support ? "enable" : "disable"
54+
security_group_referencing_support = each.value.security_group_referencing_support ? "enable" : "disable"
55+
subnet_ids = each.value.subnet_ids
5756
transit_gateway_default_route_table_association = each.value.transit_gateway_default_route_table_association
5857
transit_gateway_default_route_table_propagation = each.value.transit_gateway_default_route_table_propagation
58+
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
59+
vpc_id = each.value.vpc_id
5960

6061
tags = merge(
6162
var.tags,

variables.tf

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
variable "create" {
2+
description = "Controls if resources should be created (it affects almost all resources)"
3+
type = bool
4+
default = true
5+
}
6+
17
variable "name" {
2-
description = "Name to be used on all the resources as identifier"
8+
description = "Name to be used on all the resources as the identifier"
39
type = string
410
default = ""
511
}
@@ -14,58 +20,52 @@ variable "tags" {
1420
# Transit Gateway
1521
################################################################################
1622

17-
variable "create" {
18-
description = "Controls if TGW should be created (it affects almost all resources)"
19-
type = bool
20-
default = true
21-
}
22-
23-
variable "description" {
24-
description = "Description of the EC2 Transit Gateway"
25-
type = string
26-
default = null
27-
}
28-
2923
variable "amazon_side_asn" {
3024
description = "The Autonomous System Number (ASN) for the Amazon side of the gateway. By default the TGW is created with the current default Amazon ASN"
3125
type = string
3226
default = null
3327
}
3428

35-
variable "enable_default_route_table_association" {
36-
description = "Whether resource attachments are automatically associated with the default association route table"
29+
variable "auto_accept_shared_attachments" {
30+
description = "Whether resource attachment requests are automatically accepted"
3731
type = bool
3832
default = false
3933
}
4034

41-
variable "enable_default_route_table_propagation" {
42-
description = "Whether resource attachments automatically propagate routes to the default propagation route table"
35+
variable "default_route_table_association" {
36+
description = "Whether resource attachments are automatically associated with the default association route table"
4337
type = bool
4438
default = false
4539
}
4640

47-
variable "enable_auto_accept_shared_attachments" {
48-
description = "Whether resource attachment requests are automatically accepted"
41+
variable "default_route_table_propagation" {
42+
description = "Whether resource attachments automatically propagate routes to the default propagation route table"
4943
type = bool
5044
default = false
5145
}
5246

53-
variable "enable_vpn_ecmp_support" {
54-
description = "Whether VPN Equal Cost Multipath Protocol support is enabled"
47+
variable "description" {
48+
description = "Description of the EC2 Transit Gateway"
49+
type = string
50+
default = null
51+
}
52+
53+
variable "dns_support" {
54+
description = "Should be true to enable DNS support in the TGW"
5555
type = bool
5656
default = true
5757
}
5858

59-
variable "enable_multicast_support" {
59+
variable "multicast_support" {
6060
description = "Whether multicast support is enabled"
6161
type = bool
6262
default = false
6363
}
6464

65-
variable "enable_dns_support" {
66-
description = "Should be true to enable DNS support in the TGW"
65+
variable "security_group_referencing_support" {
66+
description = "Whether security group referencing is enabled"
6767
type = bool
68-
default = true
68+
default = false
6969
}
7070

7171
variable "transit_gateway_cidr_blocks" {
@@ -74,6 +74,12 @@ variable "transit_gateway_cidr_blocks" {
7474
default = []
7575
}
7676

77+
variable "vpn_ecmp_support" {
78+
description = "Whether VPN Equal Cost Multipath Protocol support is enabled"
79+
type = bool
80+
default = true
81+
}
82+
7783
variable "timeouts" {
7884
description = "Create, update, and delete timeout configurations for the transit gateway"
7985
type = map(string)
@@ -93,14 +99,15 @@ variable "tgw_tags" {
9399
variable "vpc_attachments" {
94100
description = "Map of VPC route table attachments to create"
95101
type = map(object({
96-
vpc_id = string
97-
subnet_ids = list(string)
102+
appliance_mode_support = optional(bool, false)
98103
dns_support = optional(bool, true)
99104
ipv6_support = optional(bool, false)
100-
appliance_mode_support = optional(bool, false)
105+
security_group_referencing_support = optional(bool, false)
106+
subnet_ids = list(string)
107+
tags = optional(map(string), {})
101108
transit_gateway_default_route_table_association = optional(bool, false)
102109
transit_gateway_default_route_table_propagation = optional(bool, false)
103-
tags = optional(map(string), {})
110+
vpc_id = string
104111

105112
accept_peering_attachment = optional(bool, false)
106113
}))

0 commit comments

Comments
 (0)