diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 43926f103..f457e6dcd 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -111,12 +111,9 @@ func resourceAwsAutoscalingGroup() *schema.Resource { }, "termination_policies": &schema.Schema{ - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, - Computed: true, - ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, }, "wait_for_capacity_timeout": &schema.Schema{ @@ -187,9 +184,8 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) autoScalingGroupOpts.VPCZoneIdentifier = expandVpcZoneIdentifiers(v.(*schema.Set).List()) } - if v, ok := d.GetOk("termination_policies"); ok && v.(*schema.Set).Len() > 0 { - autoScalingGroupOpts.TerminationPolicies = expandStringList( - v.(*schema.Set).List()) + if v, ok := d.GetOk("termination_policies"); ok && len(v.([]interface{})) > 0 { + autoScalingGroupOpts.TerminationPolicies = expandStringList(v.([]interface{})) } 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 { return err } else { diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index c1d3c2b24..1a25c9dea 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -45,7 +45,9 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) { resource.TestCheckResourceAttr( "aws_autoscaling_group.bar", "force_delete", "true"), 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), resource.TestCheckResourceAttr( "aws_autoscaling_group.bar", "desired_capacity", "5"), + resource.TestCheckResourceAttr( + "aws_autoscaling_group.bar", "termination_policies.0", "ClosestToNextInstanceHour"), testLaunchConfigurationName("aws_autoscaling_group.bar", &lc), testAccCheckAutoscalingTags(&group.Tags, "Bar", map[string]interface{}{ "value": "bar-foo", @@ -359,7 +363,7 @@ resource "aws_autoscaling_group" "bar" { health_check_type = "ELB" desired_capacity = 4 force_delete = true - termination_policies = ["OldestInstance"] + termination_policies = ["OldestInstance","ClosestToNextInstanceHour"] launch_configuration = "${aws_launch_configuration.foobar.name}" @@ -391,6 +395,7 @@ resource "aws_autoscaling_group" "bar" { health_check_type = "ELB" desired_capacity = 5 force_delete = true + termination_policies = ["ClosestToNextInstanceHour"] launch_configuration = "${aws_launch_configuration.new.name}"