github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/azure/terraform-azure-loadbalancer-example/main.tf (about) 1 # --------------------------------------------------------------------------------------------------------------------- 2 # DEPLOY AN AZURE AVAILABILITY SET 3 # This is an example of how to deploy an Azure Availability Set with a Virtual Machine in the availability set 4 # and the minimum network resources for the VM. 5 # --------------------------------------------------------------------------------------------------------------------- 6 # See test/azure/terraform_azure_loadbalancer_example_test.go for how to write automated tests for this code. 7 # --------------------------------------------------------------------------------------------------------------------- 8 provider "azurerm" { 9 version = "~>2.29" 10 features {} 11 } 12 13 # --------------------------------------------------------------------------------------------------------------------- 14 # PIN TERRAFORM VERSION TO >= 0.12 15 # The examples have been upgraded to 0.12 syntax 16 # --------------------------------------------------------------------------------------------------------------------- 17 18 terraform { 19 # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting 20 # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it 21 # forwards compatible with 0.13.x code. 22 required_version = ">= 0.12.26" 23 } 24 25 # --------------------------------------------------------------------------------------------------------------------- 26 # DEPLOY A RESOURCE GROUP 27 # --------------------------------------------------------------------------------------------------------------------- 28 29 resource "azurerm_resource_group" "lb_rg" { 30 name = "terratest-lb-rg-${var.postfix}" 31 location = var.location 32 } 33 34 # --------------------------------------------------------------------------------------------------------------------- 35 # DEPLOY VIRTUAL NETWORK 36 # --------------------------------------------------------------------------------------------------------------------- 37 38 resource "azurerm_virtual_network" "vnet" { 39 name = "vnet-${var.postfix}" 40 location = azurerm_resource_group.lb_rg.location 41 resource_group_name = azurerm_resource_group.lb_rg.name 42 address_space = ["10.200.0.0/21"] 43 } 44 45 resource "azurerm_subnet" "subnet" { 46 name = "subnet-${var.postfix}" 47 resource_group_name = azurerm_resource_group.lb_rg.name 48 virtual_network_name = azurerm_virtual_network.vnet.name 49 address_prefixes = ["10.200.2.0/25"] 50 } 51 52 # --------------------------------------------------------------------------------------------------------------------- 53 # DEPLOY LOAD BALANCER WITH PUBLIC IP 54 # --------------------------------------------------------------------------------------------------------------------- 55 56 resource "azurerm_public_ip" "pip" { 57 name = "pip-${var.postfix}" 58 location = azurerm_resource_group.lb_rg.location 59 resource_group_name = azurerm_resource_group.lb_rg.name 60 allocation_method = "Static" 61 ip_version = "IPv4" 62 sku = "Basic" 63 idle_timeout_in_minutes = "4" 64 } 65 66 resource "azurerm_lb" "public" { 67 name = "lb-public-${var.postfix}" 68 location = azurerm_resource_group.lb_rg.location 69 resource_group_name = azurerm_resource_group.lb_rg.name 70 sku = "Basic" 71 72 frontend_ip_configuration { 73 name = "config-public" 74 public_ip_address_id = azurerm_public_ip.pip.id 75 } 76 } 77 78 # --------------------------------------------------------------------------------------------------------------------- 79 # DEPLOY LOAD BALANCER WITH PRIVATE IPs 80 # --------------------------------------------------------------------------------------------------------------------- 81 82 resource "azurerm_lb" "private" { 83 name = "lb-private-${var.postfix}" 84 location = azurerm_resource_group.lb_rg.location 85 resource_group_name = azurerm_resource_group.lb_rg.name 86 sku = "Basic" 87 88 frontend_ip_configuration { 89 name = "config-private-static" 90 subnet_id = azurerm_subnet.subnet.id 91 private_ip_address = var.lb_private_ip 92 private_ip_address_allocation = "Static" 93 } 94 95 frontend_ip_configuration { 96 name = "config-private-dynamic" 97 subnet_id = azurerm_subnet.subnet.id 98 private_ip_address_allocation = "Dynamic" 99 } 100 } 101 102 # --------------------------------------------------------------------------------------------------------------------- 103 # DEPLOY LOAD BALANCER WITH NO FRONTEND CONFIGURATION 104 # --------------------------------------------------------------------------------------------------------------------- 105 106 resource "azurerm_lb" "default" { 107 name = "lb-no-frontend-${var.postfix}" 108 location = azurerm_resource_group.lb_rg.location 109 resource_group_name = azurerm_resource_group.lb_rg.name 110 sku = "Basic" 111 }