Skip to content

Commit f6fc3ba

Browse files
Merge pull request #234309 from TomArcherMsft/UserStory60501-cdn-with-custom-origin
User Story 60501: CDN Profile & Endpoint
2 parents da37d61 + 4cd7162 commit f6fc3ba

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: 'Quickstart: Create an Azure CDN profile and endpoint using Terraform'
3+
titleSuffix: Azure Content Delivery Network
4+
description: 'In this article, you create an Azure CDN profile and endpoint using Terraform'
5+
services: cdn
6+
ms.service: azure-cdn
7+
ms.topic: quickstart
8+
ms.date: 4/12/2023
9+
ms.custom: devx-track-terraform
10+
author: TomArcherMsft
11+
ms.author: tarcher
12+
---
13+
14+
# Quickstart: Create an Azure CDN profile and endpoint using Terraform
15+
16+
This article shows how to use Terraform to create an [Azure CDN profile and endpoint](/azure/cdn/cdn-overview) using [Terraform](/azure/developer/terraform/quickstart-configure).
17+
18+
[!INCLUDE [Terraform abstract](~/azure-dev-docs-pr/articles/terraform/includes/abstract.md)]
19+
20+
In this article, you learn how to:
21+
22+
> [!div class="checklist"]
23+
> * Create a random pet name for the Azure resource group name using [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
24+
> * Create an Azure resource group using [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
25+
> * Create a random string for the CDN endpoint name using [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
26+
> * Create an Azure CDN profile using [azurerm_cdn_profile](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cdn_profile)
27+
> * Create an Azure CDN endpoint using [azurerm_cdn_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cdn_endpoint)
28+
29+
[!INCLUDE [AI attribution](../../includes/ai-generated-attribution.md)]
30+
31+
## Prerequisites
32+
33+
- [Install and configure Terraform](/azure/developer/terraform/quickstart-configure)
34+
35+
## Implement the Terraform code
36+
37+
> [!NOTE]
38+
> The sample code for this article is located in the [Azure Terraform GitHub repo](https://github.com/Azure/terraform/tree/master/quickstart/101-cdn-with-custom-origin). You can view the log file containing the [test results from current and previous versions of Terraform](https://github.com/Azure/terraform/blob/master/quickstart/101-cdn-with-custom-origin/TestRecord.md).
39+
>
40+
> See more [articles and sample code showing how to use Terraform to manage Azure resources](/azure/terraform)
41+
42+
1. Create a directory in which to test and run the sample Terraform code and make it the current directory.
43+
44+
1. Create a file named `main.tf` and insert the following code:
45+
46+
[!code-terraform[master](~/terraform_samples/quickstart/101-cdn-with-custom-origin/main.tf)]
47+
48+
1. Create a file named `outputs.tf` and insert the following code:
49+
50+
[!code-terraform[master](~/terraform_samples/quickstart/101-cdn-with-custom-origin/outputs.tf)]
51+
52+
1. Create a file named `providers.tf` and insert the following code:
53+
54+
[!code-terraform[master](~/terraform_samples/quickstart/101-cdn-with-custom-origin/providers.tf)]
55+
56+
1. Create a file named `variables.tf` and insert the following code:
57+
58+
[!code-terraform[master](~/terraform_samples/quickstart/101-cdn-with-custom-origin/variables.tf)]
59+
60+
## Initialize Terraform
61+
62+
[!INCLUDE [terraform-init.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-init.md)]
63+
64+
## Create a Terraform execution plan
65+
66+
[!INCLUDE [terraform-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan.md)]
67+
68+
## Apply a Terraform execution plan
69+
70+
[!INCLUDE [terraform-apply-plan.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-apply-plan.md)]
71+
72+
## Verify the results
73+
74+
#### [Azure CLI](#tab/azure-cli)
75+
76+
1. Get the Azure resource group name in which the Azure CDN profile and endpoint were created.
77+
78+
```console
79+
resource_group_name=$(terraform output -raw resource_group_name)
80+
```
81+
82+
1. Get the CDN profile name.
83+
84+
```console
85+
cdn_profile_name=$(terraform output -raw cdn_profile_name)
86+
```
87+
88+
1. Get the CDN endpoint name.
89+
90+
```console
91+
cdn_endpoint_endpoint_name=$(terraform output -raw cdn_endpoint_endpoint_name)
92+
```
93+
94+
1. Run [az cdn custom-domain show](/cli/azure/cdn/custom-domain#az-cdn-custom-domain-show) to show details of the custom domain you created in this article.
95+
96+
```azurecli
97+
az cdn endpoint show --resource-group $resource_group_name \
98+
--profile-name $cdn_profile_name \
99+
--name $cdn_endpoint_endpoint_name
100+
```
101+
102+
#### [Azure PowerShell](#tab/azure-powershell)
103+
104+
1. Get the Azure resource group name in which the Azure CDN profile and endpoint were created.
105+
106+
```console
107+
$resource_group_name=$(terraform output -raw resource_group_name)
108+
```
109+
110+
1. Get the CDN profile name.
111+
112+
```console
113+
$cdn_profile_name=$(terraform output -raw cdn_profile_name)
114+
```
115+
116+
1. Get the CDN endpoint name.
117+
118+
```console
119+
$cdn_endpoint_endpoint_name=$(terraform output -raw cdn_endpoint_endpoint_name)
120+
```
121+
122+
1. Run [Get-AzCdnEndpoint](/powershell/module/az.cdn/get-azcdnendpoint) to show details of the custom domain you created in this article.
123+
124+
```console
125+
Get-AzCdnEndpoint -ResourceGroupName $resource_group_name `
126+
-ProfileName $cdn_profile_name `
127+
-Name $cdn_endpoint_endpoint_name
128+
```
129+
130+
---
131+
132+
## Clean up resources
133+
134+
[!INCLUDE [terraform-plan-destroy.md](~/azure-dev-docs-pr/articles/terraform/includes/terraform-plan-destroy.md)]
135+
136+
## Troubleshoot Terraform on Azure
137+
138+
[Troubleshoot common problems when using Terraform on Azure](/azure/developer/terraform/troubleshoot)
139+
140+
## Next steps
141+
142+
> [!div class="nextstepaction"]
143+
> [Tutorial: Use CDN to serve static content from a web app](cdn-add-to-web-app.md)

articles/frontdoor/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
- name: Create profile and endpoint - ARM Template
7171
displayName: Resource Manager
7272
href: ../cdn/create-profile-endpoint-template.md?toc=/azure/frontdoor/TOC.json
73+
- name: Create profile and endpoint - Terraform
74+
href: ../cdn/create-profile-endpoint-terraform.md?toc=/azure/frontdoor/TOC.json
7375
- name: Tutorials
7476
items:
7577
- name: Front Door

0 commit comments

Comments
 (0)