amazon-web-services - Terraform EC2 实例导入 - 用户数据不同

标签 amazon-web-services terraform

我正在尝试将现有的 EC2 实例导入 Terraform。我已经获取了 EC2 实例用户数据,并将其添加到我的 TF 配置文件中,例如

    user_data               = <<EOF
<powershell>
& $env:SystemRoot\System32\control.exe "intl.cpl,,/f:`"UKRegion.xml`""
& tzutil /s "GMT Standard Time" 
Set-Culture en-GB
</powershell>
EOF

资源导入正常,但是当我运行时 terraform plan我得到 TF 想要销毁并重新创建实例,作为 user_data '强制新资源'中的'更改'。
user_data: "946f756af0df239b19f86a72653e58dcc04c4b27" => "811599030dc713b18c3e35437a82b35095190a81" (forces new resource)

我尝试将用户数据从 EC2 控制台复制并粘贴到 TF 文件中,但这不起作用。这是可能吗?

最佳答案

根据这个 github issue ,看起来这是 terraform 如何将 user_data 解释为“计算”值的问题。似乎有解决办法。

  • First run a plan/apply cycle with your plan command including the extra argument on your command line:
    -target=template_file.userdata-consul. This will tell Terraform to do the minimal work it needs to update the template file, which should
    leave your launch configuration untouched.
  • Now run plan again, and since the template_file has now already been recreated it should interpolate the resolved template as expected into the user_data, and there should then be no diff because the "new" template rendering should be the same as the "old" one.

关于amazon-web-services - Terraform EC2 实例导入 - 用户数据不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48189459/

相关文章:

python - AWS云计算和文本处理入门

python - 如何在 aws lambda/tmp 目录中运行 python 脚本

linux - 为什么 EC2 实例在调整根 EBS 卷大小后无法正常启动?

amazon-web-services - CodeBuild 构建的 docker 构建阶段出错

amazon-web-services - 内联代码编辑器无法工作

azure - 如何让 terraform 自动导入所有 "already exists"资源?

azure - Terraform 扁平化和模块内循环问题

amazon-web-services - VPCId 未指定 : No default VPC for this user error when doing terraform apply

amazon-ec2 - 根模块没有声明该名称的变量。要使用此值,请将 "variable" block 添加到配置中

amazon-web-services - Terraform - AWS Route53 防止域删除