简体   繁体   English

Terraform EC2 用户数据更改未更换 EC2

[英]Terraform EC2 User Data Changes Not Replacing The EC2

I've noticed recently Terraform or AWS has made a change EC2 userdata so that changes don't trigger a 'replace' in terraform. Quote Terraform aws_instance docs: Updates to this field will trigger a stop/start of the EC2 instance.我最近注意到 Terraform 或 AWS 对 EC2 用户数据进行了更改,以便更改不会触发 terraform 中的“替换”。引用 Terraform aws_instance文档:对该字段的更新将触发 EC2 实例的停止/启动。

We have automated deployments that rely on userdata changes to trigger replacements, so that the new userdata is ran everytime.我们有依赖于用户数据更改来触发替换的自动化部署,因此每次都会运行新的用户数据。

Is there a way Terraform can be told to replace instances is it notices new userdata?有没有办法告诉 Terraform 替换实例,它是否注意到新的用户数据? Lambda has a similar issue that is solved with 'source_code_hash' Is there something similar I can use here? Lambda 有一个类似的问题,已通过“source_code_hash”解决 我可以在这里使用类似的东西吗?

Thanks.谢谢。

Good news, terraform-provider-aws has an open issue ticket where many are reporting this issue.好消息,terraform-provider-aws 有一个未决问题单,许多人都在报告这个问题。 Feedback from individuals who rely on user_data to initiate a replace on their EC2 instances have been reported.已经报告了依赖 user_data 在其 EC2 实例上启动更新的个人的反馈。 This includes CI/CD pipelines that are now broken.这包括现在已损坏的 CI/CD 管道。

jaredholgate mentions they are planning to add a parameter called user_data_replace_on_change - it will be false by default. jaredholgate 提到他们计划添加一个名为user_data_replace_on_change的参数——默认情况下为 false。

In the meantime, you can use the -replace flag to target your ec2 instance.同时,您可以使用 -replace 标志来定位您的 ec2 实例。 For example:例如:

 terraform plan -replace aws_instance.my_ec2_instance terraform apply -replace aws_instance.my_ec2_instance

For citation purposes, this issue has been reported at: https://github.com/hashicorp/terraform-provider-aws/issues/23315出于引用目的,此问题已在以下位置报告: https://github.com/hashicorp/terraform-provider-aws/issues/23315

The change has come from within a new Terraform AWS provider version更改来自新的 Terraform AWS 提供商版本

If you are running userdata with cloud-init an easy fix would be to use the cloud-init type x-shellscript-per-boot instead of x-shellscript.如果您使用cloud-init运行用户数据,一个简单的解决方法是使用 cloud-init 类型 x-shellscript-per-boot 而不是 x-shellscript。

This would mean any userdata updates would be ran every stop/start.这意味着任何用户数据更新都将在每次停止/启动时运行。

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

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