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
62 changes: 62 additions & 0 deletions 3_networking/cdn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Terraform Template - Azure CDN (Content Delivery Network)

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-13

----------

> This template contains Terraform configurations to create and manage an Azure CDN profile and endpoint.

<p align="center">
<img width="700" alt="image" src="https://github.com/user-attachments/assets/57af5973-c81e-48df-98d9-80957e0f7207">
</p>


## File Descriptions

- **main.tf**: Contains the main configuration for creating the Azure CDN profile and endpoint.
- **variables.tf**: Defines the input variables used in the Terraform configuration.
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
- **outputs.tf**: Defines the outputs such as CDN profile ID and endpoint host name.

## Variables

| Variable Name | Description | Type | Example Value |
|---------------------- |--------------------------------------------------|--------|-----------------------------|
| `subscription_id` | The Azure subscription ID | string | `"00000000-0000-0000-0000-000000000000"` |
| `resource_group_name` | The name of the resource group | string | `"RG-cdn-test"` |
| `location` | The Azure region to deploy resources | string | `"eastus"` |
| `cdn_profile_name` | The name of the CDN profile | string | `"mycdnprofile"` |
| `cdn_sku` | The SKU for the CDN profile | string | `"Standard_Microsoft"` |
| `cdn_endpoint_name` | The name of the CDN endpoint | string | `"mycdnendpoint"` |
| `origin_host` | The hostname of the origin server | string | `"myorigin.example.com"` |
| `tags` | A map of tags to assign to resources | map | `{ Environment = "CDN", Owner = "IT" }` |

## Usage

1. Clone the repository and navigate to the cdn 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 |
|-------------------------|---------------------------------------------|
| `cdn_profile_id` | The ID of the CDN profile |
| `cdn_endpoint_id` | The ID of the CDN endpoint |
| `cdn_endpoint_host_name`| The host name of the CDN endpoint |

<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>
35 changes: 35 additions & 0 deletions 3_networking/cdn/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# main.tf
# This file contains the main configuration for creating an Azure CDN Profile and Endpoint.

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

# CDN Profile
resource "azurerm_cdn_profile" "cdn" {
name = var.cdn_profile_name
location = azurerm_resource_group.cdn.location
resource_group_name = azurerm_resource_group.cdn.name
sku = var.cdn_sku
tags = var.tags
}

# CDN Endpoint
resource "azurerm_cdn_endpoint" "cdn" {
name = var.cdn_endpoint_name
profile_name = azurerm_cdn_profile.cdn.name
location = azurerm_resource_group.cdn.location
resource_group_name = azurerm_resource_group.cdn.name
origin_host_header = var.origin_host
is_http_allowed = true
is_https_allowed = true

origin {
name = "origin1"
host_name = var.origin_host
http_port = 80
https_port = 443
}
}
12 changes: 12 additions & 0 deletions 3_networking/cdn/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 Azure CDN configuration.

output "cdn_profile_id" {
description = "The ID of the CDN profile"
value = azurerm_cdn_profile.cdn.id
}

output "cdn_endpoint_id" {
description = "The ID of the CDN endpoint"
value = azurerm_cdn_endpoint.cdn.id
}
19 changes: 19 additions & 0 deletions 3_networking/cdn/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
}
20 changes: 20 additions & 0 deletions 3_networking/cdn/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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-cdn-test"
location = "eastus"

# CDN Configuration
cdn_profile_name = "mycdnprofiletestbr"
cdn_sku = "Standard_Microsoft"
cdn_endpoint_name = "mycdnendpointtestbr"
origin_host = "myorigintestbr.example.com"
tags = {
Environment = "CDN"
Owner = "IT"
}
44 changes: 44 additions & 0 deletions 3_networking/cdn/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 to deploy resources"
type = string
}

variable "cdn_profile_name" {
description = "The name of the CDN profile"
type = string
}

variable "cdn_sku" {
description = "The SKU for the CDN profile (Standard_Microsoft, Standard_Akamai, Standard_Verizon, Premium_Verizon)"
type = string
default = "Standard_Microsoft"
}

variable "cdn_endpoint_name" {
description = "The name of the CDN endpoint"
type = string
}

variable "origin_host" {
description = "The hostname of the origin server"
type = string
}

variable "tags" {
description = "A map of tags to assign to resources"
type = map(string)
default = {}
}