always set scaling_adjustment when policy_type = SimpleScaling

This commit is contained in:
Dennis Webb 2016-09-16 21:00:57 -05:00
parent 19e8932a92
commit 925fc116a8
2 changed files with 64 additions and 2 deletions

View File

@ -218,8 +218,11 @@ func getAwsAutoscalingPutScalingPolicyInput(d *schema.ResourceData) (autoscaling
params.PolicyType = aws.String(v.(string))
}
if v, ok := d.GetOk("scaling_adjustment"); ok {
params.ScalingAdjustment = aws.Int64(int64(v.(int)))
//if policy_type=="SimpleScaling" then scaling_adjustment is required and 0 is allowed
if *params.PolicyType == "SimpleScaling" {
params.ScalingAdjustment = aws.Int64(int64(d.Get("scaling_adjustment").(int)))
} else if v, ok := d.GetOk("scaling_adjustment"); ok {
params.EstimatedInstanceWarmup = aws.Int64(int64(v.(int)))
}
if v, ok := d.GetOk("step_adjustment"); ok {

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