Skip to content

Commit f8441a2

Browse files
committed
fix: Correct flow logs, add Name tags, update README
1 parent 896ea01 commit f8441a2

File tree

3 files changed

+148
-43
lines changed

3 files changed

+148
-43
lines changed

README.md

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,76 @@
11
# AWS Transit Gateway Terraform module
22

3-
Terraform module which creates Transit Gateway resources on AWS.
3+
Terraform module which creates AWS Transit Gateway resources.
44

5-
## Usage with VPC module
5+
## Usage
66

77
```hcl
88
module "transit_gateway" {
99
source = "terraform-aws-modules/transit-gateway/aws"
1010
1111
name = "example"
12-
description = "Example TGW shared with several other AWS accounts"
12+
description = "Example TGW connecting multiple VPCs"
1313
1414
# When `true` there is no need for RAM resources if using multiple AWS accounts
15-
enable_auto_accept_shared_attachments = true
15+
auto_accept_shared_attachments = true
16+
17+
flow_logs = {
18+
tgw = {
19+
log_destination = "arn:aws:s3:::flow-log-bucket"
20+
log_destination_type = "s3"
21+
traffic_type = "ALL"
22+
destination_options = {
23+
file_format = "parquet"
24+
per_hour_partition = true
25+
}
26+
},
27+
vpc1-attach = {
28+
enable_transit_gateway = false
29+
vpc_attachment_key = "vpc1"
30+
31+
log_destination = "arn:aws:s3:::flow-log-bucket"
32+
log_destination_type = "s3"
33+
traffic_type = "ALL"
34+
destination_options = {
35+
file_format = "parquet"
36+
per_hour_partition = true
37+
}
38+
},
39+
vpc2-attach = {
40+
enable_transit_gateway = false
41+
vpc_attachment_key = "vpc2"
42+
43+
log_destination = "arn:aws:s3:::flow-log-bucket"
44+
log_destination_type = "s3"
45+
traffic_type = "ALL"
46+
destination_options = {
47+
file_format = "parquet"
48+
per_hour_partition = true
49+
}
50+
}
51+
}
52+
53+
vpc_attachments = {
54+
vpc1 = {
55+
vpc_id = "vpc-1234556abcdef"
56+
security_group_referencing_support = true
57+
subnet_ids = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
58+
ipv6_support = true
59+
}
60+
61+
vpc2 = {
62+
vpc_id = "vpc-98765432d1aad"
63+
security_group_referencing_support = true
64+
subnet_ids = ["subnet-334de012", "subnet-6vfe012a", "subnet-agfi435a"]
65+
}
66+
}
1667
1768
vpc_attachments = {
1869
vpc = {
1970
attachment_type = "vpc"
2071
create_vpc_attachment = true
21-
vpc_id = "vpc-1234556abcdef"
22-
subnet_ids = ["subnet-abcde012", "subnet-bcde012a", "subnet-fghi345a"]
72+
vpc_id =
73+
subnet_ids =
2374
2475
dns_support = true
2576
ipv6_support = true
@@ -37,7 +88,49 @@ module "transit_gateway" {
3788
}
3889
3990
tags = {
40-
Purpose = "tgw-complete-example"
91+
Environment = "Development"
92+
Project = "Example"
93+
}
94+
}
95+
96+
module "transit_gateway_route_table" {
97+
source = "terraform-aws-modules/transit-gateway/aws//modules/route-table"
98+
99+
name = "example"
100+
transit_gateway_id = module.transit_gateway.id
101+
102+
associations = {
103+
vpc1 = {
104+
transit_gateway_attachment_id = module.transit_gateway.vpc_attachments["vpc1"].id
105+
propagate_route_table = true
106+
}
107+
vpc2 = {
108+
transit_gateway_attachment_id = module.transit_gateway.vpc_attachments["vpc2"].id
109+
propagate_route_table = true
110+
}
111+
}
112+
113+
routes = {
114+
blackhole = {
115+
blackhole = true
116+
destination_cidr_block = "0.0.0.0/0"
117+
}
118+
}
119+
120+
vpc_routes = {
121+
vpc1 = {
122+
destination_cidr_block = "10.0.0.0/16"
123+
route_table_id = "rtb-a73c2ede"
124+
}
125+
vpc2 = {
126+
destination_cidr_block = 10.1.0.0/16"
127+
route_table_id = "rtb-852956e2",
128+
}
129+
}
130+
131+
tags = {
132+
Environment = "Development"
133+
Project = "Example"
41134
}
42135
}
43136
```

