diff --git a/README.md b/README.md index 13893c7..20817f9 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ No modules. | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | | [tgw\_association\_default\_route\_table\_id](#input\_tgw\_association\_default\_route\_table\_id) | Existing Transit Gateway Route Table ID to use instead of creating a new one | `string` | `"tgw-rtb-0e2771324a8b5ccbc"` | no | | [tgw\_default\_route\_table\_tags](#input\_tgw\_default\_route\_table\_tags) | Additional tags for the Default TGW route table | `map(string)` | `{}` | no | -| [tgw\_peering\_attachments](#input\_tgw\_peering\_attachments) | A map of transit gateway peering attachments |
map(object({| `{}` | no | +| [tgw\_peering\_attachments](#input\_tgw\_peering\_attachments) | A map of transit gateway peering attachments |
peeer_acceptor_tgw_id = string
peer_region = string
peer_account_id = string
request_acceptor = bool
}))
map(object({| `{}` | no | | [tgw\_peering\_route\_table\_routes](#input\_tgw\_peering\_route\_table\_routes) | A list of routes for the Transit Gateway Peering Route Table |
peer_acceptor_tgw_id = string
peer_region = string
peer_account_id = string
request_acceptor = bool
}))
list(object({| `[]` | no | | [tgw\_route\_table\_tags](#input\_tgw\_route\_table\_tags) | Additional tags for the TGW route table | `map(string)` | `{}` | no | | [tgw\_tags](#input\_tgw\_tags) | Additional tags for the TGW | `map(string)` | `{}` | no | diff --git a/main.tf b/main.tf index 4d3056d..ef72c9c 100644 --- a/main.tf +++ b/main.tf @@ -1,8 +1,15 @@ locals { enable_peering = var.enable_peering && !var.create_tgw - tgw_default_route_table_tags_merged = merge( + tags = merge( var.tags, + { + Module = "terraform-aws-transit-gateway" + } + ) + + tgw_default_route_table_tags_merged = merge( + local.tags, { Name = var.name }, var.tgw_default_route_table_tags, ) @@ -53,7 +60,7 @@ resource "aws_ec2_transit_gateway" "this" { } tags = merge( - var.tags, + local.tags, { Name = var.name }, var.tgw_tags, ) @@ -85,7 +92,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" { vpc_id = each.value.vpc_id tags = merge( - var.tags, + local.tags, { Name = var.name }, var.tgw_vpc_attachment_tags, try(each.value.tags, {}), @@ -102,7 +109,7 @@ resource "aws_ec2_transit_gateway_route_table" "this" { transit_gateway_id = aws_ec2_transit_gateway.this[0].id tags = merge( - var.tags, + local.tags, { Name = var.name }, var.tgw_route_table_tags, ) @@ -168,7 +175,7 @@ resource "aws_ram_resource_share" "this" { name = coalesce(var.ram_name, var.name) tags = merge( - var.tags, + local.tags, { Name = coalesce(var.ram_name, var.name) }, var.ram_tags, ) @@ -190,11 +197,11 @@ resource "aws_ec2_transit_gateway_peering_attachment" "this" { peer_account_id = each.value.peer_account_id peer_region = each.value.peer_region - peer_transit_gateway_id = each.value.peeer_acceptor_tgw_id + peer_transit_gateway_id = each.value.peer_acceptor_tgw_id transit_gateway_id = var.peer_requester_tgw_id tags = merge( - var.tags, + local.tags, { Name = "peering-${each.value.peer_region}" } ) diff --git a/variables.tf b/variables.tf index 595e7da..e454e57 100644 --- a/variables.tf +++ b/variables.tf @@ -1,4 +1,18 @@ ################################################################################ +# Common +################################################################################ +variable "name" { + description = "Name to be used on all the resources as identifier" + type = string + default = "" +} + +variable "tags" { + description = "A map of tags to add to all resources" + type = map(string) + default = {} +} +################################################################################ # TGW Peering Settings ################################################################################ variable "peer_requester_tgw_id" { @@ -13,19 +27,14 @@ variable "tgw_association_default_route_table_id" { default = "tgw-rtb-0e2771324a8b5ccbc" } -variable "tags" { - description = "A map of tags to add to all resources" - type = map(string) - default = {} -} variable "tgw_peering_attachments" { description = "A map of transit gateway peering attachments" type = map(object({ - peeer_acceptor_tgw_id = string - peer_region = string - peer_account_id = string - request_acceptor = bool + peer_acceptor_tgw_id = string + peer_region = string + peer_account_id = string + request_acceptor = bool })) default = {} } @@ -45,13 +54,6 @@ variable "enable_peering" { default = false } -variable "name" { - description = "Name to be used on all the resources as identifier" - type = string - default = "" -} - - ################################################################################ # Transit Gateway ################################################################################
destination_cidr_block = string
peering_attachment_key = string
}))