Class: Terraforming::Resource::AutoScalingGroup

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#apply_template, #name_from_tag, #normalize_module_name, #prettify_policy, #template_path

Constructor Details

#initialize(client) ⇒ AutoScalingGroup

Returns a new instance of AutoScalingGroup.



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

def initialize(client)
  @client = client
end

Class Method Details

.tf(client: Aws::AutoScaling::Client.new) ⇒ Object



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

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

.tfstate(client: Aws::AutoScaling::Client.new) ⇒ Object



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

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

Instance Method Details

#tfObject



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

def tf
  apply_template(@client, "tf/auto_scaling_group")
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
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/terraforming/resource/auto_scaling_group.rb', line 22

def tfstate
  auto_scaling_groups.inject({}) do |resources, group|
    vpc_zone_specified = vpc_zone_specified?(group)

    attributes = {
      "availability_zones.#" => vpc_zone_specified ? "0" : group.availability_zones.length.to_s,
      "default_cooldown" => "300",
      "desired_capacity" => group.desired_capacity.to_s,
      "health_check_grace_period" => group.health_check_grace_period.to_s,
      "health_check_type" => group.health_check_type,
      "id" => group.auto_scaling_group_name,
      "launch_configuration" => group.launch_configuration_name,
      "load_balancers.#" => "0",
      "max_size" => group.max_size.to_s,
      "min_size" => group.min_size.to_s,
      "name" => group.auto_scaling_group_name,
      "tag.#" => group.tags.length.to_s,
      "termination_policies.#" => "0",
      "vpc_zone_identifier.#" => vpc_zone_specified ? vpc_zone_identifier_of(group).length.to_s : "0",
    }

    group.tags.each do |tag|
      hashcode = tag_hashcode_of(tag)
      attributes.merge!({
        "tag.#{hashcode}.key" => tag.key,
        "tag.#{hashcode}.propagate_at_launch" => tag.propagate_at_launch.to_s,
        "tag.#{hashcode}.value" => tag.value,
      })
    end

    resources["aws_autoscaling_group.#{module_name_of(group)}"] = {
      "type" => "aws_autoscaling_group",
      "primary" => {
        "id" => group.auto_scaling_group_name,
        "attributes" => attributes,
        "meta" => {
          "schema_version" => "1"
        }
      }
    }

    resources
  end
end