Terraform DSC配置与节点配置中的Azure自动化



背景

我正在尝试使用Azure Automation将一些Azure Windows虚拟机配置为DNS服务器。

我想使用Terraform来配置自动化帐户、DSC配置和DSC节点配置,但我被困在DSC节点配置上。

我有以下内容,这是有效的,但只有当我通过点击门户手动编译它时:

resource "azurerm_automation_dsc_configuration" "configuration" {
name                    = "DNSConfig"
resource_group_name     = "my_rg"
location                = "uksouth"
automation_account_name = "my_aa_account"
content_embedded = <<-CONTENT
Configuration DNSConfig
{
Node 'localhost'
{
WindowsFeature DNS
{
Ensure = 'Present'
Name   = 'DNS'
}
# plus some more stuff
}
}
CONTENT
}

我想自动化编译,所以我尝试了:

resource "azurerm_automation_dsc_nodeconfiguration" "node" {
automation_account_name = "my_aa_account"
resource_group_name     = "my_rg"
name                    = "DNSConfig.localhost"
content_embedded        = "# what goes here?"
}

问题

我对此没有很强的背景知识,所以我不确定自己是否理解得当。我不知道nodeconfigurationcontent_embedded应该包含什么。

我应该从dsc_configuration中删除Node块并将其移动到dsc_nodeconfiguration中吗?或者节点块的内容(即不包括Node 'localhost' {}包装器(?

(我真的不确定"localhost"是否是节点所代表的名称(。

例如:

resource "azurerm_automation_dsc_nodeconfiguration" "node" {
content_embedded = "Node 'localhost' { WindowsFeature DNS {...} }"
...
}

resource "azurerm_automation_dsc_nodeconfiguration" "node" {
content_embedded = "WindowsFeature DNS {...}"`
...
}

还是别的什么?

我觉得我已经尝试了其中的一些选项,但反馈循环非常慢,所以我可能在调试时找到了正确的答案,却被另一个错误绊倒了!

有人有一个工作示例吗?或者可以解释它是如何工作的?

content_embedded中,您应该包括MOF文件的内容,请参阅azurerm_automation_dsc_nodeconfiguration文档中的示例
或者您可以使用terraform文件函数加载MOF内容并将其用作脚本。请记住将MOF内容编码为Unicode或UTF-8格式。

最新更新