ROBOTS | title | titleSuffix | description | services | ms.service | ms.topic | ms.date | ms.custom | author | ms.author | content_well_notification | ai-usage | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
NOINDEX | Quickstart: Create an Azure CDN profile and endpoint using Terraform | Azure Content Delivery Network | In this article, you create an Azure CDN profile and endpoint using Terraform | cdn | azure-cdn | quickstart | 03/31/2025 | devx-track-terraform | TomArcherMsft | tarcher |
| ai-assisted |
[!INCLUDE Azure CDN from Microsoft (classic) retirement notice]
This article shows how to use Terraform to create an Azure CDN profile and endpoint using Terraform.
[!INCLUDE Terraform abstract]
In this article, you learn how to:
[!div class="checklist"]
- Create a random pet name for the Azure resource group name using random_pet
- Create an Azure resource group using azurerm_resource_group
- Create a random string for the CDN endpoint name using random_string
- Create an Azure CDN profile using azurerm_cdn_profile
- Create an Azure CDN endpoint using azurerm_cdn_endpoint
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources
Create a directory in which to test and run the sample Terraform code and make it the current directory.
Create a file named
main.tf
and insert the following code:[!code-terraformmaster]
Create a file named
outputs.tf
and insert the following code:[!code-terraformmaster]
Create a file named
providers.tf
and insert the following code:[!code-terraformmaster]
Create a file named
variables.tf
and insert the following code:[!code-terraformmaster]
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
Get the Azure resource group name in which the Azure CDN profile and endpoint were created.
resource_group_name=$(terraform output -raw resource_group_name)
Get the CDN profile name.
cdn_profile_name=$(terraform output -raw cdn_profile_name)
Get the CDN endpoint name.
cdn_endpoint_endpoint_name=$(terraform output -raw cdn_endpoint_endpoint_name)
Run az cdn custom-domain show to show details of the custom domain you created in this article.
az cdn endpoint show --resource-group $resource_group_name \ --profile-name $cdn_profile_name \ --name $cdn_endpoint_endpoint_name
Get the Azure resource group name in which the Azure CDN profile and endpoint were created.
$resource_group_name=$(terraform output -raw resource_group_name)
Get the CDN profile name.
$cdn_profile_name=$(terraform output -raw cdn_profile_name)
Get the CDN endpoint name.
$cdn_endpoint_endpoint_name=$(terraform output -raw cdn_endpoint_endpoint_name)
Run Get-AzCdnEndpoint to show details of the custom domain you created in this article.
Get-AzCdnEndpoint -ResourceGroupName $resource_group_name ` -ProfileName $cdn_profile_name ` -Name $cdn_endpoint_endpoint_name
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure
[!div class="nextstepaction"] Tutorial: Use CDN to serve static content from a web app