Skip to content

Commit 72b87e6

Browse files
authored
Merge pull request #32 from MicrosoftCloudEssentials-LearningHub/cdn
cdn sample template
2 parents 476bb07 + d5831a9 commit 72b87e6

File tree

6 files changed

+192
-0
lines changed

6 files changed

+192
-0
lines changed

3_networking/cdn/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Terraform Template - Azure CDN (Content Delivery Network)
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-13
9+
10+
----------
11+
12+
> This template contains Terraform configurations to create and manage an Azure CDN profile and endpoint.
13+
14+
<p align="center">
15+
<img width="700" alt="image" src="https://github.com/user-attachments/assets/57af5973-c81e-48df-98d9-80957e0f7207">
16+
</p>
17+
18+
19+
## File Descriptions
20+
21+
- **main.tf**: Contains the main configuration for creating the Azure CDN profile and endpoint.
22+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
23+
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
24+
- **outputs.tf**: Defines the outputs such as CDN profile ID and endpoint host name.
25+
26+
## Variables
27+
28+
| Variable Name | Description | Type | Example Value |
29+
|---------------------- |--------------------------------------------------|--------|-----------------------------|
30+
| `subscription_id` | The Azure subscription ID | string | `"00000000-0000-0000-0000-000000000000"` |
31+
| `resource_group_name` | The name of the resource group | string | `"RG-cdn-test"` |
32+
| `location` | The Azure region to deploy resources | string | `"eastus"` |
33+
| `cdn_profile_name` | The name of the CDN profile | string | `"mycdnprofile"` |
34+
| `cdn_sku` | The SKU for the CDN profile | string | `"Standard_Microsoft"` |
35+
| `cdn_endpoint_name` | The name of the CDN endpoint | string | `"mycdnendpoint"` |
36+
| `origin_host` | The hostname of the origin server | string | `"myorigin.example.com"` |
37+
| `tags` | A map of tags to assign to resources | map | `{ Environment = "CDN", Owner = "IT" }` |
38+
39+
## Usage
40+
41+
1. Clone the repository and navigate to the cdn directory.
42+
2. Update the `terraform.tfvars` file with your values.
43+
3. Initialize and apply the Terraform configuration:
44+
45+
```bash
46+
terraform init
47+
terraform plan
48+
terraform apply
49+
```
50+
51+
## Outputs
52+
53+
| Output Name | Description |
54+
|-------------------------|---------------------------------------------|
55+
| `cdn_profile_id` | The ID of the CDN profile |
56+
| `cdn_endpoint_id` | The ID of the CDN endpoint |
57+
| `cdn_endpoint_host_name`| The host name of the CDN endpoint |
58+
59+
<div align="center">
60+
<h3 style="color: #4CAF50;">Total Visitors</h3>
61+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
62+
</div>

3_networking/cdn/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# main.tf
2+
# This file contains the main configuration for creating an Azure CDN Profile and Endpoint.
3+
4+
# Resource Group
5+
resource "azurerm_resource_group" "cdn" {
6+
name = var.resource_group_name
7+
location = var.location
8+
}
9+
10+
# CDN Profile
11+
resource "azurerm_cdn_profile" "cdn" {
12+
name = var.cdn_profile_name
13+
location = azurerm_resource_group.cdn.location
14+
resource_group_name = azurerm_resource_group.cdn.name
15+
sku = var.cdn_sku
16+
tags = var.tags
17+
}
18+
19+
# CDN Endpoint
20+
resource "azurerm_cdn_endpoint" "cdn" {
21+
name = var.cdn_endpoint_name
22+
profile_name = azurerm_cdn_profile.cdn.name
23+
location = azurerm_resource_group.cdn.location
24+
resource_group_name = azurerm_resource_group.cdn.name
25+
origin_host_header = var.origin_host
26+
is_http_allowed = true
27+
is_https_allowed = true
28+
29+
origin {
30+
name = "origin1"
31+
host_name = var.origin_host
32+
http_port = 80
33+
https_port = 443
34+
}
35+
}

3_networking/cdn/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# outputs.tf
2+
# This file defines the outputs for the Azure CDN configuration.
3+
4+
output "cdn_profile_id" {
5+
description = "The ID of the CDN profile"
6+
value = azurerm_cdn_profile.cdn.id
7+
}
8+
9+
output "cdn_endpoint_id" {
10+
description = "The ID of the CDN endpoint"
11+
value = azurerm_cdn_endpoint.cdn.id
12+
}

3_networking/cdn/provider.tf

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+
}

3_networking/cdn/terraform.tfvars

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 = "" # "your-subscription-id"
7+
8+
# Resource Group
9+
resource_group_name = "RG-cdn-test"
10+
location = "eastus"
11+
12+
# CDN Configuration
13+
cdn_profile_name = "mycdnprofiletestbr"
14+
cdn_sku = "Standard_Microsoft"
15+
cdn_endpoint_name = "mycdnendpointtestbr"
16+
origin_host = "myorigintestbr.example.com"
17+
tags = {
18+
Environment = "CDN"
19+
Owner = "IT"
20+
}

3_networking/cdn/variables.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
4+
variable "subscription_id" {
5+
description = "The Azure subscription ID"
6+
type = string
7+
}
8+
9+
variable "resource_group_name" {
10+
description = "The name of the resource group"
11+
type = string
12+
}
13+
14+
variable "location" {
15+
description = "The Azure region to deploy resources"
16+
type = string
17+
}
18+
19+
variable "cdn_profile_name" {
20+
description = "The name of the CDN profile"
21+
type = string
22+
}
23+
24+
variable "cdn_sku" {
25+
description = "The SKU for the CDN profile (Standard_Microsoft, Standard_Akamai, Standard_Verizon, Premium_Verizon)"
26+
type = string
27+
default = "Standard_Microsoft"
28+
}
29+
30+
variable "cdn_endpoint_name" {
31+
description = "The name of the CDN endpoint"
32+
type = string
33+
}
34+
35+
variable "origin_host" {
36+
description = "The hostname of the origin server"
37+
type = string
38+
}
39+
40+
variable "tags" {
41+
description = "A map of tags to assign to resources"
42+
type = map(string)
43+
default = {}
44+
}

0 commit comments

Comments
 (0)