代码之家  ›  专栏  ›  技术社区  ›  phydeauxman

使用Terraform部署期间在Azure VM上安装DSC扩展时出现问题

  •  0
  • phydeauxman  · 技术社区  · 7 年前

    我试图使用本文中的信息:

    https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/dsc-template#default-configuration-script

    在部署时将VM装载到Azure Automation并应用配置。

    我正在使用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上的日志中看出,该扩展正在安装,但从未向自动化帐户注册。

    1 回复  |  直到 7 年前
        1
  •  3
  •   phydeauxman    7 年前

    找出问题所在。文档在某些方面缺乏细节,所以我确实是通过反复试验才发现了问题的原因。我在表中的值是错误的 NodeConfigurationName 财产。文档中关于此属性的说明: Specifies the node configuration in the Automation account to assign to the node. 由于没有太多的DSC经验,我打断了这段话,意思是如图所示的配置名称 Configurations 部分 State configuration (DSC) Azure门户中自动化帐户的刀片服务器。

    节点配置名称 物业真正指的是 Node 配置中的定义,其格式应为ConfigurationName.NodeName。例如,我的配置的名称是 VMConfig 在配置源代码中,我有一个 块定义调用 localhost . 所以,有了这个…这个 节点配置名称 财产应该是 VMConfig.localhost .

    推荐文章