From ef877fc2cb258d969a6df9dae0a5e501a7498233 Mon Sep 17 00:00:00 2001 From: Yuri Niyazov Date: Tue, 14 Mar 2017 19:15:26 -0700 Subject: [PATCH] Fix support for EIP in EC2-Classic --- lib/terraforming/resource/eip.rb | 10 +++++--- spec/lib/terraforming/resource/eip_spec.rb | 28 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/terraforming/resource/eip.rb b/lib/terraforming/resource/eip.rb index 8064accf..54f22cd2 100644 --- a/lib/terraforming/resource/eip.rb +++ b/lib/terraforming/resource/eip.rb @@ -24,7 +24,7 @@ def tfstate attributes = { "association_id" => addr.association_id, "domain" => addr.domain, - "id" => addr.allocation_id, + "id" => vpc?(addr) ? addr.allocation_id : addr.public_ip, "instance" => addr.instance_id, "network_interface" => addr.network_interface_id, "private_ip" => addr.private_ip_address, @@ -35,7 +35,7 @@ def tfstate resources["aws_eip.#{module_name_of(addr)}"] = { "type" => "aws_eip", "primary" => { - "id" => addr.allocation_id, + "id" => vpc?(addr) ? addr.allocation_id : addr.public_ip, "attributes" => attributes } } @@ -55,7 +55,11 @@ def vpc?(addr) end def module_name_of(addr) - normalize_module_name(addr.allocation_id) + if vpc?(addr) + normalize_module_name(addr.allocation_id) + else + normalize_module_name(addr.public_ip) + end end end end diff --git a/spec/lib/terraforming/resource/eip_spec.rb b/spec/lib/terraforming/resource/eip_spec.rb index a45f80ac..0e6ec8ea 100644 --- a/spec/lib/terraforming/resource/eip_spec.rb +++ b/spec/lib/terraforming/resource/eip_spec.rb @@ -33,6 +33,16 @@ module Resource domain: "vpc", allocation_id: "eipalloc-33333333", }, + { + instance_id: "i-91112221", + public_ip: "2.2.2.4", + allocation_id: nil, + association_id: nil, + domain: "standard", + network_interface_id: nil, + network_interface_owner_id: nil, + private_ip_address: nil + } ] end @@ -57,6 +67,11 @@ module Resource vpc = true } +resource "aws_eip" "2-2-2-4" { + instance = "i-91112221" + vpc = false +} + EOS end end @@ -107,6 +122,19 @@ module Resource } } }, + "aws_eip.2-2-2-4" => { + "type" => "aws_eip", + "primary" => { + "id" => "2.2.2.4", + "attributes" => { + "domain" => "standard", + "id" => "2.2.2.4", + "instance" => "i-91112221", + "public_ip" => "2.2.2.4", + "vpc" => "false" + }, + }, + }, }) end end