examples/complete/main.tf

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,41 @@ module "transit_gateway" {
2929
security_group_referencing_support = true
3030
transit_gateway_cidr_blocks = ["10.99.0.0/24"]
3131

32-
# flow_logs = {
33-
# tgw = {
34-
# log_destination = module.s3_bucket.s3_bucket_arn
35-
# log_destination_type = "s3"
36-
# traffic_type = "ALL"
37-
# destination_options = {
38-
# file_format = "parquet"
39-
# per_hour_partition = true
40-
# }
41-
# }
42-
# vpc1-attach = {
43-
# log_destination = module.s3_bucket.s3_bucket_arn
44-
# log_destination_type = "s3"
45-
# traffic_type = "ALL"
46-
# destination_options = {
47-
# file_format = "parquet"
48-
# per_hour_partition = true
49-
# }
50-
# }
51-
# vpc2-attach = {
52-
# log_destination = module.s3_bucket.s3_bucket_arn
53-
# log_destination_type = "s3"
54-
# traffic_type = "ALL"
55-
# destination_options = {
56-
# file_format = "parquet"
57-
# per_hour_partition = true
58-
# }
59-
# }
60-
# }
32+
flow_logs = {
33+
tgw = {
34+
log_destination = module.s3_bucket.s3_bucket_arn
35+
log_destination_type = "s3"
36+
traffic_type = "ALL"
37+
destination_options = {
38+
file_format = "parquet"
39+
per_hour_partition = true
40+
}
41+
},
42+
vpc1-attach = {
43+
enable_transit_gateway = false
44+
vpc_attachment_key = "vpc1"
45+
46+
log_destination = module.s3_bucket.s3_bucket_arn
47+
log_destination_type = "s3"
48+
traffic_type = "ALL"
49+
destination_options = {
50+
file_format = "parquet"
51+
per_hour_partition = true
52+
}
53+
},
54+
vpc2-attach = {
55+
enable_transit_gateway = false
56+
vpc_attachment_key = "vpc2"
57+
58+
log_destination = module.s3_bucket.s3_bucket_arn
59+
log_destination_type = "s3"
60+
traffic_type = "ALL"
61+
destination_options = {
62+
file_format = "parquet"
63+
per_hour_partition = true
64+
}
65+
}
66+
}
6167

6268
vpc_attachments = {
6369
vpc1 = {

main.tf

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
6060

6161
tags = merge(
6262
var.tags,
63-
{ Name = each.key },
63+
{ Name = "${var.name}-${each.key}" },
6464
each.value.tags,
6565
)
6666
}
@@ -74,7 +74,6 @@ resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "this" {
7474

7575
tags = merge(
7676
var.tags,
77-
{ Name = each.key },
7877
each.value.tags,
7978
)
8079
}
@@ -91,15 +90,22 @@ resource "aws_ec2_transit_gateway_peering_attachment" "this" {
9190
peer_transit_gateway_id = each.value.peer_transit_gateway_id
9291
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
9392

94-
tags = var.tags
93+
tags = merge(
94+
var.tags,
95+
{ Name = "${var.name}-${each.key}" },
96+
each.value.tags,
97+
)
9598
}
9699

97100
resource "aws_ec2_transit_gateway_peering_attachment_accepter" "this" {
98101
for_each = { for k, v in var.peering_attachments : k => v if var.create && v.accept_peering_attachment }
99102

100103
transit_gateway_attachment_id = aws_ec2_transit_gateway_peering_attachment.this[each.key].id
101104

102-
tags = var.tags
105+
tags = merge(
106+
var.tags,
107+
each.value.tags,
108+
)
103109
}
104110

105111
################################################################################
@@ -150,9 +156,9 @@ resource "aws_flow_log" "this" {
150156
for_each = each.value.destination_options != null ? [each.value.destination_options] : []
151157

152158
content {
153-
file_format = each.value.file_format
154-
hive_compatible_partitions = each.value.hive_compatible_partitions
155-
per_hour_partition = each.value.per_hour_partition
159+
file_format = destination_options.value.file_format
160+
hive_compatible_partitions = destination_options.value.hive_compatible_partitions
161+
per_hour_partition = destination_options.value.per_hour_partition
156162
}
157163
}
158164

0 commit comments

Comments
 (0)