Commit 83353490 authored by Daisuke Fujita's avatar Daisuke Fujita

Generate either AZs or VPC identifiers

parent da00c05e
......@@ -21,8 +21,10 @@ module Terraforming
def tfstate
auto_scaling_groups.inject({}) do |resources, group|
vpc_zone_specified = vpc_zone_specified?(group)
attributes = {
"availability_zones.#" => group.availability_zones.length.to_s,
"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,
......@@ -35,7 +37,7 @@ module Terraforming
"name" => group.auto_scaling_group_name,
"tag.#" => group.tags.length.to_s,
"termination_policies.#" => "0",
"vpc_zone_identifier.#" => vpc_zone_identifier_of(group).length.to_s,
"vpc_zone_identifier.#" => vpc_zone_specified ? vpc_zone_identifier_of(group).length.to_s : "0",
}
resources["aws_autoscaling_group.#{module_name_of(group)}"] = {
......@@ -66,6 +68,10 @@ module Terraforming
def vpc_zone_identifier_of(group)
group.vpc_zone_identifier.split(",")
end
def vpc_zone_specified?(group)
group.vpc_zone_identifier && vpc_zone_identifier_of(group).length > 0
end
end
end
end
<% auto_scaling_groups.each do |group| -%>
<%- vpc_zone_specified = vpc_zone_specified?(group) -%>
resource "aws_autoscaling_group" "<%= module_name_of(group) %>" {
<%- if group.availability_zones && group.availability_zones.length > 0 -%>
<%- unless vpc_zone_specified -%>
availability_zones = <%= group.availability_zones.inspect %>
<%- end -%>
desired_capacity = <%= group.desired_capacity %>
......@@ -10,7 +11,7 @@ resource "aws_autoscaling_group" "<%= module_name_of(group) %>" {
max_size = <%= group.max_size %>
min_size = <%= group.min_size %>
name = "<%= group.auto_scaling_group_name %>"
<%- if group.vpc_zone_identifier && vpc_zone_identifier_of(group).length > 0 -%>
<%- if vpc_zone_specified -%>
vpc_zone_identifier = <%= vpc_zone_identifier_of(group).inspect %>
<%- end -%>
......
......@@ -63,7 +63,7 @@ module Terraforming
max_size: 4,
desired_capacity: 2,
default_cooldown: 300,
availability_zones: [],
availability_zones: ["ap-northeast-1b", "ap-northeast-1c"],
load_balancer_names: [],
health_check_type: "EC2",
health_check_grace_period: 300,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment