0

我有一个 Azure ARM 模板,它成功地从 Azure 存储帐户中的文件目录引导 VM。我想让它在 Terraform 中工作,但我真的很难让它正常工作。

这是一个有效的 Azure ARM 模板,它创建 VM 并使用 Azure 存储帐户中的文件引导它。通过使用customData参数进行引导。

"variables": {
  "uniqueId": "[uniqueString(resourceGroup().id)]",
  "customData": "[concat('storage-account=', parameters('STORAGE_ACCOUNT'), ',access-key=', parameters('ACCESS_KEY'), ',file-share=', parameters('FILE_SHARE'), ',share-directory=', parameters('SHARE_DIRECTORY'))]"
},
"resources": [
  {
    "apiVersion": "2016-04-30-preview",
    "type": "Microsoft.Compute/virtualMachines",
    "name": "MY-VM",
    "location": "[resourceGroup().location]",
    "properties": {
      "hardwareProfile": {
          "vmSize": "Standard_DS3_v2"
      },
      "osProfile": {
          "computerName": "My-Computer-Name",
          "adminUsername": "[parameters('Username')]",
          "adminPassword": "[parameters('Password')]",
          "customData": "[base64(variables('customData'))]"
      }
    }
  }

这是我尝试执行相同类型的引导时无法正常工作的 Terraform 脚本。

resource "azurerm_virtual_machine" "MY-VM" {
  name                         = "${var.vm_name}"
  location                     = "${var.location}"
  resource_group_name          = "${azurerm_resource_group.rg.name}"
  vm_size                      = "${var.vm_size}"
  primary_network_interface_id = "${azurerm_network_interface.nic0.id}"

  os_profile {
    computer_name     = "${var.vm_name}"
    admin_username    = "${var.adminuser}"
    admin_password    = "${var.adminuserpassword}"
    custom_data       = "${base64encode(join("", list("storage-account=", var.STORAGE_ACCOUNT, ",access-key=", var.ACCESS_KEY, ",file-share=", var.FILE_SHARE, ",share-directory=None")))}"
  }
}

这是我运行它时收到的错误。如果我不使用 custom_data 字段,机器可以正常启动,但不会被引导。我在这里没有想法..

azurerm_virtual_machine.MY-VM: 
compute.VirtualMachinesClient#CreateOrUpdate: Failure sending 
request: StatusCode=0 -- Original Error: autorest/azure: Service 
returned an error. Status=400 Code="InvalidRequestFormat" 
Message="Cannot parse the request." Details=[]
4

1 回答 1

1

我不认为 join 适用于字符串?对于你的情况,你可以做

"storage-account=${var.STORAGE_ACCCOUNT},access-key=${var.ACCESS_KEY},file-share=${var.FILE_SHARE},share-directory=None"
于 2019-01-01T18:42:39.260 回答