Untitled
unknown
plain_text
2 years ago
1.7 kB
11
Indexable
provider "azurerm" {
subscription_id = var.subscription_id
client_id = var.client_id
client_secret = var.client_secret
tenant_id = var.tenant_id
}
resource "azurerm_lb" "lb" {
name = "example-lb"
location = var.location
frontend_ip_configurations {
name = "example-fip"
public_ip_address {
name = "example-pip"
allocation_method = "Dynamic"
}
}
backend_address_pools {
name = "example-backend-pool"
}
load_balancing_rules {
name = "example-rule"
frontend_port = 80
backend_port = 80
frontend_ip_configuration_ids = [azurerm_lb.lb.frontend_ip_configurations[0].id]
backend_address_pool_ids = [azurerm_lb.lb.backend_address_pools[0].id]
}
}
resource "azurerm_vm" "vm" {
count = var.vm_count
name = "example-vm-${count.index}"
location = var.location
resource_group_name = azurerm_lb.lb.resource_group_name
vm_size = "Standard_D2s_v3"
network_interface_ids = [azurerm_network_interface.nic-${count.index}.id]
}
resource "azurerm_network_interface" "nic" {
count = var.vm_count
name = "example-nic-${count.index}"
location = var.location
resource_group_name = azurerm_lb.lb.resource_group_name
ip_configurations {
name = "example-ipconfig-${count.index}"
public_ip_address_allocation = "Dynamic"
load_balancer_backend_address_pool_ids = [azurerm_lb.lb.backend_address_pools[0].id]
}
}
output "lb_public_ip" {
value = azurerm_lb.lb.frontend_ip_configurations[0].public_ip_address.ip_address
}
output "vm_ip_addresses" {
value = azurerm_network_interface.nic[*].ip_configurations[*].private_ip_address
}Editor is loading...