Skip to content

Commit

Permalink
fix up tags
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Dec 16, 2022
1 parent 16b0916 commit ee67e6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 11 additions & 5 deletions vpc-transit-gateway-association/self/associate.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
locals {
attachment_tags = {
Name = format("%v:%v", data.aws_iam_account_alias.current.account_alias, var.vpc_full_name)
"boc:tgw_environment" = var.transit_gateway_environment
}
}

#---
# attach this vpc to tgw (my region, my account)
#---
Expand All @@ -14,17 +21,16 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "vpc_attachment" {

tags = merge(
local.base_tags,
{
Name = format("tgwa-%v-%v-%v", var.transit_gateway_label, var.vpc_full_name, local.region),
"boc:tgw_environment" = var.transit_gateway_environment,
},
var.tags,
local.attachment_tags,
)
}

# tag in network account with passed-in tags, plus Name=current_account:vpc_name
# if this is the network account, no need to add the additional tags as they are already there
resource "aws_ec2_tag" "vpc_attachment" {
provider = aws.self
for_each = merge(var.tags, { Name = format("%v:%v", data.aws_iam_account_alias.current.account_alias, var.vpc_full_name) })
for_each = ! local.self_is_network_account ? merge(local.base_tags, var.tags, local.attachment_tags) : {}

resource_id = aws_ec2_transit_gateway_vpc_attachment.vpc_attachment.id
key = each.key
Expand Down
9 changes: 5 additions & 4 deletions vpc-transit-gateway-association/self/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
*/

locals {
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
region = data.aws_region.current.name
region_short = join("", [for c in split("-", local.region) : substr(c, 0, 1)])
account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id
account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew"
region = data.aws_region.current.name
region_short = join("", [for c in split("-", local.region) : substr(c, 0, 1)])
self_is_network_account = data.aws_caller_identity.current.account_id == data.aws_caller_identity.network_account.account_id

base_tags = {
"boc:tf_module_version" = local._module_version
Expand Down

0 comments on commit ee67e6d

Please sign in to comment.