从terraform设置PSDscAllowPlaintextPassword为true

时间:2018-07-13 15:59:16

标签: powershell terraform

我正在使用terraform和powershell DSC来设置活动目录域控制器。

当我在服务器中运行脚本时,一切都可以正常进行,因为我可以将“ PSDscAllowPlaintextPassword”设置为true来指定配置数据(我知道这不是最佳实践,但现在是我们所需要的)。

但是,当从terraform扩展名运行此脚本时,发生的事情是没有提供配置数据,并且我无法(或者我不知道如何)将其设置为true才能使脚本正常工作。

我希望能够在节点定义内将PSDscAllowPlaintextPassword指定为true(不需要配置数据),或者能够从terraform扩展名发送它。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

所以我们终于找到了实现方法。

我们从Terraform调用powershell脚本,如下所示:

  resource "azurerm_virtual_machine_extension" "test" {
  count                      = "1"
  name                       = "xxx"
  location                   = "xxx"
  resource_group_name        = "xxx"
  virtual_machine_name       = "xxx"
  publisher                  = "Microsoft.Powershell"
  type                       = "DSC"
  type_handler_version       = "2.73"
  auto_upgrade_minor_version = true

  settings = <<SETTINGS
    {
      "configuration": {
        "url": "package_url",
        "script": "scriptforactivedomain.ps1",
        "function": "functionname"
      }
    }
SETTINGS

  tags {
    environment = "xxx"
    category    = "xxx"
  }
}

我们只需要在设置区域添加一个代码段即可:

  settings = <<SETTINGS
{
  "configuration": {
    "url": "package_url",
    "script": "scriptforactivedomain.ps1",
    "function": "functionname"
  },
   "configurationData": {
    "url": "url_to_file_with_configuration_data.psd1"
  }
}

设置

然后在.psd1中,就像通常一样指定配置数据:

@{
   AllNodes = @(
       @{
            NodeName = 'localhost'
            PSDscAllowPlainTextPassword = $true
            }
        )
    }

在这种情况下,这很简单,但是我却把头弄坏了!