azure - 如何在terraform中使用azurerm_virtual_machine资源的custom_data字段?

标签 azure terraform terraform-provider-azure

我正在尝试使用资源 azurerm_virtual_machine 的 custom_data 字段,但遇到了此错误。知道我缺少什么或者这是错误的用法吗?

resource "azurerm_virtual_machine" "csrVM" {
  name                  = "csr-terraform-poc"
  location              = "${var.location}"
  resource_group_name   = "${azurerm_resource_group.terraformRG.name}"
  network_interface_ids = ["${azurerm_network_interface.terraformNic1.id}",
                           "${azurerm_network_interface.terraformNic2.id}"]
  primary_network_interface_id = "${azurerm_network_interface.terraformNic1.id}"
  vm_size               = "Standard_DS1_v2"

  custom_data = "${file("customdata.txt")}"
  #custom_data = <<CUSTOMDATA
  #username testuser privilege 15 password testpass
  #enable password testpass
#CUSTOMDATA

~>terraform apply -var-file=azure.tfvars

错误:azurerm_virtual_machine.csrVM::无效或未知 key :custom_data

~>terraform -v 地形 v0.11.3 + 提供商.azurerm v1.1.1

最佳答案

我从未使用过 terraform,但查看 resource definition您需要创建一个 os_profile 节点并将 custom_data 放置在那里。

os_profile 支持以下内容:

computer_name - (Required) Specifies the name of the virtual machine.  
admin_username - (Required) Specifies the name of the administrator account.  
admin_password - (Required for Windows, Optional for Linux) Specifies the password of the administrator account.  
custom_data - (Optional) Specifies custom data to supply to the machine. On linux-based systems, this can be used as a cloud-init script. On other systems, this will be copied as a file on disk. Internally, Terraform will base64 encode this value before sending it to the API. The maximum length of the binary array is 65535 bytes.

关于azure - 如何在terraform中使用azurerm_virtual_machine资源的custom_data字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48976216/

相关文章:

azure - 如何使用注册应用程序的服务主体通过 PowerShell 模块连接到 Azure?

node.js - 如何使用从 OIDCStrategy 检索到的 accessToken 来遍历 Azure Graph API?

azure - 根据资源 ID (GUID) 获取资源名称 - Azure

terraform - 访问 Terraform Cloud 环境变量

azure - 触发警报时不会触发操作

azure - 如何授予应用程序访问其自己的 api 的权限

Terraform 未知参数或属性是什么

sql - SQL Azure 中是否支持 PARTITION BY ... ORDER BY

azure - 添加计划 block 作为条件 if 语句

terraform - 使用 TerraForm 创建 Azure Front Door 实例