Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.8 kB
1
Indexable
Never
provider "azurerm" {
  subscription_id = var.subscription_id
  client_id = var.client_id
  client_secret = var.client_secret
}

resource "azurerm_lb" "lb" {
  name = "my-lb"
  location = var.location
  sku {
    name = "Standard"
    tier = "Regional"
  }
  frontend_ip_configurations {
    name = "my-frontend-ip"
    public_ip_addresses {
      name = "my-public-ip"
    }
  }
}

resource "azurerm_vm" "vm1" {
  name = "my-vm1"
  location = var.location
  resource_group_name = azurerm_lb.lb.resource_group_name
  network_interface_ids = [azurerm_network_interface.vm1_nic.id]
  vm_size = "Standard_DS2_v2"
}

resource "azurerm_vm" "vm2" {
  name = "my-vm2"
  location = var.location
  resource_group_name = azurerm_lb.lb.resource_group_name
  network_interface_ids = [azurerm_network_interface.vm2_nic.id]
  vm_size = "Standard_DS2_v2"
}

resource "azurerm_lb_backend_address_pool_address" "vm1_backend_address" {
  lb_backend_address_pool_id = azurerm_lb.lb.backend_address_pools[0].id
  network_interface_id = azurerm_network_interface.vm1_nic.id
  private_ip_address = azurerm_network_interface.vm1_nic.primary_private_ip_address
}

resource "azurerm_lb_backend_address_pool_address" "vm2_backend_address" {
  lb_backend_address_pool_id = azurerm_lb.lb.backend_address_pools[0].id
  network_interface_id = azurerm_network_interface.vm2_nic.id
  private_ip_address = azurerm_network_interface.vm2_nic.primary_private_ip_address
}

resource "azurerm_lb_rule" "http_rule" {
  name = "my-http-rule"
  lb_id = azurerm_lb.lb.id
  protocol = "Http"
  frontend_port = 80
  backend_port = 80
  frontend_ip_configuration_ids = [azurerm_lb_frontend_ip_configuration.lb_frontend_ip.id]
  backend_address_pool_ids = [azurerm_lb_backend_address_pool.lb_backend_address_pool.id]
}