diff --git a/builtin/providers/aws/resource_aws_autoscaling_policy.go b/builtin/providers/aws/resource_aws_autoscaling_policy.go index ea7b2bb06..3c91bd32b 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_policy.go +++ b/builtin/providers/aws/resource_aws_autoscaling_policy.go @@ -218,7 +218,8 @@ func getAwsAutoscalingPutScalingPolicyInput(d *schema.ResourceData) (autoscaling params.PolicyType = aws.String(v.(string)) } - if v, ok := d.GetOk("scaling_adjustment"); ok { + //if policy_type=="SimpleScaling" then scaling_adjustment is required and 0 is allowed + if v, ok := d.GetOk("scaling_adjustment"); ok || *params.PolicyType == "SimpleScaling" { params.ScalingAdjustment = aws.Int64(int64(v.(int))) } diff --git a/builtin/providers/aws/resource_aws_autoscaling_policy_test.go b/builtin/providers/aws/resource_aws_autoscaling_policy_test.go index d2d2f11fd..c7f5fbcaf 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_policy_test.go +++ b/builtin/providers/aws/resource_aws_autoscaling_policy_test.go @@ -316,3 +316,62 @@ resource "aws_autoscaling_policy" "foobar_simple" { } `, name, name, name) } + +func TestAccAWSAutoscalingPolicy_SimpleScalingStepAdjustment(t *testing.T) { + var policy autoscaling.ScalingPolicy + + name := acctest.RandString(5) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAutoscalingPolicyDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSAutoscalingPolicyConfig_SimpleScalingStepAdjustment(name), + Check: resource.ComposeTestCheckFunc( + testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_simple", &policy), + resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "adjustment_type", "ExactCapacity"), + resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "scaling_adjustment", "0"), + ), + }, + }, + }) +} + +func testAccAWSAutoscalingPolicyConfig_SimpleScalingStepAdjustment(name string) string { + return fmt.Sprintf(` +resource "aws_launch_configuration" "foobar" { + name = "tf-test-%s" + image_id = "ami-21f78e11" + instance_type = "t1.micro" +} + +resource "aws_autoscaling_group" "foobar" { + availability_zones = ["us-west-2a"] + name = "terraform-test-%s" + max_size = 5 + min_size = 0 + health_check_grace_period = 300 + health_check_type = "ELB" + force_delete = true + termination_policies = ["OldestInstance"] + launch_configuration = "${aws_launch_configuration.foobar.name}" + + tag { + key = "Foo" + value = "foo-bar" + propagate_at_launch = true + } +} + +resource "aws_autoscaling_policy" "foobar_simple" { + name = "foobar_simple_%s" + adjustment_type = "ExactCapacity" + cooldown = 300 + policy_type = "SimpleScaling" + scaling_adjustment = 0 + autoscaling_group_name = "${aws_autoscaling_group.foobar.name}" +} +`, name, name, name) +}