Sha256: 9afdc4b7c555edfbab4a3703af37ecbcc46ecff29c0a62e28661b32ece4edb31

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

module Terraforming
  module Resource
    class ELB
      include Terraforming::Util

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

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

      def initialize(client)
        @client = client
      end

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

      def tfstate
        resources = load_balancers.inject({}) do |result, load_balancer|
          attributes = {
            "availability_zones.#" => load_balancer.availability_zones.length.to_s,
            "dns_name" => load_balancer.dns_name,
            "health_check.#" => "1",
            "id" => load_balancer.load_balancer_name,
            "instances.#" => load_balancer.instances.length.to_s,
            "listener.#" => load_balancer.listener_descriptions.length.to_s,
            "name" => load_balancer.load_balancer_name,
            "security_groups.#" => load_balancer.security_groups.length.to_s,
            "subnets.#" => load_balancer.subnets.length.to_s,
          }
          result["aws_elb.#{module_name_of(load_balancer)}"] = {
            "type" => "aws_elb",
            "primary" => {
              "id" => load_balancer.load_balancer_name,
              "attributes" => attributes
            }
          }

          result
        end

        generate_tfstate(resources)
      end

      def load_balancers
        @client.describe_load_balancers.load_balancer_descriptions
      end

      def module_name_of(load_balancer)
        normalize_module_name(load_balancer.load_balancer_name)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraforming-0.0.2 lib/terraforming/resource/elb.rb