【问题标题】:Creating subnet per availability zones in Azure using terraform使用 terraform 在 Azure 中为每个可用区创建子网
【发布时间】:2020-10-08 06:15:32
【问题描述】:

我正在尝试使用 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 terraform azure-virtual-network


    【解决方案1】:

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

    例如,您可以为每个可用区创建一个 Azure VM 或 Azure 公共 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

    【讨论】:

      猜你喜欢
      • 2019-11-22
      • 2021-01-07
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2022-10-15
      相关资源
      最近更新 更多