【问题标题】:Forcing azurerm extension to wait until vm is deployed强制 azurerm 扩展等到部署 vm
【发布时间】:2018-02-13 18:16:51
【问题描述】:

我遇到了一个问题,目前阻止我使用 Terraform,我想看看是否有人看到过相同的行为。我正在使用 count 来部署多个虚拟机以及每个虚拟机的 dsc 扩展。

因为在第二台机器上运行之前我需要在第一台机器上运行 dsc 扩展,所以我尝试使用该扩展的depends_on 属性,但由于我使用插值进行机器命名的方式,它失败了,因为插值不是在depends_on中得到支持。

有人知道解决这个问题的方法吗?我还测试了将机器名称推送到数据资源中,但我需要再次使用 depends_on 属性来支持插值。

resource "azurerm_virtual_machine" "Server" {
  name = "${format("${var.customerProject}${var.environment}${var.machineAcronyms["Server"]}%02d", count.index + 1)}"
  location = "${var.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  network_interface_ids = ["${element(azurerm_network_interface.Server_NIC.*.id, count.index)}"]
  vm_size = "${var.Server_Specs["ServerType"]}"
  count = "${var.Server_Specs["Number_of_Machines"]}"

  storage_image_reference {
    publisher = "${var.Server_Specs["Image_Publisher"]}"
    offer = "${var.Server_Specs["Image_Offer"]}"
    sku = "${var.Server_Specs["Image_sku"]}"
    version = "${var.Server_Specs["Image_Version"]}"
  }

  plan {
    name = "${var.Server_Specs["Plan_Name"]}"
    publisher = "${var.Server_Specs["Plan_Publisher"]}"
    product = "${var.Server_Specs["Plan_Product"]}"
  }

  os_profile {
    computer_name  = "${format("${var.customerProject}${var.environment}${var.machineAcronyms["Server"]}%02d", count.index + 1)}"
    admin_username = "${var.AdminCredentials["Username"]}"
    admin_password = "${var.AdminCredentials["Password"]}"
  }

  os_profile_windows_config {
    provision_vm_agent  = "true"
  }
}

resource "azurerm_virtual_machine_extension" "Server_DSC" {
  name = "${format("${var.customerProject}${var.environment}${var.machineAcronyms["Server"]}%02d", count.index + 1)}-dsc"
  location = "${var.location}"
  resource_group_name = "${azurerm_resource_group.rg.name}"
  virtual_machine_name = "${format("${var.customerProject}${var.environment}${var.machineAcronyms["Server"]}%02d", count.index + 1)}"
  publisher = "Microsoft.Powershell"
  type = "DSC"
  type_handler_version = "${var.dsc_extension}"
  auto_upgrade_minor_version = true
  depends_on = ["azurerm_storage_share.fileShare"]
  count = "${var.Server_Specs["Number_of_Machines"]}"

  settings = <<SETTINGS
  {
    "configuration": {
        "url": "${var.resourceStore["fileShareUrl"]}${var.resourceStore["dscArchiveName"]}${var.azureCredentials["storageKey"]}",
        "function": "contenthostingha",
        "script": "contenthostingha.ps1"
    },
    "configurationArguments": {
        "ExternalDNS": "${var.externalDNS}",
        "NumberOfMachines": "${var.Server_Specs["Number_of_Machines"]}",
        "AzureFileUrl": "azurerm_storage_share.fileShare.url",
        "AzureFileShareKey": "${azurerm_storage_account.storageAccount.secondary_access_key}"
    }
}

  SETTINGS

  protected_settings = <<PROTECTED_SETTINGS
  {
    "configurationArguments": {}
  }
  PROTECTED_SETTINGS
}

【问题讨论】:

    标签: terraform


    【解决方案1】:

    我没有尝试过,但您可能会复制 Server_DSC 资源(例如 Server_DSC_0 和 Server_DSC_nth),_0 将使用固定的 "0" 而不是计数,并且实例数应减少 1,例如,使用将原始变量减一的局部变量。

    【讨论】:

      猜你喜欢
      • 2019-09-02
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 2014-07-23
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多