Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions 3_networking/traffic-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Terraform Template - Azure Traffic Manager

Costa Rica

[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-06-12

----------

> This template contains Terraform configurations to create and manage an Azure Traffic Manager profile, including DNS configuration and endpoint monitoring.

> [!NOTE]
> This Traffic Manager configuration uses best practices for routing, monitoring, and DNS setup.

<p align="center">
<img width="550" alt="image" src="https://github.com/user-attachments/assets/32680750-b3c9-4149-b0a9-677bcaccffca">
</p>

## File Descriptions

- **main.tf**: Contains the main configuration for creating the Azure Traffic Manager profile and its associated resources.
- **variables.tf**: Defines the input variables used in the Terraform configuration.
- **provider.tf**: Configures the Azure provider to interact with Azure resources.
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
- **outputs.tf**: Defines the outputs such as Traffic Manager profile ID and FQDN.

## Variables

Below is a list of variables used in this template, their expected values, types, and examples:

| Variable Name | Description | Type | Example Value |
|------------------------ |-------------------------------------------------------|--------------|----------------------|
| `resource_group_name` | The name of the resource group | string | `"tm-resource-group"` |
| `location` | The Azure region for the resource group | string | `"eastus"` |
| `traffic_manager_name` | The name of the Traffic Manager profile | string | `"my-tm-profile"` |
| `traffic_routing_method`| The traffic routing method (Performance, Priority, etc.) | string | `"Performance"` |
| `dns_name` | The relative DNS name for the Traffic Manager profile | string | `"mytmprofile"` |
| `ttl` | The DNS Time-To-Live (TTL) in seconds | number | `30` |
| `monitor_protocol` | The protocol used for endpoint monitoring | string | `"HTTP"` |
| `monitor_port` | The port used for endpoint monitoring | number | `80` |
| `monitor_path` | The path used for endpoint monitoring | string | `"/"` |

## Usage

1. Clone the repository and navigate to the traffic-manager directory.
2. Update the `terraform.tfvars` file with your values.
3. Initialize and apply the Terraform configuration:

```bash
terraform init
terraform plan
terraform apply
```

## Outputs

| Output Name | Description |
|----------------------------|---------------------------------------------|
| `traffic_manager_profile_id` | The ID of the Traffic Manager profile |
| `traffic_manager_fqdn` | The FQDN of the Traffic Manager profile |

<div align="center">
<h3 style="color: #4CAF50;">Total Visitors</h3>
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
</div>
28 changes: 28 additions & 0 deletions 3_networking/traffic-manager/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# main.tf
# This file contains the main configuration for creating an Azure Traffic Manager profile.

# Resource Group
resource "azurerm_resource_group" "tm" {
name = var.resource_group_name
location = var.location
}

# Traffic Manager Profile
resource "azurerm_traffic_manager_profile" "tm" {
name = var.traffic_manager_name
resource_group_name = azurerm_resource_group.tm.name
traffic_routing_method = var.traffic_routing_method

dns_config {
relative_name = var.dns_name
ttl = var.ttl
}

monitor_config {
protocol = var.monitor_protocol
port = var.monitor_port
path = var.monitor_path
}

# Add endpoints as needed using azurerm_traffic_manager_endpoint resources
}
12 changes: 12 additions & 0 deletions 3_networking/traffic-manager/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# outputs.tf
# This file defines the outputs for the Traffic Manager configuration.

output "traffic_manager_profile_id" {
description = "The ID of the Traffic Manager profile"
value = azurerm_traffic_manager_profile.tm.id
}

output "traffic_manager_fqdn" {
description = "The FQDN of the Traffic Manager profile"
value = azurerm_traffic_manager_profile.tm.fqdn
}
19 changes: 19 additions & 0 deletions 3_networking/traffic-manager/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# provider.tf
# This file configures the Azure provider to interact with Azure resources.
# It specifies the required provider and its version, along with provider-specific configurations.

terraform {
required_version = ">= 1.8, < 2.0"
# Specify the required provider and its version
required_providers {
azurerm = {
source = "hashicorp/azurerm" # Source of the AzureRM provider
version = "~> 4.16.0" # Version of the AzureRM provider
}
}
}

provider "azurerm" {
features {} # Enable all features for the AzureRM provider
subscription_id = var.subscription_id # Use the subscription ID variable
}
19 changes: 19 additions & 0 deletions 3_networking/traffic-manager/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# terraform.tfvars
# This file provides default values for the variables defined in variables.tf.
# These values can be overridden by specifying different values during Terraform execution.

# Azure Subscription
subscription_id = "" # your-subscription-id

# Resource Group
resource_group_name = "RG-trafficmanager-test" # your-resource-group-name
location = "eastus"

# Traffic Manager Configuration
traffic_manager_name = "my-tm-profile"
traffic_routing_method = "Performance"
dns_name = "mytmprofilebrowntest"
ttl = 30
monitor_protocol = "HTTP"
monitor_port = 80
monitor_path = "/"
57 changes: 57 additions & 0 deletions 3_networking/traffic-manager/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# variables.tf
# This file defines the input variables used in the Terraform configuration.

variable "subscription_id" {
description = "The Azure subscription ID"
type = string
}

variable "resource_group_name" {
description = "The name of the resource group"
type = string
}

variable "location" {
description = "The Azure region for the resource group"
type = string
}

variable "traffic_manager_name" {
description = "The name of the Traffic Manager profile"
type = string
}

variable "traffic_routing_method" {
description = "The traffic routing method (e.g., Performance, Priority, Weighted, Geographic, MultiValue, Subnet)"
type = string
default = "Performance"
}

variable "dns_name" {
description = "The relative DNS name for the Traffic Manager profile"
type = string
}

variable "ttl" {
description = "The DNS Time-To-Live (TTL) in seconds"
type = number
default = 30
}

variable "monitor_protocol" {
description = "The protocol used for endpoint monitoring (HTTP, HTTPS, TCP)"
type = string
default = "HTTP"
}

variable "monitor_port" {
description = "The port used for endpoint monitoring"
type = number
default = 80
}

variable "monitor_path" {
description = "The path used for endpoint monitoring"
type = string
default = "/"
}