Terraform – Virtual Network deployment

This Terraform script deploys a resource group, a virtual network with six subnets with tags.

### Define the resource group
resource "azurerm_resource_group" "aa" {
  name     = "allen-TFvnet"
  location = "southafricanorth"
  tags = {
    CustomerName         = "Customer01"
    AutoShutdownSchedule = "None"
    Environment          = "sandbox"
  }
}

### Define the virtual network
resource "azurerm_virtual_network" "aa" {
  name                = "vnet-sandbox"
  resource_group_name = azurerm_resource_group.aa.name
  location            = azurerm_resource_group.aa.location
  address_space       = ["10.0.0.0/16"]
  dns_servers         = ["10.0.0.10", "10.0.0.12"]
  tags = {
    CustomerName         = "Customer01"
    AutoShutdownSchedule = "None"
    Environment          = "sandbox"
  }
}

### Define the subnets
resource "azurerm_subnet" "subnet1" {
  name                 = "Internal-subnet01"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.0/27"]
}

resource "azurerm_subnet" "subnet2" {
  name                 = "Internal-subnet02"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.32/27"]
}

resource "azurerm_subnet" "subnet3" {
  name                 = "Internal-subnet03"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.64/27"]
}

resource "azurerm_subnet" "subnet4" {
  name                 = "Internal-subnet04"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.96/27"]
}

resource "azurerm_subnet" "subnet5" {
  name                 = "Internal-subnet05"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.128/27"]
}

resource "azurerm_subnet" "subnet6" {
  name                 = "Internal-subnet06"
  resource_group_name  = azurerm_resource_group.aa.name
  virtual_network_name = azurerm_virtual_network.aa.name
  address_prefixes     = ["10.0.1.160/27"]
}

— I hope this Terraform script helped expedite your deployment–

Leave a comment

Your email address will not be published. Required fields are marked *