Przeglądaj źródła

Merges transit gateway attachment into standard VPC module

Removes need for separate transit_gateway_attachment module, though that
is still needed for certain others.

To be tagged v0.8.1
Fred Damstra 4 lat temu
rodzic
commit
6746617d8b

+ 31 - 0
base/standard_vpc/tgw.tf

@@ -0,0 +1,31 @@
+resource "aws_ram_resource_share_accepter" "accept_tgw_share" {
+  count = var.accept_tgw_invitation ? 1 : 0
+  share_arn = var.tgw_share_arn
+}
+
+resource "aws_ec2_transit_gateway_vpc_attachment" "attach_tgw" {
+  count = var.vpc_info["tgw_attached"] ? 1 : 0
+  depends_on = [ aws_ram_resource_share_accepter.accept_tgw_share ]
+
+  #subnet_ids         = concat(module.vpc.public_subnets, module.vpc.private_subnets)
+  subnet_ids         = module.vpc.private_subnets # Note: Connects to all subnets in vpc, not just private ones
+  transit_gateway_id = var.tgw_id
+  vpc_id             = module.vpc.vpc_id
+
+  tags = merge(
+    var.standard_tags, 
+    var.tags
+  )
+}
+
+# The VPC automatically tells the TGW about its network, but the
+# VPCs themselves need to know what all to send to the TGW. For
+# our purposes, it's only RFC1918 addresses. In fact, just 
+# 10.0.0.0/8 for now.
+resource "aws_route" "route_to_10" {
+  for_each = toset(concat(module.vpc.private_route_table_ids, module.vpc.public_route_table_ids))
+
+  route_table_id            = each.value
+  destination_cidr_block    = "10.0.0.0/8"
+  transit_gateway_id        = var.tgw_id
+}

+ 16 - 0
base/standard_vpc/vars.tf

@@ -1,3 +1,19 @@
+variable "accept_tgw_invitation" {
+  description = "Whether to accept the transit gateway sharing invitation. Only done once per account."
+  type        = bool
+}
+
+variable "tgw_id" {
+  description = "Transit Gateway ID"
+  type = string
+}
+
+variable "tgw_share_arn" {
+  description = "The ARN of the share to accept."
+  type        = string
+  default     = ""
+}
+
 variable "vpc_info" {
   description = "A map of information about the VPC to create. Must contain `name` and `cidr`."
   type = map

+ 3 - 1
base/transit_gateway_client/README.md

@@ -1,3 +1,5 @@
 # Transit Gateway Client
 
-Accepts the invitation to the transit gateway and attaches the VPCs.
+Accepts the invitation to the transit gateway and attaches a VPC.
+
+NOTE: This is usually handled by the standard_vpc module itself, and does not need to be done separately.

+ 0 - 1
base/transit_gateway_client/main.tf

@@ -31,4 +31,3 @@ resource "aws_route" "route_to_10" {
   destination_cidr_block    = "10.0.0.0/8"
   transit_gateway_id        = var.tgw_id
 }
-

+ 1 - 2
base/transit_gateway_client/vars.tf

@@ -1,4 +1,3 @@
-
 variable "tags" {
   description = "Tags to add to the resource (in addition to global standard tags)"
   type        = map
@@ -17,7 +16,7 @@ variable "share_arn" {
 }
 
 variable tgw_id {
-  description = "VPC ID of the client"
+  description = "Transit Gateway ID"
   type = string
 }