我正在尝试使用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中是否可以做同样的事情。如果有人伸出援助之手,那将是很好的。
谢谢!
答案 0 :(得分:1)
天蓝色的子网不是Zonal service(资源固定到特定区域的地方),请参考Azure services and regions that support Availability Zones。因此,您需要为每个可用性区域创建特定的支持服务。
例如,您可以在每个可用性区域中创建Azure VM或Azure公共IP。
import (
"fmt"
"time"
)
func main() {
start := time.Now()
for i := 0; i < 50000; i++ {
fmt.Println("Index", i)
}
finish := time.Now().Sub(start).Seconds()
fmt.Printf("Elapsed time was %.2f seconds.\n", finish)
}
如果您对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"
}
}
选项感兴趣,可以查看此open issue。