Class: Terraforming::Resource::ELB

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/terraforming/resource/elb.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #generate_tfstate, #name_from_tag, #normalize_module_name, #template_path

Constructor Details

#initialize(client) ⇒ ELB

Returns a new instance of ELB.



14
15
16
# File 'lib/terraforming/resource/elb.rb', line 14

def initialize(client)
  @client = client
end

Class Method Details

.tf(client = Aws::ElasticLoadBalancing::Client.new) ⇒ Object



6
7
8
# File 'lib/terraforming/resource/elb.rb', line 6

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

.tfstate(client = Aws::ElasticLoadBalancing::Client.new) ⇒ Object



10
11
12
# File 'lib/terraforming/resource/elb.rb', line 10

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

Instance Method Details

#load_balancer_attributes_of(load_balancer) ⇒ Object



59
60
61
# File 'lib/terraforming/resource/elb.rb', line 59

def load_balancer_attributes_of(load_balancer)
  @client.describe_load_balancer_attributes(load_balancer_name: load_balancer.load_balancer_name).load_balancer_attributes
end

#load_balancersObject



55
56
57
# File 'lib/terraforming/resource/elb.rb', line 55

def load_balancers
  @client.describe_load_balancers.load_balancer_descriptions
end

#module_name_of(load_balancer) ⇒ Object



63
64
65
# File 'lib/terraforming/resource/elb.rb', line 63

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

#tfObject



18
19
20
# File 'lib/terraforming/resource/elb.rb', line 18

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

#tfstateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/terraforming/resource/elb.rb', line 22

def tfstate
  resources = load_balancers.inject({}) do |result, load_balancer|
    load_balancer_attributes = load_balancer_attributes_of(load_balancer)
    attributes = {
      "availability_zones.#" => load_balancer.availability_zones.length.to_s,
      "connection_draining" => load_balancer_attributes.connection_draining.enabled.to_s,
      "connection_draining_timeout" => load_balancer_attributes.connection_draining.timeout.to_s,
      "cross_zone_load_balancing" => load_balancer_attributes.cross_zone_load_balancing.enabled.to_s,
      "dns_name" => load_balancer.dns_name,
      "health_check.#" => "1",
      "id" => load_balancer.load_balancer_name,
      "idle_timeout" => load_balancer_attributes.connection_settings.idle_timeout.to_s,
      "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,
      "source_security_group" => load_balancer.source_security_group.group_name,
      "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