将Azure文件共享附加到Windows机器的Azure Terraform

时间:2019-02-21 23:21:08

标签: azure azure-storage terraform terraform-provider-azure azure-files


问题陈述
我正在创建Windows OS的Azure VM群集。到目前为止,我可以创建一个Azure文件共享。和天蓝色的Windows群集。我想将创建的文件共享附加到群集中的每个VM。找不到参考如何在Windows VM上添加参考。

此代码

resource "azurerm_storage_account" "main" {
  name                     = "stor${var.environment}${var.cost_centre}${var.project}"
  location                     = "${azurerm_resource_group.main.location}"
  resource_group_name          = "${azurerm_resource_group.main.name}"
  account_tier             = "${var.storage_account_tier}"
  account_replication_type = "${var.storage_replication_type}"
}


resource "azurerm_storage_share" "main" {
  name = "storageshare${var.environment}${var.cost_centre}${var.project}"

  resource_group_name  = "${azurerm_resource_group.main.name}"
  storage_account_name = "${azurerm_storage_account.main.name}"

  quota = "${var.storage_share_quota}"
}

resource "azurerm_virtual_machine" "vm" {
  name                  = "vm-${var.location_id}-${var.environment}-${var.cost_centre}-${var.project}-${var.seq_id}-${count.index}"
  location              = "${azurerm_resource_group.main.location}"
  resource_group_name   = "${azurerm_resource_group.main.name}"
  availability_set_id   = "${azurerm_availability_set.main.id}"
  vm_size               = "${var.vm_size}"
  network_interface_ids = ["${element(azurerm_network_interface.main.*.id, count.index)}"]
  count                 = "${var.vm_count}"

  storage_image_reference {
    publisher = "${var.image_publisher}"
    offer     = "${var.image_offer}"
    sku       = "${var.image_sku}"
    version   = "${var.image_version}"
  }

  storage_os_disk {
    name          = "osdisk${count.index}"
    create_option = "FromImage"
  }

  os_profile {
    computer_name  = "${var.vm_name}-${count.index}"
    admin_username = "${var.admin_username}"
    admin_password = "${var.admin_password}"
  }

  os_profile_windows_config {}

  depends_on = ["azurerm_network_interface.main"]

}

1 个答案:

答案 0 :(得分:0)

Azure没有提供类似的功能,因此您无法在本地执行此操作,您需要创建一个脚本并在vm use script extension \ dsc extension上运行该脚本,或者在terraform支持的情况下-使用terraform。

https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux