在使用 Terraform 进行部署期间在 Azure VM 上安装 DSC 扩展时出现问题
Issue with install DSC extension on Azure VM during deployment using Terraform
我正在尝试使用本文中的信息:
在部署时将 VM 载入 Azure 自动化并应用配置。
我正在使用 Terraform 进行部署,下面是我用于扩展的代码:
resource "azurerm_virtual_machine_extension" "cse-dscconfig" {
name = "${var.vm_name}-dscconfig-cse"
location = "${azurerm_resource_group.my_rg.location}"
resource_group_name = "${azurerm_resource_group.my_rg.name}"
virtual_machine_name = "${azurerm_virtual_machine.my_vm.name}"
publisher = "Microsoft.Powershell"
type = "DSC"
type_handler_version = "2.76"
depends_on = ["azurerm_virtual_machine.my_vm"]
settings = <<SETTINGS
{
"configurationArguments": {
"RegistrationUrl": "${var.endpoint}",
"NodeConfigurationName": "VMConfig"
}
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"configurationArguments": {
"registrationKey": {
"userName": "NOT_USED",
"Password": "${var.key}"
}
}
}
PROTECTED_SETTINGS
}
我在执行时通过 运行 下面的命令获取 RegistrationURL
值并将该值传递给 Terraform:
$endpoint = (Get-AzureRmAutomationRegistrationInfo -ResourceGroupName $tf_state_rg -AutomationAccountName $autoAcctName).Endpoint
我在执行时通过 运行 下面的命令获取 Password
值并将该值传递给 Terraform:
$key = (Get-AzureRmAutomationRegistrationInfo -ResourceGroupName $tf_state_rg -AutomationAccountName $autoAcctName).PrimaryKey
我可以从 VM 上的日志中得知扩展正在安装,但从未注册到自动化帐户。
找出问题所在。该文档在某些方面的细节很薄,因此我确实是通过反复试验才发现导致问题的原因。我在 NodeConfigurationName
属性中有错误的值。文档对此有何评论 属性:Specifies the node configuration in the Automation account to assign to the node.
没有太多使用 DSC 的经验,我打断了它来表示配置的名称,如 [=13= 的 Configurations
部分所示] Azure 门户中自动化帐户的边栏选项卡。
NodeConfigurationName
属性真正指的是配置里面的Node
定义,应该是ConfigurationName.NodeName的格式。例如,我的配置名称是 VMConfig
,在配置源中我有一个 Node
块定义为 localhost
。所以,有了这个...... NodeConfigurationName
属性 的值应该是 VMConfig.localhost
.
我正在尝试使用本文中的信息:
在部署时将 VM 载入 Azure 自动化并应用配置。
我正在使用 Terraform 进行部署,下面是我用于扩展的代码:
resource "azurerm_virtual_machine_extension" "cse-dscconfig" {
name = "${var.vm_name}-dscconfig-cse"
location = "${azurerm_resource_group.my_rg.location}"
resource_group_name = "${azurerm_resource_group.my_rg.name}"
virtual_machine_name = "${azurerm_virtual_machine.my_vm.name}"
publisher = "Microsoft.Powershell"
type = "DSC"
type_handler_version = "2.76"
depends_on = ["azurerm_virtual_machine.my_vm"]
settings = <<SETTINGS
{
"configurationArguments": {
"RegistrationUrl": "${var.endpoint}",
"NodeConfigurationName": "VMConfig"
}
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"configurationArguments": {
"registrationKey": {
"userName": "NOT_USED",
"Password": "${var.key}"
}
}
}
PROTECTED_SETTINGS
}
我在执行时通过 运行 下面的命令获取 RegistrationURL
值并将该值传递给 Terraform:
$endpoint = (Get-AzureRmAutomationRegistrationInfo -ResourceGroupName $tf_state_rg -AutomationAccountName $autoAcctName).Endpoint
我在执行时通过 运行 下面的命令获取 Password
值并将该值传递给 Terraform:
$key = (Get-AzureRmAutomationRegistrationInfo -ResourceGroupName $tf_state_rg -AutomationAccountName $autoAcctName).PrimaryKey
我可以从 VM 上的日志中得知扩展正在安装,但从未注册到自动化帐户。
找出问题所在。该文档在某些方面的细节很薄,因此我确实是通过反复试验才发现导致问题的原因。我在 NodeConfigurationName
属性中有错误的值。文档对此有何评论 属性:Specifies the node configuration in the Automation account to assign to the node.
没有太多使用 DSC 的经验,我打断了它来表示配置的名称,如 [=13= 的 Configurations
部分所示] Azure 门户中自动化帐户的边栏选项卡。
NodeConfigurationName
属性真正指的是配置里面的Node
定义,应该是ConfigurationName.NodeName的格式。例如,我的配置名称是 VMConfig
,在配置源中我有一个 Node
块定义为 localhost
。所以,有了这个...... NodeConfigurationName
属性 的值应该是 VMConfig.localhost
.