github.com/jrperritt/terraform@v0.1.1-0.20170525065507-96f391dafc38/examples/azure-2-vms-loadbalancer-lbrules/main.tf (about) 1 # provider "azurerm" { 2 # subscription_id = "REPLACE-WITH-YOUR-SUBSCRIPTION-ID" 3 # client_id = "REPLACE-WITH-YOUR-CLIENT-ID" 4 # client_secret = "REPLACE-WITH-YOUR-CLIENT-SECRET" 5 # tenant_id = "REPLACE-WITH-YOUR-TENANT-ID" 6 # } 7 8 resource "azurerm_resource_group" "rg" { 9 name = "${var.resource_group}" 10 location = "${var.location}" 11 } 12 13 resource "azurerm_storage_account" "stor" { 14 name = "${var.dns_name}stor" 15 location = "${var.location}" 16 resource_group_name = "${azurerm_resource_group.rg.name}" 17 account_type = "${var.storage_account_type}" 18 } 19 20 resource "azurerm_availability_set" "avset" { 21 name = "${var.dns_name}avset" 22 location = "${var.location}" 23 resource_group_name = "${azurerm_resource_group.rg.name}" 24 platform_fault_domain_count = 2 25 platform_update_domain_count = 2 26 managed = true 27 } 28 29 resource "azurerm_public_ip" "lbpip" { 30 name = "${var.rg_prefix}-ip" 31 location = "${var.location}" 32 resource_group_name = "${azurerm_resource_group.rg.name}" 33 public_ip_address_allocation = "dynamic" 34 domain_name_label = "${var.lb_ip_dns_name}" 35 } 36 37 resource "azurerm_virtual_network" "vnet" { 38 name = "${var.virtual_network_name}" 39 location = "${var.location}" 40 address_space = ["${var.address_space}"] 41 resource_group_name = "${azurerm_resource_group.rg.name}" 42 } 43 44 resource "azurerm_subnet" "subnet" { 45 name = "${var.rg_prefix}subnet" 46 virtual_network_name = "${azurerm_virtual_network.vnet.name}" 47 resource_group_name = "${azurerm_resource_group.rg.name}" 48 address_prefix = "${var.subnet_prefix}" 49 } 50 51 resource "azurerm_lb" "lb" { 52 resource_group_name = "${azurerm_resource_group.rg.name}" 53 name = "${var.rg_prefix}lb" 54 location = "${var.location}" 55 56 frontend_ip_configuration { 57 name = "LoadBalancerFrontEnd" 58 public_ip_address_id = "${azurerm_public_ip.lbpip.id}" 59 } 60 } 61 62 resource "azurerm_lb_backend_address_pool" "backend_pool" { 63 resource_group_name = "${azurerm_resource_group.rg.name}" 64 loadbalancer_id = "${azurerm_lb.lb.id}" 65 name = "BackendPool1" 66 } 67 68 resource "azurerm_lb_nat_rule" "tcp" { 69 resource_group_name = "${azurerm_resource_group.rg.name}" 70 loadbalancer_id = "${azurerm_lb.lb.id}" 71 name = "RDP-VM-${count.index}" 72 protocol = "tcp" 73 frontend_port = "5000${count.index + 1}" 74 backend_port = 3389 75 frontend_ip_configuration_name = "LoadBalancerFrontEnd" 76 count = 2 77 } 78 79 resource "azurerm_lb_rule" "lb_rule" { 80 resource_group_name = "${azurerm_resource_group.rg.name}" 81 loadbalancer_id = "${azurerm_lb.lb.id}" 82 name = "LBRule" 83 protocol = "tcp" 84 frontend_port = 80 85 backend_port = 80 86 frontend_ip_configuration_name = "LoadBalancerFrontEnd" 87 enable_floating_ip = false 88 backend_address_pool_id = "${azurerm_lb_backend_address_pool.backend_pool.id}" 89 idle_timeout_in_minutes = 5 90 probe_id = "${azurerm_lb_probe.lb_probe.id}" 91 depends_on = ["azurerm_lb_probe.lb_probe"] 92 } 93 94 resource "azurerm_lb_probe" "lb_probe" { 95 resource_group_name = "${azurerm_resource_group.rg.name}" 96 loadbalancer_id = "${azurerm_lb.lb.id}" 97 name = "tcpProbe" 98 protocol = "tcp" 99 port = 80 100 interval_in_seconds = 5 101 number_of_probes = 2 102 } 103 104 resource "azurerm_network_interface" "nic" { 105 name = "nic${count.index}" 106 location = "${var.location}" 107 resource_group_name = "${azurerm_resource_group.rg.name}" 108 count = 2 109 110 ip_configuration { 111 name = "ipconfig${count.index}" 112 subnet_id = "${azurerm_subnet.subnet.id}" 113 private_ip_address_allocation = "Dynamic" 114 load_balancer_backend_address_pools_ids = ["${azurerm_lb_backend_address_pool.backend_pool.id}"] 115 load_balancer_inbound_nat_rules_ids = ["${element(azurerm_lb_nat_rule.tcp.*.id, count.index)}"] 116 } 117 } 118 119 resource "azurerm_virtual_machine" "vm" { 120 name = "vm${count.index}" 121 location = "${var.location}" 122 resource_group_name = "${azurerm_resource_group.rg.name}" 123 availability_set_id = "${azurerm_availability_set.avset.id}" 124 vm_size = "${var.vm_size}" 125 network_interface_ids = ["${element(azurerm_network_interface.nic.*.id, count.index)}"] 126 count = 2 127 128 storage_image_reference { 129 publisher = "${var.image_publisher}" 130 offer = "${var.image_offer}" 131 sku = "${var.image_sku}" 132 version = "${var.image_version}" 133 } 134 135 storage_os_disk { 136 name = "osdisk${count.index}" 137 create_option = "FromImage" 138 } 139 140 os_profile { 141 computer_name = "${var.hostname}" 142 admin_username = "${var.admin_username}" 143 admin_password = "${var.admin_password}" 144 } 145 }