I am using a single Azure CDN profile with multiple endpoints. Not all endpoints will use all the same features. This however is causing me to have the errors below (if I create a new CDN profile with my endpoint there will be no issue but this is not the desired outcome):
main.tf
resource "azurerm_cdn_endpoint" "cdn-endpoint" {
count = length(var.endpoints)
name = var.endpoints[count.index].cdn_endpoint_name
profile_name = azurerm_cdn_profile.cdn-profile.name
location = var.location
resource_group_name = var.resource_group_name
is_http_allowed = false
origin {
name = var.endpoints[count.index].cdn_endpoint_origin_name
host_name = var.endpoints[count.index].cdn_endpoint_hostname
}
delivery_rule {
name = var.endpoints[count.index].cdn_endpoint_delivery_rule_name
order = var.endpoints[count.index].cdn_endpoint_delivery_rule_order
request_scheme_condition {
operator = var.endpoints[count.index].cdn_endpoint_request_operator
match_values = var.endpoints[count.index].cdn_endpoint_request_match_values
}
url_redirect_action {
redirect_type = var.endpoints[count.index].cdn_endpoint_redirect_type
protocol = var.endpoints[count.index].cdn_endpoint_redirect_protocol
hostname = var.endpoints[count.index].cdn_endpoint_redirect_hostname
path = var.endpoints[count.index].cdn_endpoint_redirect_path
}
}
}
variables.tf
variable "endpoints" {
type = list(object({
cdn_endpoint_name = string
cdn_endpoint_origin_name = string
cdn_endpoint_hostname = string
cdn_custom_domain_host_name = string
cdn_endpoint_delivery_rule_name = string
cdn_endpoint_delivery_rule_order = string
cdn_endpoint_request_operator = string
cdn_endpoint_request_match_values = list(string)
cdn_endpoint_redirect_type = string
cdn_endpoint_redirect_protocol = string
cdn_endpoint_redirect_hostname = string
cdn_endpoint_redirect_path = string
}))
}
prod.tfvars
cdn = [
{
cdn_profile_name = "cdn-profile1",
endpoints = [
{
cdn_endpoint_name = "endpoint1",
cdn_endpoint_origin_name = "origin1-endpoint",
cdn_endpoint_hostname = "sendgrid.net",
cdn_custom_domain_host_name = "test.customdomain.com",
cdn_endpoint_delivery_rule_name = null,
cdn_endpoint_delivery_rule_order = null,
cdn_endpoint_request_operator = null,
cdn_endpoint_request_match_values = null,
cdn_endpoint_redirect_type = null,
cdn_endpoint_redirect_protocol = null,
cdn_endpoint_redirect_hostname = null,
cdn_endpoint_redirect_path = null
},
{
cdn_endpoint_name = "endpoint2",
create_custom_domain_resource = "1",
cdn_endpoint_origin_name = "origin2-endpoint",
cdn_endpoint_hostname = "moo.blob.core.windows.net",
cdn_custom_domain_host_name = "customdomain.com",
cdn_endpoint_delivery_rule_name = "Rule1",
cdn_endpoint_delivery_rule_order = "1",
cdn_endpoint_request_operator = "Equal",
cdn_endpoint_request_match_values = ["HTTP"],
cdn_endpoint_redirect_type = "Found",
cdn_endpoint_redirect_protocol = "Http",
cdn_endpoint_redirect_hostname = "moo.blob.core.windows.net",
cdn_endpoint_redirect_path = "/moo/moo.txt"
}
],
}
]
When I do a terraform plan
Planning Terraform project deployment
╷
│ Error: Missing required argument
│
│ with module.cdn[0].azurerm_cdn_endpoint.cdn-endpoint[4],
│ on modules/cdn/main.tf line 23, in resource "azurerm_cdn_endpoint" "cdn-endpoint":
│ 23: name = var.endpoints[count.index].cdn_endpoint_delivery_rule_name
│
│ The argument "delivery_rule.0.name" is required, but no definition was found.
Only the following vars are giving the above error
cdn_endpoint_delivery_rule_name
cdn_endpoint_delivery_rule_order
cdn_endpoint_request_match_values
cdn_endpoint_redirect_type
What would be the best approach on how to tackle this issue? I would rather not setup another CDN profile as I want to limit it to a single CDN profile for all CDN endpoints.