From 5eccbba606fea722caa34028e41ecfbd3aee3818 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Oct 2014 16:25:23 -0700 Subject: [PATCH] providers/aws: support non-destructive update of desired_capacity for ASG --- .../aws/resource_aws_autoscaling_group.go | 6 +++- .../resource_aws_autoscaling_group_test.go | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 545160c970..a5f4a2de7d 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -33,7 +33,6 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Type: schema.TypeInt, Optional: true, Computed: true, - ForceNew: true, }, "min_size": &schema.Schema{ @@ -168,6 +167,11 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{}) Name: d.Id(), } + if d.HasChange("desired_capacity") { + opts.DesiredCapacity = d.Get("desired_capacity").(int) + opts.SetDesiredCapacity = true + } + if d.HasChange("min_size") { opts.MinSize = d.Get("min_size").(int) opts.SetMinSize = true diff --git a/builtin/providers/aws/resource_aws_autoscaling_group_test.go b/builtin/providers/aws/resource_aws_autoscaling_group_test.go index 3522c6add3..0e63c9d44d 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group_test.go @@ -40,6 +40,15 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) { "aws_autoscaling_group.bar", "force_delete", "true"), ), }, + + resource.TestStep{ + Config: testAccAWSAutoScalingGroupConfigUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group), + resource.TestCheckResourceAttr( + "aws_autoscaling_group.bar", "desired_capacity", "5"), + ), + }, }, }) } @@ -198,6 +207,27 @@ resource "aws_autoscaling_group" "bar" { } ` +const testAccAWSAutoScalingGroupConfigUpdate = ` +resource "aws_launch_configuration" "foobar" { + name = "foobarautoscaling-terraform-test" + image_id = "ami-21f78e11" + instance_type = "t1.micro" +} + +resource "aws_autoscaling_group" "bar" { + availability_zones = ["us-west-2a"] + name = "foobar3-terraform-test" + max_size = 5 + min_size = 2 + health_check_grace_period = 300 + health_check_type = "ELB" + desired_capacity = 5 + force_delete = true + + launch_configuration = "${aws_launch_configuration.foobar.name}" +} +` + const testAccAWSAutoScalingGroupConfigWithLoadBalancer = ` resource "aws_elb" "bar" { name = "foobar-terraform-test"