Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: aws_autoscaling_policy fails when setting scaling_adjustment to 0 for SimpleScaling #8893

Merged
merged 3 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion builtin/providers/aws/resource_aws_autoscaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down
59 changes: 59 additions & 0 deletions builtin/providers/aws/resource_aws_autoscaling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}