Terraform-provider-aws: aws_autoscaling_policy step_adjustment values are being multiplied by 2-3x on apply?

Created on 14 Dec 2017  ยท  3Comments  ยท  Source: hashicorp/terraform-provider-aws

Hi all,

Whenever I create a scaling policy using the step features the action upper and lower bound definitions are always created on AWS with different values to the Terraform plan values.

Generally the values created are always double of what is specified in Terraform configuration. However this can change.. example if you divide the specified values by 2 in Terraform, the actual values created on AWS are triple the Terraform calculated values..

I have spent a long time trying different values and structures etc and I am stumped by this one, I believe there has to be a bug causing this.

Surely I can't be the only one experiencing this!

Please let me know if I am doing anything wrong.

Thanks!
Tully Dwyer

Terraform Version

Terraform v0.11.1

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_autoscaling_policy (step_adjustment)

Terraform Configuration Files

resource "aws_autoscaling_policy" "asg_policy_step" {
  adjustment_type        = "PercentChangeInCapacity"
  autoscaling_group_name = "webservers"
  name                   = "scale_up"
  policy_type            = "StepScaling"

  # Step 1 (Normal)
  step_adjustment {
    scaling_adjustment          = 15
    metric_interval_lower_bound = 70
    metric_interval_upper_bound = 85
  }

  # Step 2 (Spike)
  step_adjustment {
    scaling_adjustment          = 30
    metric_interval_lower_bound = 85
  }
}

resource "aws_cloudwatch_metric_alarm" "monitor_asg_cpu" {
  actions_enabled     = true
  alarm_actions       = ["${aws_autoscaling_policy.asg_policy_step.arn}"]
  alarm_name          = "asg-cpu-alarm"
  comparison_operator = "GreaterThanOrEqualToThreshold"

  dimensions = {
    "AutoScalingGroupName" = "webservers"
  }

  evaluation_periods = "1"
  metric_name        = "CPUUtilization"
  namespace          = "AWS/EC2"
  period             = "60"
  statistic          = "Average"
  threshold          = "70"
}

Debug Output

Output of Terraform apply:

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_autoscaling_policy.asg_policy_step: Creating...
  adjustment_type:                                        "" => "PercentChangeInCapacity"
  arn:                                                    "" => "<computed>"
  autoscaling_group_name:                                 "" => "webservers"
  metric_aggregation_type:                                "" => "<computed>"
  name:                                                   "" => "scale_up"
  policy_type:                                            "" => "StepScaling"
  step_adjustment.#:                                      "" => "2"
  step_adjustment.2085151041.metric_interval_lower_bound: "" => "70"
  step_adjustment.2085151041.metric_interval_upper_bound: "" => "85"
  step_adjustment.2085151041.scaling_adjustment:          "" => "15"
  step_adjustment.2143956991.metric_interval_lower_bound: "" => "85"
  step_adjustment.2143956991.metric_interval_upper_bound: "" => ""
  step_adjustment.2143956991.scaling_adjustment:          "" => "30"
aws_autoscaling_policy.asg_policy_step: Creation complete after 1s (ID: scale_up)
aws_cloudwatch_metric_alarm.monitor_asg_cpu: Creating...
  actions_enabled:                       "" => "true"
  alarm_actions.#:                       "" => "1"
  alarm_actions.2851778316:              "" => "arn:aws:autoscaling:ap-southeast-2:xxxxx:scalingPolicy:f1effa5b-b517-4839-bfd2-a85a6444e74c:autoScalingGroupName/webservers:policyName/scale_up"
  alarm_name:                            "" => "asg-cpu-alarm"
  comparison_operator:                   "" => "GreaterThanOrEqualToThreshold"
  dimensions.%:                          "" => "1"
  dimensions.AutoScalingGroupName:       "" => "webservers"
  evaluate_low_sample_count_percentiles: "" => "<computed>"
  evaluation_periods:                    "" => "1"
  metric_name:                           "" => "CPUUtilization"
  namespace:                             "" => "AWS/EC2"
  period:                                "" => "60"
  statistic:                             "" => "Average"
  threshold:                             "" => "70"
  treat_missing_data:                    "" => "missing"
aws_cloudwatch_metric_alarm.monitor_asg_cpu: Creation complete after 1s (ID: asg-cpu-alarm)

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Please provider a link to a GitHub Gist containing the complete debug output:
Debug output of Terraform apply:
https://gist.github.com/tullydwyer/72662ad1ef7c327d21bceb619f08192c

Expected Behavior

It should have created the step_adjustment's with the values specified. E.g.

Steps:
Add | 15 | percent of group | when | 70 | <= | CPUUtilization | < | 85ย 
Add | 30 | percent of group | when | 85 | <= | CPUUtilization | < | +infinity

Actual Behavior

It creates the step_adjustment's with the upper and lower bounds doubled every time. E.g.

Steps:
Add | 15 | percent of group | when | 140 | <= | CPUUtilization | < | 155ย 
Add | 30 | percent of group | when | 155 | <= | CPUUtilization | < | +infinity

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Copy the definition and and update autoscaling_group_name to an existing ASG.
  2. terraform apply
  3. Check values in AWS console.

Important Factoids

  • Fresh setup.
  • If I set the values to be divided by 2 aka "metric_interval_lower_bound = "${70 / 2}"" the values are tripled on AWS?? E.g. "${70 / 2}" comes out to be 105.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here?

  • #1690
servicautoscaling

Most helpful comment

Did some rubber duck debugging today and got the answer.

Read carefully! - "The lower bound for the _difference_ between the alarm threshold and the CloudWatch metric." (very different to the console creation process) see: https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html

What the values should have been to achieve the scaling policy:

resource "aws_autoscaling_policy" "asg_policy_step" {
  adjustment_type        = "PercentChangeInCapacity"
  autoscaling_group_name = "webservers"
  name                   = "scale_up"
  policy_type            = "StepScaling"

  # Step 1 (Normal)
  step_adjustment {
    scaling_adjustment          = 15
    metric_interval_lower_bound = 0 # Zero over CW threshold
    metric_interval_upper_bound = 15 # 15 over CW threshold (70 + 15 = 85)
  }

  # Step 2 (Spike)
  step_adjustment {
    scaling_adjustment          = 30
    metric_interval_lower_bound = 15 # 15 over CW threshold (70 + 15 = 85)
  }
}

All 3 comments

Did some rubber duck debugging today and got the answer.

Read carefully! - "The lower bound for the _difference_ between the alarm threshold and the CloudWatch metric." (very different to the console creation process) see: https://www.terraform.io/docs/providers/aws/r/autoscaling_policy.html

What the values should have been to achieve the scaling policy:

resource "aws_autoscaling_policy" "asg_policy_step" {
  adjustment_type        = "PercentChangeInCapacity"
  autoscaling_group_name = "webservers"
  name                   = "scale_up"
  policy_type            = "StepScaling"

  # Step 1 (Normal)
  step_adjustment {
    scaling_adjustment          = 15
    metric_interval_lower_bound = 0 # Zero over CW threshold
    metric_interval_upper_bound = 15 # 15 over CW threshold (70 + 15 = 85)
  }

  # Step 2 (Spike)
  step_adjustment {
    scaling_adjustment          = 30
    metric_interval_lower_bound = 15 # 15 over CW threshold (70 + 15 = 85)
  }
}

@tullydwyer Thanks for your message, this got me confused for longer than I would like to admit.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings