强制azurerm扩展等待直到部署vm

时间:2018-02-13 18:16:51

标签: terraform

我遇到了一个阻止我现在使用Terraform的问题,想知道是否有人看到了同样的行为。我使用count来为每个VM部署多个VM以及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
}

1 个答案:

答案 0 :(得分:0)

我还没有尝试,但您可能会复制Server_DSC资源(例如Server_DSC_0Server_DSC_nth),_0将使用固定的"0"代替计数和数字实例应减少1,例如使用局部变量将一减去原始变量。