繁体   English   中英

如何避免 Terraform 重复原地更新 AWS 自动伸缩策略?

[英]How to avoid Terraform's repeated in-place updates of AWS autoscaling policy?

更具体地说, adjustment_type在每个terraform plan上不断(看似)更新。 为什么会这样,可以避免吗?

Terraform will perform the following actions:

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

这是自动缩放策略定义:

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
  • 地龙 0.40.2

从有问题的信息来看,没有理由改变它。 您可能正在经历“幽灵”变化,这是已知的、长期存在的 TF 问题,例如此处 您可以尝试使用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
    ]
  }

}

hashicorp/aws提供程序使用单一资源类型aws_autoscaling_policy来表示Target Tracking Scaling PoliciesSimple/Step Scaling Policies 不幸的是,这些策略类型中的每一个都需要 arguments 的不同子集,并且(如提供程序错误 #18853中所讨论的)当您使用不适合您所选类型的参数时,需要捕获一些缺少的验证规则。

您正在使用policy_type = "TargetTrackingScaling" ,但缩放调整类型适用于步进/简单缩放策略。 因此,我相信 AWS API 在创建/更新时会默默地忽略您的adjustment_type值。 当 AWS 提供商在刷新步骤期间从远程 API 读回您的策略时,API 表示未设置adjustment_type ,因此 AWS 提供商认为它在 Terraform 之外发生了更改。

如果您使用不适合您的policy_type的参数,这里最好的解决方法是提供者返回一个错误,但与此同时我怀疑您可以通过在您的配置中保留adjustment_type未设置来解决这个问题 go,这应该然后使您的配置描述的所需 state 与远程 object 的实际 state 匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM