Last active
August 25, 2020 00:28
-
-
Save magodo/ced95a6c93f8b7c40d525116ae6bf0ce to your computer and use it in GitHub Desktop.
terraform config for azurerm_cdn_endpoint_custom_domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "azurerm" { | |
features {} | |
} | |
variable "domain_name" { | |
default = "magodo.in" | |
} | |
variable "dns_zone_name" { | |
default = "magodo.in" | |
} | |
variable "dns_zone_rg" { | |
default = "magodo-testcdn" | |
} | |
variable "sub_domain_name" { | |
default = "cdn2" | |
} | |
variable "prefix" { | |
default = "magodocdn" | |
} | |
resource "azurerm_resource_group" "example" { | |
name = "${var.prefix}-test" | |
location = "West US" | |
} | |
resource "azurerm_storage_account" "example" { | |
name = "${var.prefix}cdnsa" | |
resource_group_name = azurerm_resource_group.example.name | |
location = azurerm_resource_group.example.location | |
account_tier = "Standard" | |
account_replication_type = "GRS" | |
} | |
resource "azurerm_cdn_profile" "example" { | |
name = "${var.prefix}-example-cdn" | |
location = azurerm_resource_group.example.location | |
resource_group_name = azurerm_resource_group.example.name | |
sku = "Standard_Verizon" | |
} | |
resource "azurerm_cdn_endpoint" "example" { | |
name = "${var.prefix}-example" | |
profile_name = azurerm_cdn_profile.example.name | |
location = azurerm_resource_group.example.location | |
resource_group_name = azurerm_resource_group.example.name | |
origin { | |
name = "example" | |
host_name = trimsuffix(trimprefix(trimprefix(azurerm_storage_account.example.primary_blob_endpoint, "https://"), "http://"), "/") | |
} | |
} | |
data "azurerm_dns_zone" "example" { | |
name = var.dns_zone_name | |
resource_group_name = var.dns_zone_rg | |
} | |
resource "azurerm_dns_cname_record" "example" { | |
name = var.sub_domain_name | |
zone_name = data.azurerm_dns_zone.example.name | |
resource_group_name = data.azurerm_dns_zone.example.resource_group_name | |
ttl = 3600 | |
target_resource_id = azurerm_cdn_endpoint.example.id | |
} | |
resource "azurerm_cdn_endpoint_custom_domain" "example" { | |
name = "${var.prefix}-customdomain" | |
cdn_endpoint_id = azurerm_cdn_endpoint.example.id | |
host_name = "${azurerm_dns_cname_record.example.name}.${var.domain_name}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PhilippSchmidCoC There is a PR for it: hashicorp/terraform-provider-azurerm#7918