Merge pull request #8893 from dennis-bsi/fix-asg-policy-to-0

provider/aws: aws_autoscaling_policy fails when setting scaling_adjustment to 0 for SimpleScaling
This commit is contained in:
Clint 2016-10-21 16:17:16 -05:00 committed by GitHub
commit dcbcde4b82
2 changed files with 61 additions and 1 deletions

View File

@ -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)))
}

View File

@ -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)
}