首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在terraform中设置winrm AllowUnencrypted="true“和auth @{Basic="true"}

在Terraform中设置winrm AllowUnencrypted="true"和auth @{Basic="true"}的方法如下:

  1. 使用Terraform的null_resource资源创建一个本地执行器,用于运行shell命令。在配置文件中添加以下内容:
代码语言:txt
复制
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
  }
}
  1. 替换your_winrm_usernameyour_winrm_passwordyour_winrm_host分别为实际的WinRM用户名、密码和主机地址。
  2. 运行terraform init初始化配置。
  3. 运行terraform apply应用配置,Terraform将创建一个null资源并执行Shell命令来配置WinRM。

这样,通过在Terraform中使用null资源和本地执行器,可以设置WinRM的AllowUnencrypted和auth属性为所需的值。请注意,这个例子中使用的是PowerShell命令,因此需要在运行Terraform的环境中安装PowerShell。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券