class Terraforming::Resource::EIP

Public Class Methods

new(client) click to toggle source
# File lib/terraforming/resource/eip.rb, line 14
def initialize(client)
  @client = client
end
tf(client: Aws::EC2::Client.new) click to toggle source
# File lib/terraforming/resource/eip.rb, line 6
def self.tf(client: Aws::EC2::Client.new)
  self.new(client).tf
end
tfstate(client: Aws::EC2::Client.new) click to toggle source
# File lib/terraforming/resource/eip.rb, line 10
def self.tfstate(client: Aws::EC2::Client.new)
  self.new(client).tfstate
end

Public Instance Methods

tf() click to toggle source
# File lib/terraforming/resource/eip.rb, line 18
def tf
  apply_template(@client, "tf/eip")
end
tfstate() click to toggle source
# File lib/terraforming/resource/eip.rb, line 22
def tfstate
  eips.inject({}) do |resources, addr|
    attributes = {
      "association_id" => addr.association_id,
      "domain" => addr.domain,
      "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,
      "public_ip" => addr.public_ip,
      "vpc" => vpc?(addr).to_s,
    }
    attributes.delete_if { |_k, v| v.nil? }
    resources["aws_eip.#{module_name_of(addr)}"] = {
      "type" => "aws_eip",
      "primary" => {
        "id" => vpc?(addr) ? addr.allocation_id : addr.public_ip,
        "attributes" => attributes
      }
    }

    resources
  end
end

Private Instance Methods

eips() click to toggle source
# File lib/terraforming/resource/eip.rb, line 49
def eips
  @client.describe_addresses.map(&:addresses).flatten
end
module_name_of(addr) click to toggle source
# File lib/terraforming/resource/eip.rb, line 57
def module_name_of(addr)
  if vpc?(addr)
    normalize_module_name(addr.allocation_id)
  else
    normalize_module_name(addr.public_ip)
  end
end
vpc?(addr) click to toggle source
# File lib/terraforming/resource/eip.rb, line 53
def vpc?(addr)
  addr.domain.eql?("vpc")
end