skip to Main Content

More specifically, adjustment_type keeps getting (seemingly) updated on each terraform plan. Why is that and can it be avoided?

Terraform will perform the following actions:

  # aws_autoscaling_policy.this will be updated in-place
  ~ resource "aws_autoscaling_policy" "this" {
      + adjustment_type           = "ChangeInCapacity"

Here’s autoscaling policy definition:

resource "aws_autoscaling_policy" "this" {
  name                   = var.service_name # Same between `terraform` invocations.
  autoscaling_group_name = aws_autoscaling_group.this.name
  adjustment_type        = "ChangeInCapacity"
  policy_type            = "TargetTrackingScaling"
  # ASG merely serves as an EC2-ready-to-be-made-scalable, hence `false`.
  enabled = false
  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }
    target_value = 99.0
  }
}
  • terraform 1.3.1
  • terragrunt 0.40.2

2

Answers


  1. From the info in question there is no reason why it would change. Its possibile that you are experiencing "ghost" changes, which are known, long lasting TF issue, e.g. here. You can try using ignore_changes:

    resource "aws_autoscaling_policy" "this" {
      name                   = var.service_name # Same between `terraform` invocations.
      autoscaling_group_name = aws_autoscaling_group.this.name
      adjustment_type        = "ChangeInCapacity"
      policy_type            = "TargetTrackingScaling"
      # ASG merely serves as an EC2-ready-to-be-made-scalable, hence `false`.
      enabled = false
      target_tracking_configuration {
        predefined_metric_specification {
          predefined_metric_type = "ASGAverageCPUUtilization"
        }
        target_value = 99.0
      }
    
      lifecycle {
        ignore_changes = [
           adjustment_type
        ]
      }
    
    }
    
    Login or Signup to reply.
  2. The hashicorp/aws provider uses a single resource type aws_autoscaling_policy to represent both Target Tracking Scaling Policies and Simple/Step Scaling Policies. Unfortunately each of these policy types expects a different subset of arguments, and (as discussed in provider bug #18853) there are some missing validation rules to catch when you use an argument that isn’t appropriate for your selected type.

    You are using policy_type = "TargetTrackingScaling", but Scaling Adjustment Types are for step/simple scaling policies. Therefore I believe the AWS API is silently ignoring your adjustment_type value when creating/updating. When the AWS provider reads your policy back from the remote API during the refresh step, the API indicates that adjustment_type isn’t set and so the AWS provider thinks it’s changed outside of Terraform.

    The best fix here would be for the provider to return an error if you use an argument that isn’t appropriate for your policy_type, but in the meantime I suspect you can make this problem go away by leaving adjustment_type unset in your configuration, which should then make the desired state described by your configuration match the actual state of the remote object.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search