Skip to content

Commit

Permalink
feat: Added Transit Gateway Attachment tagging (#92)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <anton@antonbabenko.com>
Co-authored-by: jrkalf <jelle@kalf.org>
  • Loading branch information
3 people authored Sep 18, 2023
1 parent 7c5b222 commit 9f82005
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ No modules.

| Name | Type |
|------|------|
| [aws_ec2_tag.tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_vpn_connection.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection) | resource |
| [aws_vpn_connection.preshared](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection) | resource |
| [aws_vpn_connection.tunnel](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection) | resource |
Expand Down
11 changes: 11 additions & 0 deletions examples/complete-vpn-connection-transit-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module "vpn_gateway_1" {

create_vpn_gateway_attachment = false
connect_to_transit_gateway = true

tags = {
key1 = "example value 1"
key2 = "example value 2"
}
}

module "vpn_gateway_2" {
Expand All @@ -38,6 +43,12 @@ module "vpn_gateway_2" {

create_vpn_gateway_attachment = false
connect_to_transit_gateway = true

tags = {
vpn2a = "example value 1"
vpn2b = "example value 2"
}

}

module "vpc" {
Expand Down
15 changes: 15 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,18 @@ resource "aws_vpn_connection_route" "default" {

destination_cidr_block = element(var.vpn_connection_static_routes_destinations, count.index)
}

### Fix tagging on Transit Gateway Attachment if it exists
resource "aws_ec2_tag" "tags" {
for_each = { for key, value in merge({ "Name" = local.name_tag }, var.tags) : key => value if var.create_vpn_connection && var.connect_to_transit_gateway }

resource_id = try(
aws_vpn_connection.default[0].transit_gateway_attachment_id,
aws_vpn_connection.tunnel[0].transit_gateway_attachment_id,
aws_vpn_connection.preshared[0].transit_gateway_attachment_id,
aws_vpn_connection.tunnel_preshared[0].transit_gateway_attachment_id
)

key = each.key
value = each.value
}

0 comments on commit 9f82005

Please sign in to comment.