gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:36:38 25 4
gpt4 key购买 nike

我正在尝试将现有的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com