Skip to content

Commit

Permalink
Add enabled attribute for aws_autoscaling_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
teraken0509 committed Jun 7, 2020
1 parent d15a5fe commit 6507c98
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aws/resource_aws_autoscaling_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func resourceAwsAutoscalingPolicy() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"estimated_instance_warmup": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -222,6 +227,7 @@ func resourceAwsAutoscalingPolicyRead(d *schema.ResourceData, meta interface{})
d.Set("adjustment_type", p.AdjustmentType)
d.Set("autoscaling_group_name", p.AutoScalingGroupName)
d.Set("cooldown", p.Cooldown)
d.Set("enabled", p.Enabled)
d.Set("estimated_instance_warmup", p.EstimatedInstanceWarmup)
d.Set("metric_aggregation_type", p.MetricAggregationType)
d.Set("policy_type", p.PolicyType)
Expand Down Expand Up @@ -303,6 +309,7 @@ func getAwsAutoscalingPutScalingPolicyInput(d *schema.ResourceData) (autoscaling
var params = autoscaling.PutScalingPolicyInput{
AutoScalingGroupName: aws.String(d.Get("autoscaling_group_name").(string)),
PolicyName: aws.String(d.Get("name").(string)),
Enabled: aws.Bool(d.Get("enabled").(bool)),
}

// get policy_type first as parameter support depends on policy type
Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_autoscaling_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestAccAWSAutoscalingPolicy_basic(t *testing.T) {
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "name", name+"-foobar_simple"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "scaling_adjustment", "2"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "autoscaling_group_name", name),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "enabled", "true"),
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_step", &policy),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "adjustment_type", "ChangeInCapacity"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "policy_type", "StepScaling"),
Expand Down Expand Up @@ -77,6 +78,7 @@ func TestAccAWSAutoscalingPolicy_basic(t *testing.T) {
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_simple", &policy),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "policy_type", "SimpleScaling"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "cooldown", "30"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "enabled", "false"),
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_step", &policy),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "policy_type", "StepScaling"),
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "estimated_instance_warmup", "20"),
Expand Down Expand Up @@ -421,6 +423,7 @@ resource "aws_autoscaling_policy" "foobar_simple" {
policy_type = "SimpleScaling"
scaling_adjustment = 2
autoscaling_group_name = "${aws_autoscaling_group.test.name}"
enabled = false
}
resource "aws_autoscaling_policy" "foobar_step" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/autoscaling_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The following arguments are supported:
* `adjustment_type` - (Optional) Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity`, and `PercentChangeInCapacity`.
* `policy_type` - (Optional) The policy type, either "SimpleScaling", "StepScaling" or "TargetTrackingScaling". If this value isn't provided, AWS will default to "SimpleScaling."
* `estimated_instance_warmup` - (Optional) The estimated time, in seconds, until a newly launched instance will contribute CloudWatch metrics. Without a value, AWS will default to the group's specified cooldown period.
* `enabled` - (Optional, Default: true) Indicates whether the scaling policy is enabled or disabled.

The following arguments are only available to "SimpleScaling" type policies:

Expand Down

0 comments on commit 6507c98

Please sign in to comment.