如何避免"Objects have changed outside of Terraform"?
How to avoid "Objects have changed outside of Terraform"?
最近将我的 Terraform 项目升级到 AWS 提供商 3.74.0 和 TF 1.1.4(从更旧的版本)。
我突然收到此自动缩放计划报告外部更改:
resource "aws_autoscaling_schedule" "api-svc-tst-down-schedule" {
scheduled_action_name = "api-svc-tst-down-schedule"
min_size = 0
max_size = 1
desired_capacity = 0
// Minute Hour DayOfMonth Month DayOfWeek
recurrence = "0 13 * * *"
autoscaling_group_name = aws_autoscaling_group.api-svc-tst-asg.name
lifecycle {
ignore_changes = [start_time]
}
}
plan
命令正在报告:
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply":
# aws_autoscaling_schedule.api-svc-tst-down-schedule has changed
~ resource "aws_autoscaling_schedule" "api-svc-tst-down-schedule" {
id = "api-svc-tst-down-schedule"
~ start_time = "2022-01-31T13:00:00Z" -> "2022-02-01T13:00:00Z"
# (7 unchanged attributes hidden)
}
如果我 apply
计划,TF 似乎不会更改 ASG(我假设它只是更新其状态文件)并且通知会在第二天消失。
我注意到 AWS 控制台确实显示 Scheduled action
有一个 Start time
,这似乎是由 AWS 设置的。
我尝试将 start_time
添加到 ignored_changes
但它似乎没有什么不同,仍然报告为外部更改。
这是 Terraform 的已知问题吗(我通过谷歌搜索没有看到任何内容)?
如何防止 TF 被标记为外部更改?
编辑:我也尝试按照评论中的建议设置 start_time
属性。但是第二天检测到的更改警告又回来了。
编辑 2:我也尝试通过 Terraform 删除并重新添加资源,但第二天它仍然被标记为已更改。
这种不良行为是 Terraform version 0.15.4 中引入的有意更改。
目前无法避免。唯一的解决方法是必须教育所有团队成员(和工具)忽略“预期漂移”。
请注意,这种“预期漂移”行为不仅限于 aws_autoscaling_schedule
资源,甚至不限于 AWS 提供商。对于云供应商在创建资源后更新属性的任何资源,该问题发生在许多不同的 platforms/types 上。
许多资源会在创建后立即报告漂移 - 通常您可以通过立即执行 apply
或 refresh
来更新 TF 状态来摆脱报告,只要 AWS 没有如果不更改这些属性,您将不会看到报告为已更改的资源。
其他资源属性(如 aws_autoscaling_schedule.start_time
)由云供应商定期更新。每当您 运行 plan
.
时,这些类型的资源将间歇性地报告“对象已在 Terraform 之外更改”
有一个锁定未解决问题需要跟踪:https://github.com/hashicorp/terraform/issues/28803。
请注意,问题已锁定,因为 Hashicorp 厌倦了人们告诉他们这对他们的团队有多么负面的影响。
在 1.2 版本(尚未发布)中,他们承诺不会再那么糟糕了 https://github.com/hashicorp/terraform/issues/28803#issuecomment-1072740861
Starting with v1.2, the goal for the refresh report is that only external changes which may have contributed to changes in the plan will be shown. This means in most cases, unused attributes changing outside of terraform will not show up in the normal plan output. If there are no changes in the plan, no external changes will be shown in the CLI at all. All refresh information is still stored within the plan, and if a user wants to see all external changes of resources in the CLI, a refresh-only plan can be used.
P.S。顺便说一句,这些东西可以用 sed 从输出中排除,例如(经过 macOS 测试):
terraform plan | sed -n '/Objects have changed outside of Terraform/,/─────────────────────────────────────────────────────────────────────────────/!p
最近将我的 Terraform 项目升级到 AWS 提供商 3.74.0 和 TF 1.1.4(从更旧的版本)。
我突然收到此自动缩放计划报告外部更改:
resource "aws_autoscaling_schedule" "api-svc-tst-down-schedule" {
scheduled_action_name = "api-svc-tst-down-schedule"
min_size = 0
max_size = 1
desired_capacity = 0
// Minute Hour DayOfMonth Month DayOfWeek
recurrence = "0 13 * * *"
autoscaling_group_name = aws_autoscaling_group.api-svc-tst-asg.name
lifecycle {
ignore_changes = [start_time]
}
}
plan
命令正在报告:
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply":
# aws_autoscaling_schedule.api-svc-tst-down-schedule has changed
~ resource "aws_autoscaling_schedule" "api-svc-tst-down-schedule" {
id = "api-svc-tst-down-schedule"
~ start_time = "2022-01-31T13:00:00Z" -> "2022-02-01T13:00:00Z"
# (7 unchanged attributes hidden)
}
如果我 apply
计划,TF 似乎不会更改 ASG(我假设它只是更新其状态文件)并且通知会在第二天消失。
我注意到 AWS 控制台确实显示 Scheduled action
有一个 Start time
,这似乎是由 AWS 设置的。
我尝试将 start_time
添加到 ignored_changes
但它似乎没有什么不同,仍然报告为外部更改。
这是 Terraform 的已知问题吗(我通过谷歌搜索没有看到任何内容)?
如何防止 TF 被标记为外部更改?
编辑:我也尝试按照评论中的建议设置 start_time
属性。但是第二天检测到的更改警告又回来了。
编辑 2:我也尝试通过 Terraform 删除并重新添加资源,但第二天它仍然被标记为已更改。
这种不良行为是 Terraform version 0.15.4 中引入的有意更改。
目前无法避免。唯一的解决方法是必须教育所有团队成员(和工具)忽略“预期漂移”。
请注意,这种“预期漂移”行为不仅限于 aws_autoscaling_schedule
资源,甚至不限于 AWS 提供商。对于云供应商在创建资源后更新属性的任何资源,该问题发生在许多不同的 platforms/types 上。
许多资源会在创建后立即报告漂移 - 通常您可以通过立即执行 apply
或 refresh
来更新 TF 状态来摆脱报告,只要 AWS 没有如果不更改这些属性,您将不会看到报告为已更改的资源。
其他资源属性(如 aws_autoscaling_schedule.start_time
)由云供应商定期更新。每当您 运行 plan
.
有一个锁定未解决问题需要跟踪:https://github.com/hashicorp/terraform/issues/28803。
请注意,问题已锁定,因为 Hashicorp 厌倦了人们告诉他们这对他们的团队有多么负面的影响。
在 1.2 版本(尚未发布)中,他们承诺不会再那么糟糕了 https://github.com/hashicorp/terraform/issues/28803#issuecomment-1072740861
Starting with v1.2, the goal for the refresh report is that only external changes which may have contributed to changes in the plan will be shown. This means in most cases, unused attributes changing outside of terraform will not show up in the normal plan output. If there are no changes in the plan, no external changes will be shown in the CLI at all. All refresh information is still stored within the plan, and if a user wants to see all external changes of resources in the CLI, a refresh-only plan can be used.
P.S。顺便说一句,这些东西可以用 sed 从输出中排除,例如(经过 macOS 测试):
terraform plan | sed -n '/Objects have changed outside of Terraform/,/─────────────────────────────────────────────────────────────────────────────/!p