简体   繁体   English

使用 Terraform user_data 和 Windows Powershell

[英]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.

相关问题 Terraform 用户数据 output 在 terraform output - Terraform user_data output in terraform output 使用 terraform 创建 ec2 实例时生成包含“IP 地址”的用户数据 - generate user_data including "IP Address" while creating ec2 instance using terraform terraform 中的 User_data 无法接收 pem 密钥的变量 - User_data in terraform unable to receive variable of pem key Terraform 等到执行 user_data 然后制作图像以自动缩放? - Terraform wait until execution of user_data then make an image to autoscale? 我可以将变量传递给使用 terraform 和 user_data 创建的 AWS EC2 实例吗? 或者更新一个已经创建的资源 - Can i pass variables to AWS EC2 instances created with terraform and user_data? Or update an already created resource 在使用 terraform 云 [aws-provider] 启动 ec2 实例时,既不能执行 user_data 脚本,也不能执行带有连接块的 remote-exec - Can't execute neither user_data script, nor remote-exec with connection block while launching ec2 instance with terraform cloud [aws-provider] 绕过 16KB EC2 user_data 限制 - Bypassing 16KB EC2 user_data limitation 是否可以使用 terraform 创建 SSO 用户 - AWS - Is it possible to create an SSO user using terraform - AWS 在Terraform中使用python加载csv数据到bigquery - Loading csv data to bigquery using python in Terraform 将 Azure CLI 命令与 Terraform 中的“数据源”一起使用 Windows 失败 - Use Azure CLI command with Terraform "data source" in Windows is failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM