Skip to content

Commit

Permalink
Tags the same if overlapping resources (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrken authored and grem11n committed Oct 18, 2019
1 parent a2a28d2 commit 32ccbcb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ provider "aws" {
locals {
this_region = data.aws_region.this.name
peer_region = data.aws_region.peer.name

same_region = data.aws_region.this.name == data.aws_region.peer.name
same_account = data.aws_caller_identity.this.account_id == data.aws_caller_identity.peer.account_id
same_acount_and_region = local.same_region && local.same_account
}

##########################
Expand All @@ -23,7 +27,7 @@ resource "aws_vpc_peering_connection" "this" {
peer_vpc_id = var.peer_vpc_id
vpc_id = var.this_vpc_id
peer_region = data.aws_region.peer.name
tags = var.tags
tags = merge(var.tags, map("Side", local.same_acount_and_region ? "Both" : "Requester"))
}

######################################
Expand All @@ -33,7 +37,7 @@ resource "aws_vpc_peering_connection_accepter" "peer_accepter" {
provider = "aws.peer"
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
auto_accept = var.auto_accept_peering
tags = merge(var.tags, map("Side", "Accepter"))
tags = merge(var.tags, map("Side", local.same_acount_and_region ? "Both" : "Accepter"))
}

#######################
Expand Down

0 comments on commit 32ccbcb

Please sign in to comment.