Merge pull request #2890 from pforman/asg-termination
Update AWS ASG termination policy code and tests
This commit is contained in:
commit
3ce656b007
|
@ -111,12 +111,9 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
"termination_policies": &schema.Schema{
|
"termination_policies": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
|
||||||
ForceNew: true,
|
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: schema.HashString,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"wait_for_capacity_timeout": &schema.Schema{
|
"wait_for_capacity_timeout": &schema.Schema{
|
||||||
|
@ -187,9 +184,8 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
autoScalingGroupOpts.VPCZoneIdentifier = expandVpcZoneIdentifiers(v.(*schema.Set).List())
|
autoScalingGroupOpts.VPCZoneIdentifier = expandVpcZoneIdentifiers(v.(*schema.Set).List())
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("termination_policies"); ok && v.(*schema.Set).Len() > 0 {
|
if v, ok := d.GetOk("termination_policies"); ok && len(v.([]interface{})) > 0 {
|
||||||
autoScalingGroupOpts.TerminationPolicies = expandStringList(
|
autoScalingGroupOpts.TerminationPolicies = expandStringList(v.([]interface{}))
|
||||||
v.(*schema.Set).List())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts)
|
log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts)
|
||||||
|
@ -280,6 +276,24 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("termination_policies") {
|
||||||
|
// If the termination policy is set to null, we need to explicitly set
|
||||||
|
// it back to "Default", or the API won't reset it for us.
|
||||||
|
// This means GetOk() will fail us on the zero check.
|
||||||
|
v := d.Get("termination_policies")
|
||||||
|
if len(v.([]interface{})) > 0 {
|
||||||
|
opts.TerminationPolicies = expandStringList(v.([]interface{}))
|
||||||
|
} else {
|
||||||
|
// Policies is a slice of string pointers, so build one.
|
||||||
|
// Maybe there's a better idiom for this?
|
||||||
|
log.Printf("[DEBUG] Explictly setting null termination policy to 'Default'")
|
||||||
|
pol := "Default"
|
||||||
|
s := make([]*string, 1, 1)
|
||||||
|
s[0] = &pol
|
||||||
|
opts.TerminationPolicies = s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := setAutoscalingTags(conn, d); err != nil {
|
if err := setAutoscalingTags(conn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -45,7 +45,9 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_autoscaling_group.bar", "force_delete", "true"),
|
"aws_autoscaling_group.bar", "force_delete", "true"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_autoscaling_group.bar", "termination_policies.912102603", "OldestInstance"),
|
"aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.1", "ClosestToNextInstanceHour"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -56,6 +58,8 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
||||||
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.new", &lc),
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.new", &lc),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_autoscaling_group.bar", "desired_capacity", "5"),
|
"aws_autoscaling_group.bar", "desired_capacity", "5"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_autoscaling_group.bar", "termination_policies.0", "ClosestToNextInstanceHour"),
|
||||||
testLaunchConfigurationName("aws_autoscaling_group.bar", &lc),
|
testLaunchConfigurationName("aws_autoscaling_group.bar", &lc),
|
||||||
testAccCheckAutoscalingTags(&group.Tags, "Bar", map[string]interface{}{
|
testAccCheckAutoscalingTags(&group.Tags, "Bar", map[string]interface{}{
|
||||||
"value": "bar-foo",
|
"value": "bar-foo",
|
||||||
|
@ -359,7 +363,7 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
health_check_type = "ELB"
|
health_check_type = "ELB"
|
||||||
desired_capacity = 4
|
desired_capacity = 4
|
||||||
force_delete = true
|
force_delete = true
|
||||||
termination_policies = ["OldestInstance"]
|
termination_policies = ["OldestInstance","ClosestToNextInstanceHour"]
|
||||||
|
|
||||||
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
||||||
|
|
||||||
|
@ -391,6 +395,7 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
health_check_type = "ELB"
|
health_check_type = "ELB"
|
||||||
desired_capacity = 5
|
desired_capacity = 5
|
||||||
force_delete = true
|
force_delete = true
|
||||||
|
termination_policies = ["ClosestToNextInstanceHour"]
|
||||||
|
|
||||||
launch_configuration = "${aws_launch_configuration.new.name}"
|
launch_configuration = "${aws_launch_configuration.new.name}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue