在Terraform中设置winrm AllowUnencrypted="true"和auth @{Basic="true"}的方法如下:
null_resource
资源创建一个本地执行器,用于运行shell命令。在配置文件中添加以下内容:resource "null_resource" "winrm_config" {
provisioner "local-exec" {
command = <<EOT
$username = "your_winrm_username"
$password = "your_winrm_password"
$host = "your_winrm_host"
$secpasswd = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$session = New-PSSession -Credential $credentials -ConnectionUri http://$host:5985 -SessionOption (New-PSSessionOption -SkipCACheck)
$cmd = "winrm set winrm/config/service '@{AllowUnencrypted=""true""}'"
Invoke-Command -Session $session -ScriptBlock {param($cmd) iex $cmd} -Args $cmd
$cmd = "winrm set winrm/config/service/auth '@{Basic=""true""}'"
Invoke-Command -Session $session -ScriptBlock {param($cmd) iex $cmd} -Args $cmd
Remove-PSSession -Session $session
EOT
}
}
your_winrm_username
、your_winrm_password
和your_winrm_host
分别为实际的WinRM用户名、密码和主机地址。terraform init
初始化配置。terraform apply
应用配置,Terraform将创建一个null资源并执行Shell命令来配置WinRM。这样,通过在Terraform中使用null资源和本地执行器,可以设置WinRM的AllowUnencrypted和auth属性为所需的值。请注意,这个例子中使用的是PowerShell命令,因此需要在运行Terraform的环境中安装PowerShell。
领取专属 10元无门槛券
手把手带您无忧上云