使用terraform在Ubuntu虚拟机上预安装Azure-cli

ep6jt1vc  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(189)

我正在使用Terraform部署Azure VM。我想探索在云中创建虚拟机后,在虚拟机上预安装一系列工具(如Azure cli)的选项。有人能帮我举一个如何实现这一点的示例吗?我当前的Terraform脚本如下所示:

resource "azurerm_linux_virtual_machine" "main" {
  name                            = "trainingVM-1"
  resource_group_name             = data.azurerm_resource_group.current.name
  location                        = data.azurerm_resource_group.current.location
  size                            = "Standard_B2s"
  admin_username                  = "vmsysuser2"
  admin_password                  = "Training123!"
  disable_password_authentication = false
  network_interface_ids = [
    azurerm_network_interface.linux.id,
  ]

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  identity {
    type         = "SystemAssigned, UserAssigned"
    identity_ids = [azurerm_user_assigned_identity.uai.id]
  }
}
euoag5mw

euoag5mw1#

1/您需要将此添加到您的***azure VM***资源块:

custom_data = filebase64("azure_cli.tpl")

2/然后创建文件“azure_cli.tpl”,其中包含安装Azure CLI的Linux说明:

sudo apt-get update
sudo apt-get install azure-cli -y

相关问题