hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.7k stars 9.07k forks source link

[Bug]: unexpected update of estimatedInstanceWarmup when terraform apply #32947

Open tonystaark opened 1 year ago

tonystaark commented 1 year ago

Terraform Core Version

1.3.5

AWS Provider Version

4.62.0

Affected Resource(s)

aws_autoscaling_group aws_autoscaling_policy

Expected Behavior

After updated the preconfigured autoscaling policy target tracking value in the console (from old value to new value), another run of terraform plan should show changes to update the target tracking value back to the old value. Terraform apply should perform the intended change. Nothing else should have changed.

Actual Behavior

The new run of terraform plan/update shows changes to update the target tracking value back to the old value. However after terraform apply, the estimatedInstanceWarmup is updated to zero as well. It was confirmed both on the AWS console and from the Cloudtrail.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_autoscaling_group" "this" {
  ...
  default_instance_warmup = var.default_instance_warmup
  ...
}

resource "aws_autoscaling_policy" "target_tracking_scaling" {
  ...
  policy_type            = "TargetTrackingScaling"

  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }

    target_value = 60
  }
}

Steps to Reproduce

  1. Provision resource "aws_autoscaling_group" with terraform (with the default_instance_warmup config as above) and its target tracking scaling policy.
  2. After provisioned, go to AWS console and update the target tracking value config at the scaling policy level.
  3. Reapply the terraform again.
  4. Observe that the plan shows only change to revert the target tracking value
  5. Go to AWS console and find out that not only the target tracking value was reverted, but the instance warm up was updated to 0.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

Screenshot 2023-08-10 at 5 40 43 PM
github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

skyfox675 commented 9 months ago

Confirmed with the following updates:

Terraform Core Version

1.6.3

AWS Provider Version

5.25.0

Affected Resource(s)

aws_autoscaling_policy

Actual Behavior

If the aws_autoscaling_policy is created without the estimated_instance_warmup and the autoscaling policy still has an empty/default value in the console, The new run of Terraform plan/update shows no changes, Infrastructure up to date. However after updating via the console, Terraform does successfully determine the difference between desired and actual and suggest to update.

madwolfa commented 6 months ago

I'm running into the same issue with Terraform Core Version 1.6.1 and AWS Provider Version 5.35.0. I don't even have to manually change the target value in the console first. It does this every time I'm updating the target value through Terraform vs creating a brand new policy. It has led to some nasty runaway scale-outs in our case.

New policy:

    "requestParameters": {
        "autoScalingGroupName": "atl-gen-use1-ingress-asg",
        "policyType": "TargetTrackingScaling",
        "enabled": true,
        "targetTrackingConfiguration": {
            "targetValue": 5,
            "customizedMetricSpecification": {
                "dimensions": [],
                "namespace": "VMseries-Ingress-NP",
                "metricName": "panSessionSslProxyUtilization",
                "statistic": "Average"
            },
            "disableScaleIn": false
        },
        "policyName": "atl-gen-use1-ingress-dynamic-policy"
    },

Update policy with new Target Value:

    "requestParameters": {
        "autoScalingGroupName": "atl-gen-use1-ingress-asg",
        "policyType": "TargetTrackingScaling",
        "enabled": true,
        "targetTrackingConfiguration": {
            "targetValue": 70,
            "customizedMetricSpecification": {
                "dimensions": [],
                "namespace": "VMseries-Ingress-NP",
                "metricName": "panSessionSslProxyUtilization",
                "statistic": "Average"
            },
            "disableScaleIn": false
        },
        "estimatedInstanceWarmup": 0,
        "policyName": "atl-gen-use1-ingress-dynamic-policy",
        "cooldown": 0
    },