Creating terraform virtual networks, resource groups, subnets – Part 2

Azure & Terraform

Part 2 – Creating Terraform virtual networks, resource groups with frontend and backend subnets using Terraform.

Script to Create a Resource Group, vNet with FrontEnd and BackEnd subnets.

# Cloudinspired.com Part 2 - Create a Resource Group, vNet with FrontEnd and BackEnd subnets.

#Create Resource Group in UK south

resource "azurerm_resource_group" "RG" {
    name     = "RGUKS"
    location = "UK South"

    tags {
        environment = "Production"
    }
}

#Create VNET in UK south

resource "azurerm_virtual_network" "VNET" {
    name                = "UKS"
    address_space       = ["10.0.0.0/16"]
    location            = "UK South"
    resource_group_name = "${azurerm_resource_group.RG.name}"

    tags {
        environment = "Production"
    }
}

#Create FrontEnd Subnet 

resource "azurerm_subnet" "FrontEnd" {
    name                 = "FrontEnd"
    resource_group_name  = "${azurerm_resource_group.RG.name}"
    virtual_network_name = "${azurerm_virtual_network.VNET.name}"
    address_prefix       = "10.0.1.0/24"
}

#Create BackendEnd Subnet

resource "azurerm_subnet" "BackEnd" {
    name                 = "BackEnd"
    resource_group_name  = "${azurerm_resource_group.RG.name}"
    virtual_network_name = "${azurerm_virtual_network.VNET.name}"
    address_prefix       = "10.0.2.0/24"
}

#Create Availability Set FrontEnd

resource "azurerm_availability_set" "AS1" {
  name                = "UKSAS1"
  location            = "UK South"
  resource_group_name = "${azurerm_resource_group.RG.name}"
  managed 			  = true
  platform_fault_domain_count = 2

  tags {
    environment = "Production"
  }
}

#Create Availability Set Backend

resource "azurerm_availability_set" "AS2" {
  name                = "UKSAS2"
  location            = "UK South"
  resource_group_name = "${azurerm_resource_group.RG.name}"
  managed 			  = true
  platform_fault_domain_count = 2

  tags {
    environment = "Production"
  }
}

 
One Comment

Add a Comment

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