Skip to content

Commit b655e72

Browse files
authored
feat: default tgw route table tags (#49)
1 parent bf9871a commit b655e72

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ No modules.
8585

8686
| Name | Type |
8787
|------|------|
88+
| [aws_ec2_tag.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
8889
| [aws_ec2_transit_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway) | resource |
8990
| [aws_ec2_transit_gateway_route.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_route) | resource |
9091
| [aws_ec2_transit_gateway_route_table.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_route_table) | resource |
@@ -116,6 +117,7 @@ No modules.
116117
| <a name="input_ram_tags"></a> [ram\_tags](#input\_ram\_tags) | Additional tags for the RAM | `map(string)` | `{}` | no |
117118
| <a name="input_share_tgw"></a> [share\_tgw](#input\_share\_tgw) | Whether to share your transit gateway with other accounts | `bool` | `true` | no |
118119
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
120+
| <a name="input_tgw_default_route_table_tags"></a> [tgw\_default\_route\_table\_tags](#input\_tgw\_default\_route\_table\_tags) | Additional tags for the Default TGW route table | `map(string)` | `{}` | no |
119121
| <a name="input_tgw_route_table_tags"></a> [tgw\_route\_table\_tags](#input\_tgw\_route\_table\_tags) | Additional tags for the TGW route table | `map(string)` | `{}` | no |
120122
| <a name="input_tgw_tags"></a> [tgw\_tags](#input\_tgw\_tags) | Additional tags for the TGW | `map(string)` | `{}` | no |
121123
| <a name="input_tgw_vpc_attachment_tags"></a> [tgw\_vpc\_attachment\_tags](#input\_tgw\_vpc\_attachment\_tags) | Additional tags for VPC attachments | `map(string)` | `{}` | no |

main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ locals {
1111
vpc_attachments_with_routes = chunklist(flatten([
1212
for k, v in var.vpc_attachments : setproduct([{ key = k }], v["tgw_routes"]) if length(lookup(v, "tgw_routes", {})) > 0
1313
]), 2)
14+
15+
tgw_default_route_table_tags_merged = merge(
16+
{
17+
"Name" = format("%s", var.name)
18+
},
19+
var.tags,
20+
var.tgw_default_route_table_tags,
21+
)
1422
}
1523

1624
resource "aws_ec2_transit_gateway" "this" {
@@ -33,6 +41,13 @@ resource "aws_ec2_transit_gateway" "this" {
3341
)
3442
}
3543

44+
resource "aws_ec2_tag" "this" {
45+
for_each = var.create_tgw ? local.tgw_default_route_table_tags_merged : {}
46+
resource_id = aws_ec2_transit_gateway.this[0].association_default_route_table_id
47+
key = each.key
48+
value = each.value
49+
}
50+
3651
#########################
3752
# Route table and routes
3853
#########################

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ variable "tgw_route_table_tags" {
8585
default = {}
8686
}
8787

88+
variable "tgw_default_route_table_tags" {
89+
description = "Additional tags for the Default TGW route table"
90+
type = map(string)
91+
default = {}
92+
}
93+
8894
variable "tgw_vpc_attachment_tags" {
8995
description = "Additional tags for VPC attachments"
9096
type = map(string)

0 commit comments

Comments
 (0)