From 7d4064ca03a2259459ed0e8c0f891a0f9bd4f539 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 23 Oct 2014 14:58:54 -0700 Subject: [PATCH] Termination Policy Support --- .../aws/resource_aws_autoscaling_group.go | 17 +++++++++++++++++ .../aws/resource_aws_autoscaling_group_test.go | 5 ++++- .../providers/aws/r/autoscale.html.markdown | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 54c744989..5ed487d72 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -12,6 +12,7 @@ import ( ) func resourceAwsAutoscalingGroup() *schema.Resource { + fmt.Println("HELLO WORLD") return &schema.Resource{ Create: resourceAwsAutoscalingGroupCreate, Read: resourceAwsAutoscalingGroupRead, @@ -105,6 +106,17 @@ func resourceAwsAutoscalingGroup() *schema.Resource { return hashcode.String(v.(string)) }, }, + + "termination_policies": &schema.Schema{ + Type: schema.TypeSet, + Optional: true, + Computed: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: func(v interface{}) int { + return hashcode.String(v.(string)) + }, + }, }, } } @@ -148,6 +160,11 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{}) autoScalingGroupOpts.VPCZoneIdentifier = expandStringList( v.(*schema.Set).List()) } + + if v, ok := d.GetOk("termination_policies"); ok { + autoScalingGroupOpts.TerminationPolicies = expandStringList( + v.(*schema.Set).List()) + } log.Printf("[DEBUG] AutoScaling Group create configuration: %#v", autoScalingGroupOpts) _, err := autoscalingconn.CreateAutoScalingGroup(&autoScalingGroupOpts) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index 79ce2f6b7..74efd82b1 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -38,6 +38,8 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) { "aws_autoscaling_group.bar", "desired_capacity", "4"), resource.TestCheckResourceAttr( "aws_autoscaling_group.bar", "force_delete", "true"), + resource.TestCheckResourceAttr( + "aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"), ), }, @@ -202,7 +204,8 @@ resource "aws_autoscaling_group" "bar" { health_check_type = "ELB" desired_capacity = 4 force_delete = true - + termination_policies = ["OldestInstance"] + launch_configuration = "${aws_launch_configuration.foobar.name}" } ` diff --git a/website/source/docs/providers/aws/r/autoscale.html.markdown b/website/source/docs/providers/aws/r/autoscale.html.markdown index a10dec4ce..bb592a819 100644 --- a/website/source/docs/providers/aws/r/autoscale.html.markdown +++ b/website/source/docs/providers/aws/r/autoscale.html.markdown @@ -43,6 +43,7 @@ The following arguments are supported: * `load_balancers` (Optional) A list of load balancer names to add to the autoscaling group names. * `vpc_zone_identifier` (Optional) A list of subnet IDs to launch resources in. +* `termination_policies` (Optional) A list of policies to decide how the instances in the auto scale group should be terminated. ## Attributes Reference