Sha256: de1e24a907d139db2d730c2a1750c1bae17cbdf63481e472978819ade26a0395

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

module Terraforming
  module Resource
    class EIP
      include Terraforming::Util

      def self.tf(client: Aws::EC2::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::EC2::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/eip")
      end

      def tfstate
        eips.inject({}) do |resources, addr|
          attributes = {
            "association_id" => addr.association_id,
            "domain" => addr.domain,
            "id" => addr.allocation_id,
            "instance" => addr.instance_id,
            "network_interface" => addr.network_interface_id,
            "private_ip" => addr.private_ip_address,
            "public_ip" => addr.public_ip,
            "vpc" => is_vpc?(addr).to_s,
          }
          attributes.delete_if{|k, v| v.nil?}
          resources["aws_eip.#{addr.allocation_id}"] = {
            "type" => "aws_eip",
            "primary" => {
              "id" => addr.allocation_id,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def eips
        @client.describe_addresses.addresses
      end

      def is_vpc?(addr)
        addr.domain.eql?("vpc")
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
terraforming-0.9.1 lib/terraforming/resource/eip.rb
terraforming-0.9.0 lib/terraforming/resource/eip.rb
terraforming-0.8.0 lib/terraforming/resource/eip.rb
terraforming-0.7.0 lib/terraforming/resource/eip.rb
terraforming-0.6.2 lib/terraforming/resource/eip.rb
terraforming-0.6.1 lib/terraforming/resource/eip.rb
terraforming-0.6.0 lib/terraforming/resource/eip.rb
terraforming-0.5.0 lib/terraforming/resource/eip.rb
terraforming-0.4.0 lib/terraforming/resource/eip.rb
terraforming-0.3.2 lib/terraforming/resource/eip.rb
terraforming-0.3.1 lib/terraforming/resource/eip.rb
terraforming-0.3.0 lib/terraforming/resource/eip.rb