gpt4 book ai didi

azure - 基于共享图像库上提供的自定义图像部署 Azure VM

转载 作者:行者123 更新时间:2023-12-02 23:12:38 28 4
gpt4 key购买 nike

enter image description here

我首先在 Azure 中创建了一个简单的标准虚拟机,我使用不同的软件针对数据科学目的对其进行了定制。然后,我从该虚拟机创建了一个镜像,以便我可以使用相同的配置更快地基于自定义镜像部署新虚拟机。我已将图像保存在 Azure 共享图像库 下。有什么方法可以将这个自定义图像从 Terraform 脚本部署到新的资源组中吗?我知道如何从 Terraform 部署普通标准虚拟机,但无法找到如何根据共享镜像库中保存的自定义镜像来部署它。

最佳答案

使用 terraform 从 Azure 共享图像库部署自定义图像。您可以使用 Data Source: azurerm_shared_imageazurerm_windows_virtual_machineazurerm_linux_virtual_machine通过指定source_image_id来管理它。请注意,在部署之前,新创建的虚拟机应与共享镜像位于同一区域。如果没有,您可以将此镜像复制到您所需的区域,请阅读 https://learn.microsoft.com/en-us/azure/virtual-machines/shared-image-galleries#replication

例如,从通用共享镜像部署 Windows VM:

provider "azurerm" {
features {}
}


data "azurerm_shared_image" "example" {
name = "my-image"
gallery_name = "my-image-gallery"
resource_group_name = "example-resources-imageRG"
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "xxxxximageregion"
}

resource "azurerm_virtual_network" "example" {
name = "example-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "example" {
name = "example-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_windows_virtual_machine" "example" {
name = "example-machine"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_F2"
admin_username = "adminuser"
admin_password = "P@$$w0rd1234!"
network_interface_ids = [
azurerm_network_interface.example.id,
]

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

source_image_id = data.azurerm_shared_image.example.id

}

结果

enter image description here

关于azure - 基于共享图像库上提供的自定义图像部署 Azure VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67178590/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com