From 2a740bc3eda1e159f28577362a3a7d7c14ba4a86 Mon Sep 17 00:00:00 2001 From: Antonio Falzarano Date: Fri, 24 Jan 2020 11:22:24 +0100 Subject: [PATCH 1/3] added nat gateway to route tables --- lib/terraforming/resource/route_table.rb | 1 + lib/terraforming/template/tf/route_table.erb | 3 +++ .../terraforming/resource/route_table_spec.rb | 25 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/terraforming/resource/route_table.rb b/lib/terraforming/resource/route_table.rb index 1ef2925c..70c2abca 100644 --- a/lib/terraforming/resource/route_table.rb +++ b/lib/terraforming/resource/route_table.rb @@ -76,6 +76,7 @@ def route_attributes_of(route) attributes = { "route.#{hashcode}.cidr_block" => route.destination_cidr_block.to_s, "route.#{hashcode}.gateway_id" => route.gateway_id.to_s, + "route.#{hashcode}.nat_gateway_id" => route.nat_gateway_id.to_s, "route.#{hashcode}.instance_id" => route.instance_id.to_s, "route.#{hashcode}.network_interface_id" => route.network_interface_id.to_s, "route.#{hashcode}.vpc_peering_connection_id" => route.vpc_peering_connection_id.to_s diff --git a/lib/terraforming/template/tf/route_table.erb b/lib/terraforming/template/tf/route_table.erb index 8aa77d80..87caa73f 100644 --- a/lib/terraforming/template/tf/route_table.erb +++ b/lib/terraforming/template/tf/route_table.erb @@ -8,6 +8,9 @@ resource "aws_route_table" "<%= module_name_of(route_table) %>" { <% if route.gateway_id -%> gateway_id = "<%= route.gateway_id %>" <% end -%> +<% if route.nat_gateway_id -%> + nat_gateway_id = "<%= route.nat_gateway_id %>" +<% end -%> <% if route.instance_id -%> instance_id = "<%= route.instance_id %>" <% end -%> diff --git a/spec/lib/terraforming/resource/route_table_spec.rb b/spec/lib/terraforming/resource/route_table_spec.rb index 00335ed0..57f3f5f9 100644 --- a/spec/lib/terraforming/resource/route_table_spec.rb +++ b/spec/lib/terraforming/resource/route_table_spec.rb @@ -52,6 +52,17 @@ module Resource network_interface_id: nil, vpc_peering_connection_id: 'pcx-c56789de', state: 'active' + }, + { + destination_cidr_block: '192.168.3.0/24', + destination_prefix_list_id: nil, + gateway_id: nil, + nat_gateway_id: 'nat-0a123456789012a3b', + instance_id: nil, + instance_owner_id: nil, + network_interface_id: nil, + vpc_peering_connection_id: nil, + state: 'active' } ], associations: [ @@ -151,6 +162,11 @@ module Resource vpc_peering_connection_id = "pcx-c56789de" } + route { + cidr_block = "192.168.3.0/24" + nat_gateway_id = "nat-0a123456789012a3b" + } + propagating_vgws = ["vgw-1a4j20b"] tags { @@ -207,7 +223,14 @@ module Resource "route.2351420441.instance_id" => "", "route.2351420441.network_interface_id" => "", "route.2351420441.vpc_peering_connection_id" => "pcx-c56789de", - + + "route.3152305367.cidr_block" => "192.168.3.0/24", + "route.3152305367.gateway_id" => "", + "route.3152305367.nat_gateway_id" => "nat-0a123456789012a3b", + "route.3152305367.instance_id" => "", + "route.3152305367.network_interface_id" => "", + "route.3152305367.vpc_peering_connection_id" => "", + "propagating_vgws.#" => "1", "propagating_vgws.772379535" => "vgw-1a4j20b" } From 78aecc1677802b797439265d33313b5cba0f668c Mon Sep 17 00:00:00 2001 From: Antonio Falzarano Date: Fri, 24 Jan 2020 11:38:06 +0100 Subject: [PATCH 2/3] fix ident --- spec/lib/terraforming/resource/route_table_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/terraforming/resource/route_table_spec.rb b/spec/lib/terraforming/resource/route_table_spec.rb index 57f3f5f9..3ab39728 100644 --- a/spec/lib/terraforming/resource/route_table_spec.rb +++ b/spec/lib/terraforming/resource/route_table_spec.rb @@ -56,7 +56,7 @@ module Resource { destination_cidr_block: '192.168.3.0/24', destination_prefix_list_id: nil, - gateway_id: nil, + gateway_id: nil, nat_gateway_id: 'nat-0a123456789012a3b', instance_id: nil, instance_owner_id: nil, @@ -162,7 +162,7 @@ module Resource vpc_peering_connection_id = "pcx-c56789de" } - route { + route { cidr_block = "192.168.3.0/24" nat_gateway_id = "nat-0a123456789012a3b" } @@ -224,9 +224,9 @@ module Resource "route.2351420441.network_interface_id" => "", "route.2351420441.vpc_peering_connection_id" => "pcx-c56789de", - "route.3152305367.cidr_block" => "192.168.3.0/24", + "route.3152305367.cidr_block" => "192.168.3.0/24", "route.3152305367.gateway_id" => "", - "route.3152305367.nat_gateway_id" => "nat-0a123456789012a3b", + "route.3152305367.nat_gateway_id" => "nat-0a123456789012a3b", "route.3152305367.instance_id" => "", "route.3152305367.network_interface_id" => "", "route.3152305367.vpc_peering_connection_id" => "", From 20dd041135d58dbebc820a9307d68b4c764bb2b9 Mon Sep 17 00:00:00 2001 From: Antonio Falzarano Date: Thu, 7 Jan 2021 16:03:21 +0100 Subject: [PATCH 3/3] fix spec --- spec/lib/terraforming/resource/route_table_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/lib/terraforming/resource/route_table_spec.rb b/spec/lib/terraforming/resource/route_table_spec.rb index 57f3f5f9..d8360ab1 100644 --- a/spec/lib/terraforming/resource/route_table_spec.rb +++ b/spec/lib/terraforming/resource/route_table_spec.rb @@ -56,7 +56,7 @@ module Resource { destination_cidr_block: '192.168.3.0/24', destination_prefix_list_id: nil, - gateway_id: nil, + gateway_id: nil, nat_gateway_id: 'nat-0a123456789012a3b', instance_id: nil, instance_owner_id: nil, @@ -205,28 +205,31 @@ module Resource "tags.#" => "1", "tags.Name" => "my-route-table", - "route.#" => "3", + "route.#" => "4", "route.4066406027.cidr_block" => "0.0.0.0/0", "route.4066406027.gateway_id" => "igw-1ab2345c", + "route.4066406027.nat_gateway_id" => "", "route.4066406027.instance_id" => "", "route.4066406027.network_interface_id" => "", "route.4066406027.vpc_peering_connection_id" => "", "route.3686469914.cidr_block" => "192.168.1.0/24", "route.3686469914.gateway_id" => "", + "route.3686469914.nat_gateway_id" => "", "route.3686469914.instance_id" => "i-ec12345a", "route.3686469914.network_interface_id" => "", "route.3686469914.vpc_peering_connection_id" => "", "route.2351420441.cidr_block" => "192.168.2.0/24", "route.2351420441.gateway_id" => "", + "route.2351420441.nat_gateway_id" => "", "route.2351420441.instance_id" => "", "route.2351420441.network_interface_id" => "", "route.2351420441.vpc_peering_connection_id" => "pcx-c56789de", - "route.3152305367.cidr_block" => "192.168.3.0/24", + "route.3152305367.cidr_block" => "192.168.3.0/24", "route.3152305367.gateway_id" => "", - "route.3152305367.nat_gateway_id" => "nat-0a123456789012a3b", + "route.3152305367.nat_gateway_id" => "nat-0a123456789012a3b", "route.3152305367.instance_id" => "", "route.3152305367.network_interface_id" => "", "route.3152305367.vpc_peering_connection_id" => "", @@ -250,6 +253,7 @@ module Resource "route.#" => "1", "route.4031521715.cidr_block" => "0.0.0.0/0", "route.4031521715.gateway_id" => "vgw-2345cdef", + "route.4031521715.nat_gateway_id" => "", "route.4031521715.instance_id" => "", "route.4031521715.network_interface_id" => "", "route.4031521715.vpc_peering_connection_id" => "",