[英]Using Terraform user_data with Windows Powershell
I am trying to create Windows EC2 instance, and I want to change its hostname immediately after creation.我正在尝试创建 Windows EC2 实例,我想在创建后立即更改其主机名。 I was trying to do it with user_data, but it looks like never gets executed.
我试图用 user_data 来做,但看起来永远不会被执行。 Does anyone know how can I do this?
有谁知道我该怎么做?
Script:脚本:
<powershell>
Rename-Computer -NewName "Server044"
Restart-Computer
</powershell>
Terraform Code: Terraform 代码:
resource "aws_instance" "web" {
.
.
user_data = base64encode(file("${"host.ps1"}"))
}
Looking at the modules I work with, we don't use base64encode() for powershell userdata.查看我使用的模块,我们不对 powershell 用户数据使用 base64encode()。 I think you try dropping that, or else look into the user_data_base64 argument.
我认为您尝试放弃它,或者查看 user_data_base64 参数。
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#user_data https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#user_data
Also, remove the unnecessary string interpolation.另外,删除不必要的字符串插值。
user_data = file("host.ps1")
You may also try adding the -Force
parameter to your Rename-Computer cmdlet so it suppresses the confirmation prompt, and -Restart
to do it with a single command.您也可以尝试将
-Force
参数添加到您的 Rename-Computer cmdlet 中,以便它取消确认提示,并使用-Restart
来使用单个命令执行此操作。
<powershell>
Rename-Computer -NewName "Server044" -Force -Restart
</powershell>
In the end, I changed the script file to be.txt, and then just used powershell tags inside.最后我把脚本文件改成be.txt,然后里面就用了powershell个标签。 That worked for me
这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.