Skip to content

Commit 15a7c8d

Browse files
authored
Merge 271d794 into d7e8670
2 parents d7e8670 + 271d794 commit 15a7c8d

File tree

6 files changed

+302
-0
lines changed

6 files changed

+302
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Terraform Template - Azure Load Balancer
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-06-12
9+
10+
----------
11+
12+
> This template contains Terraform configurations to create and manage an Azure Load Balancer with its associated components including public IP, backend pool, health probe, and load balancing rules.
13+
14+
> [!NOTE]
15+
> The Load Balancer configuration uses Standard SKU which provides enhanced features and scalability compared to Basic SKU.
16+
17+
<p align="center">
18+
<img width="750" alt="image" src="https://github.com/user-attachments/assets/b4f46023-3b27-4ff3-a637-dfc9deedf4aa">
19+
</p>
20+
21+
## File Descriptions
22+
23+
- **main.tf**: Contains the main configuration for creating the Azure Load Balancer and its associated resources.
24+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
25+
- **provider.tf**: Configures the Azure provider to interact with Azure resources.
26+
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
27+
- **outputs.tf**: Defines the outputs such as Load Balancer ID and public IP address.
28+
29+
## Variables
30+
31+
> Below is a list of variables used in this template, their expected values, types, and examples:
32+
33+
| Variable Name | Description | Type | Example Value |
34+
|--------------|-------------|------|---------------|
35+
| `subscription_id` | The Azure subscription ID | string | `"your-subscription-id"` |
36+
| `resource_group_name` | The name of the resource group | string | `"my-resource-group"` |
37+
| `location` | The Azure region to deploy resources | string | `"eastus"` |
38+
| `load_balancer_name` | The name of the load balancer | string | `"my-load-balancer"` |
39+
| `public_ip_name` | The name of the public IP address | string | `"my-lb-public-ip"` |
40+
| `frontend_ip_configuration_name` | Name of the frontend IP configuration | string | `"frontend-ip-config"` |
41+
| `backend_pool_name` | Name of the backend address pool | string | `"backend-pool"` |
42+
| `health_probe_name` | Name of the health probe | string | `"health-probe"` |
43+
| `lb_rule_name` | Name of the load balancer rule | string | `"lb-rule"` |
44+
| `lb_sku` | SKU of the load balancer | string | `"Standard"` |
45+
| `probe_protocol` | Protocol for health probe | string | `"Tcp"` |
46+
| `probe_port` | Port for health probe | number | `80` |
47+
| `frontend_port` | Frontend port for load balancer rule | number | `80` |
48+
| `backend_port` | Backend port for load balancer rule | number | `80` |
49+
| `tags` | Tags to apply to all resources | map | `{ "Environment": "Production" }` |
50+
51+
## Usage
52+
53+
1. Clone the repository and navigate to the load balancer directory
54+
2. Update the `terraform.tfvars` file with your values
55+
3. Initialize and apply the Terraform configuration:
56+
57+
```bash
58+
terraform init
59+
terraform plan
60+
terraform apply
61+
```
62+
63+
## Outputs
64+
65+
| Output Name | Description |
66+
|-------------|-------------|
67+
| `load_balancer_id` | The ID of the Load Balancer |
68+
| `public_ip_address` | The public IP address of the Load Balancer |
69+
| `backend_pool_id` | The ID of the Backend Address Pool |
70+
| `frontend_ip_configuration_id` | The ID of the Frontend IP Configuration |
71+
72+
<div align="center">
73+
<h3 style="color: #4CAF50;">Total Visitors</h3>
74+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
75+
</div>

