Skip to content

Commit a8e75fc

Browse files
committed
cdn template
1 parent 6f1a506 commit a8e75fc

8 files changed

Lines changed: 282 additions & 1 deletion

File tree

11_media-services/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Last updated: 2026-02-09
1010
------------------------------------------
1111

1212
> [!IMPORTANT]
13-
> TThis folder contains sample Terraform templates for Azure media services. These templates are starting points and should be customized based on your application needs.
13+
> This folder contains sample Terraform templates for Azure media services. These templates are starting points and should be customized based on your application needs.
14+
15+
## Templates
16+
17+
- [cdn](./cdn)
1418

1519
<!-- START BADGE -->
1620
<div align="center">

11_media-services/cdn/.terraform-provider-schema.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

11_media-services/cdn/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Terraform Template - CDN (Azure 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: 2026-02-10
9+
10+
------------------------------------------
11+
12+
> This template contains Terraform configurations to create an Azure Front Door (Standard/Premium) profile and endpoint suitable for serving media assets (for example, fronting a storage/web origin).
13+
14+
> [!NOTE]
15+
> Azure CDN (classic) profiles (for example `Standard_Microsoft`) no longer support new profile creation. This template uses the modern Azure Front Door resources (`azurerm_cdn_frontdoor_*`).
16+
> The modern replacement for “Microsoft-managed global CDN + edge routing” is Azure Front Door Standard/Premium. It provides the CDN capability, but it’s provisioned via azurerm_cdn_frontdoor_* resources (Front Door profile/endpoint/route/origin), not azurerm_cdn_profile. <br/>
17+
> - If you already have classic CDN resources: Terraform can often still manage them.
18+
> - If you’re creating new: you generally need Front Door Standard/Premium (or another supported CDN provider SKU where available), because classic Microsoft CDN can’t be created anymore.
19+
20+
## File Descriptions
21+
22+
- **main.tf**: Creates the Resource Group, Front Door Profile, Endpoint, Origin Group, Origin, and a default Route.
23+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
24+
- **provider.tf**: Configures the Azure provider (uses Azure CLI auth context).
25+
- **terraform.tfvars**: Provides example values for the variables defined in `variables.tf`.
26+
- **outputs.tf**: Defines outputs such as CDN profile ID, endpoint ID, and endpoint host name.
27+
28+
## Variables
29+
30+
| Variable Name | Description | Type | Example Value |
31+
| --- | --- | --- | --- |
32+
| `resource_group_name` | The name of the resource group to create. | string | `"rg-media-services-dev"` |
33+
| `location` | Azure region for deployment. | string | `"East US"` |
34+
| `cdn_profile_name` | Front Door profile name. | string | `"cdn-media-services-dev-001"` |
35+
| `cdn_sku` | Front Door profile SKU. | string | `"Standard_AzureFrontDoor"` |
36+
| `cdn_endpoint_name` | Front Door endpoint name. | string | `"cdn-media-dev-001"` |
37+
| `origin_host` | Origin hostname (no scheme/path). | string | `"myorigin.example.com"` |
38+
| `tags` | Tags applied to supported resources. | map(string) | `{ env = "dev" }` |
39+
40+
## Usage
41+
42+
1. Authenticate:
43+
44+
```sh
45+
az login
46+
```
47+
48+
2. (Optional) Select subscription:
49+
50+
```sh
51+
az account set --subscription "<subscription-id-or-name>"
52+
```
53+
54+
3. Initialize:
55+
56+
```sh
57+
terraform init -upgrade
58+
```
59+
60+
4. Validate and plan:
61+
62+
```sh
63+
terraform validate
64+
terraform plan
65+
```
66+
67+
5. Apply:
68+
69+
```sh
70+
terraform apply -auto-approve
71+
```
72+
73+
## Outputs
74+
75+
| Output Name | Description |
76+
| --- | --- |
77+
| `cdn_profile_id` | The ID of the CDN profile. |
78+
| `cdn_endpoint_id` | The ID of the CDN endpoint. |
79+
| `cdn_endpoint_host_name` | The host name (FQDN) of the CDN endpoint. |
80+
81+
<!-- START BADGE -->
82+
<div align="center">
83+
<img src="https://img.shields.io/badge/Total%20views-1646-limegreen" alt="Total views">
84+
<p>Refresh Date: 2026-02-10</p>
85+
</div>
86+
<!-- END BADGE -->

11_media-services/cdn/main.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# main.tf
2+
# This file contains the main configuration for creating an Azure Front Door (Standard/Premium)
3+
# profile and endpoint (Azure CDN/Front Door modern offering).
4+
5+
resource "azurerm_resource_group" "cdn" {
6+
name = var.resource_group_name
7+
location = var.location
8+
9+
tags = var.tags
10+
}
11+
12+
resource "azurerm_cdn_frontdoor_profile" "cdn" {
13+
name = var.cdn_profile_name
14+
resource_group_name = azurerm_resource_group.cdn.name
15+
sku_name = var.cdn_sku
16+
17+
tags = var.tags
18+
}
19+
20+
resource "azurerm_cdn_frontdoor_endpoint" "cdn" {
21+
name = var.cdn_endpoint_name
22+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.cdn.id
23+
24+
tags = var.tags
25+
}
26+
27+
resource "azurerm_cdn_frontdoor_origin_group" "cdn" {
28+
name = "${var.cdn_endpoint_name}-og"
29+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.cdn.id
30+
31+
load_balancing {
32+
additional_latency_in_milliseconds = 50
33+
sample_size = 4
34+
successful_samples_required = 3
35+
}
36+
}
37+
38+
resource "azurerm_cdn_frontdoor_origin" "cdn" {
39+
name = "origin1"
40+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.cdn.id
41+
42+
enabled = true
43+
certificate_name_check_enabled = false
44+
45+
host_name = var.origin_host
46+
origin_host_header = var.origin_host
47+
http_port = 80
48+
https_port = 443
49+
50+
priority = 1
51+
weight = 500
52+
}
53+
54+
resource "azurerm_cdn_frontdoor_route" "cdn" {
55+
name = "${var.cdn_endpoint_name}-route"
56+
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.cdn.id
57+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.cdn.id
58+
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.cdn.id]
59+
60+
enabled = true
61+
62+
forwarding_protocol = "HttpsOnly"
63+
https_redirect_enabled = true
64+
patterns_to_match = ["/*"]
65+
supported_protocols = ["Http", "Https"]
66+
67+
link_to_default_domain = true
68+
}

