[英]How to avoid Terraform's repeated in-place updates of AWS autoscaling policy?
More specifically, adjustment_type
keeps getting (seemingly) updated on each terraform plan
.更具体地说,
adjustment_type
在每个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
}
}
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, eg here .
您可能正在经历“幽灵”变化,这是已知的、长期存在的 TF 问题,例如此处。 You can try using ignore_changes :
您可以尝试使用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
]
}
}
The hashicorp/aws
provider uses a single resource type aws_autoscaling_policy
to represent both Target Tracking Scaling Policies and Simple/Step Scaling Policies . hashicorp/aws
提供程序使用单一资源类型aws_autoscaling_policy
来表示Target Tracking Scaling Policies和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.不幸的是,这些策略类型中的每一个都需要 arguments 的不同子集,并且(如提供程序错误 #18853中所讨论的)当您使用不适合您所选类型的参数时,需要捕获一些缺少的验证规则。
You are using policy_type = "TargetTrackingScaling"
, but Scaling Adjustment Types are for step/simple scaling policies.您正在使用
policy_type = "TargetTrackingScaling"
,但缩放调整类型适用于步进/简单缩放策略。 Therefore I believe the AWS API is silently ignoring your adjustment_type
value when creating/updating.因此,我相信 AWS API 在创建/更新时会默默地忽略您的
adjustment_type
值。 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.当 AWS 提供商在刷新步骤期间从远程 API 读回您的策略时,API 表示未设置
adjustment_type
,因此 AWS 提供商认为它在 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.如果您使用不适合您的
policy_type
的参数,这里最好的解决方法是提供者返回一个错误,但与此同时我怀疑您可以通过在您的配置中保留adjustment_type
未设置来解决这个问题 go,这应该然后使您的配置描述的所需 state 与远程 object 的实际 state 匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.