3_networking/load-balancer/main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# main.tf
2+
# This file contains the main configuration for creating the Azure Load Balancer and its associated resources.
3+
4+
# Resource Group for Load Balancer
5+
resource "azurerm_resource_group" "lb" {
6+
name = var.resource_group_name
7+
location = var.location
8+
tags = var.tags
9+
}
10+
11+
# Public IP for Load Balancer
12+
resource "azurerm_public_ip" "lb" {
13+
name = var.public_ip_name
14+
location = azurerm_resource_group.lb.location
15+
resource_group_name = azurerm_resource_group.lb.name
16+
allocation_method = "Static"
17+
sku = var.lb_sku
18+
tags = var.tags
19+
}
20+
21+
# Azure Load Balancer
22+
resource "azurerm_lb" "lb" {
23+
name = var.load_balancer_name
24+
location = azurerm_resource_group.lb.location
25+
resource_group_name = azurerm_resource_group.lb.name
26+
sku = var.lb_sku
27+
28+
frontend_ip_configuration {
29+
name = var.frontend_ip_configuration_name
30+
public_ip_address_id = azurerm_public_ip.lb.id
31+
}
32+
33+
tags = var.tags
34+
}
35+
36+
# Backend Address Pool for Load Balancer
37+
resource "azurerm_lb_backend_address_pool" "lb" {
38+
name = var.backend_pool_name
39+
loadbalancer_id = azurerm_lb.lb.id
40+
}
41+
42+
# Health Probe for Load Balancer
43+
resource "azurerm_lb_probe" "lb" {
44+
name = var.health_probe_name
45+
loadbalancer_id = azurerm_lb.lb.id
46+
protocol = var.probe_protocol
47+
port = var.probe_port
48+
interval_in_seconds = 15
49+
number_of_probes = 2
50+
}
51+
52+
# Load Balancer Rule
53+
resource "azurerm_lb_rule" "lb" {
54+
name = var.lb_rule_name
55+
loadbalancer_id = azurerm_lb.lb.id
56+
protocol = "Tcp"
57+
frontend_port = var.frontend_port
58+
backend_port = var.backend_port
59+
frontend_ip_configuration_name = var.frontend_ip_configuration_name
60+
backend_address_pool_ids = [azurerm_lb_backend_address_pool.lb.id]
61+
probe_id = azurerm_lb_probe.lb.id
62+
enable_floating_ip = false
63+
idle_timeout_in_minutes = 4
64+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# outputs.tf
2+
# This file defines the outputs of the Terraform configuration.
3+
4+
output "resource_group_name" {
5+
value = azurerm_resource_group.lb.name
6+
}
7+
8+
output "load_balancer_id" {
9+
description = "The ID of the Load Balancer"
10+
value = azurerm_lb.lb.id
11+
}
12+
13+
output "public_ip_address" {
14+
description = "The public IP address of the Load Balancer"
15+
value = azurerm_public_ip.lb.ip_address
16+
}
17+
18+
output "backend_pool_id" {
19+
description = "The ID of the Backend Address Pool"
20+
value = azurerm_lb_backend_address_pool.lb.id
21+
}
22+
23+
output "frontend_ip_configuration_id" {
24+
description = "The ID of the Frontend IP Configuration"
25+
value = azurerm_lb.lb.frontend_ip_configuration[0].id
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
# It specifies the required provider and its version, along with provider-specific configurations.
4+
5+
terraform {
6+
required_version = ">= 1.8, < 2.0"
7+
# Specify the required provider and its version
8+
required_providers {
9+
azurerm = {
10+
source = "hashicorp/azurerm" # Source of the AzureRM provider
11+
version = "~> 4.16.0" # Version of the AzureRM provider
12+
}
13+
}
14+
}
15+
16+
provider "azurerm" {
17+
features {} # Enable all features for the AzureRM provider
18+
subscription_id = var.subscription_id # Use the subscription ID variable
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# terraform.tfvars
2+
# This file provides default values for the variables defined in variables.tf.
3+
# These values can be overridden by specifying different values during Terraform execution.
4+
5+
# Azure Subscription
6+
subscription_id = ""
7+
8+
# Resource Group
9+
resource_group_name = "your-resource-group-name"
10+
location = "eastus"
11+
12+
# Load Balancer Configuration
13+
load_balancer_name = "my-load-balancer"
14+
public_ip_name = "my-lb-public-ip"
15+
frontend_ip_configuration_name = "frontend-ip-config"
16+
backend_pool_name = "backend-pool"
17+
health_probe_name = "health-probe"
18+
lb_rule_name = "lb-rule"
19+
lb_sku = "Standard"
20+
probe_protocol = "Tcp"
21+
probe_port = 80
22+
frontend_port = 80
23+
backend_port = 80
24+
25+
# Tags
26+
tags = {
27+
Environment = "Production"
28+
Project = "MyProject"
29+
Owner = "TeamName"
30+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
# Each variable includes a description and type.
4+
5+
variable "subscription_id" {
6+
description = "The Azure subscription ID"
7+
type = string
8+
}
9+
10+
variable "resource_group_name" {
11+
description = "The name of the resource group"
12+
type = string
13+
}
14+
15+
variable "location" {
16+
description = "The Azure region to deploy resources"
17+
type = string
18+
}
19+
20+
variable "load_balancer_name" {
21+
description = "The name of the load balancer"
22+
type = string
23+
}
24+
25+
variable "public_ip_name" {
26+
description = "The name of the public IP address"
27+
type = string
28+
}
29+
30+
variable "frontend_ip_configuration_name" {
31+
description = "Name of the frontend IP configuration"
32+
type = string
33+
default = "frontend-ip-config"
34+
}
35+
36+
variable "backend_pool_name" {
37+
description = "Name of the backend address pool"
38+
type = string
39+
default = "backend-pool"
40+
}
41+
42+
variable "health_probe_name" {
43+
description = "Name of the health probe"
44+
type = string
45+
default = "health-probe"
46+
}
47+
48+
variable "lb_rule_name" {
49+
description = "Name of the load balancer rule"
50+
type = string
51+
default = "lb-rule"
52+
}
53+
54+
variable "lb_sku" {
55+
description = "SKU of the load balancer (Basic or Standard)"
56+
type = string
57+
default = "Standard"
58+
}
59+
60+
variable "probe_protocol" {
61+
description = "Protocol for health probe"
62+
type = string
63+
default = "Tcp"
64+
}
65+
66+
variable "probe_port" {
67+
description = "Port for health probe"
68+
type = number
69+
default = 80
70+
}
71+
72+
variable "frontend_port" {
73+
description = "Frontend port for load balancer rule"
74+
type = number
75+
default = 80
76+
}
77+
78+
variable "backend_port" {
79+
description = "Backend port for load balancer rule"
80+
type = number
81+
default = 80
82+
}
83+
84+
variable "tags" {
85+
description = "Tags to apply to all resources"
86+
type = map(string)
87+
default = {}
88+
}

0 commit comments

Comments
 (0)