11_media-services/cdn/outputs.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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_frontdoor_profile.cdn.id
7+
}
8+
9+
output "cdn_endpoint_id" {
10+
description = "The ID of the CDN endpoint."
11+
value = azurerm_cdn_frontdoor_endpoint.cdn.id
12+
}
13+
14+
output "cdn_endpoint_host_name" {
15+
description = "The host name (FQDN) of the CDN endpoint."
16+
value = azurerm_cdn_frontdoor_endpoint.cdn.host_name
17+
}

11_media-services/cdn/provider.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
4+
terraform {
5+
required_version = ">= 1.8, < 2.0"
6+
7+
required_providers {
8+
azurerm = {
9+
source = "hashicorp/azurerm"
10+
version = "~> 3.116"
11+
}
12+
}
13+
}
14+
15+
provider "azurerm" {
16+
features {
17+
resource_group {
18+
prevent_deletion_if_contains_resources = false
19+
}
20+
}
21+
22+
# Uses the current Azure CLI context (az login + az account set)
23+
skip_provider_registration = false
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Example values for the Azure CDN template (Media Services).
2+
3+
resource_group_name = "rg-media-services-dev"
4+
location = "East US"
5+
6+
cdn_profile_name = "cdn-media-services-dev-001"
7+
cdn_sku = "Standard_AzureFrontDoor"
8+
cdn_endpoint_name = "cdn-media-dev-001"
9+
10+
# Example: storage or web origin hostname (no scheme, no path)
11+
origin_host = "myorigin.example.com"
12+
13+
tags = {
14+
env = "dev"
15+
app = "media-services"
16+
owner = "terraform"
17+
}

11_media-services/cdn/variables.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
4+
variable "resource_group_name" {
5+
description = "The name of the resource group to create."
6+
type = string
7+
8+
validation {
9+
condition = length(trimspace(var.resource_group_name)) > 0
10+
error_message = "resource_group_name must not be empty."
11+
}
12+
}
13+
14+
variable "location" {
15+
description = "The Azure region where resources will be created."
16+
type = string
17+
18+
validation {
19+
condition = length(trimspace(var.location)) > 0
20+
error_message = "location must not be empty."
21+
}
22+
}
23+
24+
variable "cdn_profile_name" {
25+
description = "The name of the Front Door Profile."
26+
type = string
27+
28+
validation {
29+
condition = length(trimspace(var.cdn_profile_name)) > 0
30+
error_message = "cdn_profile_name must not be empty."
31+
}
32+
}
33+
34+
variable "cdn_sku" {
35+
description = "The SKU for the Front Door Profile. Possible values: Standard_AzureFrontDoor, Premium_AzureFrontDoor."
36+
type = string
37+
default = "Standard_AzureFrontDoor"
38+
}
39+
40+
variable "cdn_endpoint_name" {
41+
description = "The name of the Front Door Endpoint."
42+
type = string
43+
44+
validation {
45+
condition = length(trimspace(var.cdn_endpoint_name)) > 0
46+
error_message = "cdn_endpoint_name must not be empty."
47+
}
48+
}
49+
50+
variable "origin_host" {
51+
description = "The hostname of the origin server (for example a Storage endpoint, App Service, or any HTTPS origin)."
52+
type = string
53+
54+
validation {
55+
condition = length(trimspace(var.origin_host)) > 0
56+
error_message = "origin_host must not be empty."
57+
}
58+
}
59+
60+
variable "tags" {
61+
description = "A map of tags to assign to supported resources."
62+
type = map(string)
63+
default = {}
64+
}

0 commit comments

Comments
 (0)