tgw.tf 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. resource "aws_ram_resource_share_accepter" "accept_tgw_share" {
  2. count = var.accept_tgw_invitation ? 1 : 0
  3. share_arn = var.tgw_share_arn
  4. }
  5. resource "aws_ec2_transit_gateway_vpc_attachment" "attach_tgw" {
  6. count = var.vpc_info["tgw_attached"] ? 1 : 0
  7. depends_on = [aws_ram_resource_share_accepter.accept_tgw_share]
  8. #subnet_ids = concat(module.vpc.public_subnets, module.vpc.private_subnets)
  9. subnet_ids = module.vpc.private_subnets # Note: Connects to all subnets in vpc, not just private ones
  10. transit_gateway_id = var.tgw_id
  11. vpc_id = module.vpc.vpc_id
  12. tags = merge(
  13. local.standard_tags,
  14. var.tags
  15. )
  16. }
  17. # The VPC automatically tells the TGW about its network, but the
  18. # VPCs themselves need to know what all to send to the TGW. For
  19. # our purposes, it's only RFC1918 addresses. In fact, just
  20. # 10.0.0.0/8 for now.
  21. resource "aws_route" "route_to_10" {
  22. for_each = toset(concat(module.vpc.private_route_table_ids, module.vpc.public_route_table_ids))
  23. route_table_id = each.value
  24. destination_cidr_block = "10.0.0.0/8"
  25. transit_gateway_id = var.tgw_id
  26. }