gpt4 book ai didi

azure - 使用 terraform 在 Azure 中为每个可用区创建子网

转载 作者:行者123 更新时间:2023-12-04 04:07:59 25 4
gpt4 key购买 nike

我正在尝试使用 terraform 在 Azure 中为每个可用区创建子网。我正在使用下面的代码创建一个子网。

resource "azurerm_subnet" "public_subnet" {
name = "public_subnet"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.terraform_rg.name
address_prefix = "10.20.10.0/24"
}

我的要求在AWS中是可能的。由于我是 Azure 的新手,我不确定是否可以在 Azure 中执行相同的操作。如果有人伸出援手来帮助我,那就太好了。

提前致谢!

最佳答案

Azure 子网不是 Zonal service (其中资源被固定到特定区域),请参阅Azure services and regions that support Availability Zones 。因此,您需要为每个可用区创建特定的支持服务。

例如,您可以为每个可用区域创建一个 Azure VM 或 Azure 公共(public) IP。

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "east us"
}

resource "azurerm_public_ip" "example" {
name = "acceptanceTestPublicIp1"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
allocation_method = "Static"
sku = "Standard"
zones = ["1"]

}

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_prefix = "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"
public_ip_address_id = azurerm_public_ip.example.id
}
}

resource "azurerm_linux_virtual_machine" "example" {
name = "example-machine"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
size = "Standard_F2"
zone = "1"
admin_username = "adminuser"
network_interface_ids = [
azurerm_network_interface.example.id,
]

admin_ssh_key {
username = "adminuser"
public_key = file("~/.ssh/id_rsa.pub")
}

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

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

如果您对 zone 选项感兴趣,可以查看此 open issue .

关于azure - 使用 terraform 在 Azure 中为每个可用区创建子网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62195054/

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