Skip to content

Commit

Permalink
add tags for the vpn attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Feb 26, 2022
1 parent 57b2c6b commit 84ca88a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vpn-transit-gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ No modules.
| Name | Type |
|------|------|
| [aws_customer_gateway.vpn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/customer_gateway) | resource |
| [aws_ec2_tag.vpn_tag_created_by](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_ec2_tag.vpn_tag_environment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_ec2_tag.vpn_tag_name](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_ec2_transit_gateway_route_table_association.route_table](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_route_table_association) | resource |
| [aws_ec2_transit_gateway_route_table_propagation.propagate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_route_table_propagation) | resource |
| [aws_vpn_connection.vpn](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection) | resource |
Expand Down
21 changes: 21 additions & 0 deletions vpn-transit-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ resource "aws_vpn_connection" "vpn" {
)
}

# attachments are implicity. Use aws_ec2_tag to set the tags
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway_vpn_attachment

resource "aws_ec2_tag" "vpn_tag_created_by" {
for_each = var.create ? local.vpn_settings : {}
resource_id = aws_vpn_connection.vpn[each.key].transit_gateway_attachment_id
key = "boc:created_by"
value = local.base_tags["boc:created_by"]
}
resource "aws_ec2_tag" "vpn_tag_name" {
for_each = var.create ? local.vpn_settings : {}
resource_id = aws_vpn_connection.vpn[each.key].transit_gateway_attachment_id
key = "Name"
value = format("%v%v%v", (var.use_tgw_prefixes ? local._prefixes["transit-gateway-vpn"] : ""), local._prefixes["vpn-connection"], each.key)
}
resource "aws_ec2_tag" "vpn_tag_environment" {
for_each = var.create ? local.vpn_settings : {}
resource_id = aws_vpn_connection.vpn[each.key].transit_gateway_attachment_id
key = "boc:tgw_environmen"
value = var.tgw_environment
}

## #---
## # vpn routes and propagation
Expand Down

0 comments on commit 84ca88a

Please sign in to comment.