hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

[azurerm_cdn_endpoint] Standard_Verizon global_delivery_rule and delivery_rule support #8511

Open restfulhead opened 4 years ago

restfulhead commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.12.28
+ provider.azurerm v2.27.0

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_cdn_endpoint" "cdn_endpoint_standard" {
  count               = var.cdn_sku == "Standard_Verizon" ? 1:0
  name                = "${data.terraform_remote_state.main.outputs.name}-cdn-endpoint"
  profile_name        = azurerm_cdn_profile.cdn_profile.name
  location            = data.terraform_remote_state.shared.outputs.resource_group_location
  resource_group_name = data.terraform_remote_state.shared.outputs.resource_group_name

  origin {
    name      = "${data.terraform_remote_state.main.outputs.name}-cdn-origin"
    host_name = var.storage_account_ui_url
  }

  global_delivery_rule {
    cache_expiration_action {
      behavior = "Override"
      duration = "00:05:00"
    }
  }

  delivery_rule {
    name  = "cachegeneratedfiles"
    order = 2
    url_file_extension_condition {
      operator = "Any" 
      match_values = ["css", "js", "woff", "woff2"]
      transforms = ["Lowercase"]
    }
    cache_expiration_action {
      behavior = "Override"
      duration = "365.00:00:00"
    }
  }

  querystring_caching_behaviour = "IgnoreQueryString"

  origin_host_header     = var.storage_account_ui_url
  is_http_allowed        = false
  is_compression_enabled = true

  content_types_to_compress = ["text/plain", "application/json", "application/x-javascript", "application/javascript", "application/xml", "text/javascript", "text/html", "text/css"]
}

Expected Behavior

Expected TF to create caching rules or do not set these attributes.

Actual Behavior

With global_delivery_rule and delivery_rule present, the following error occurs:

Error: Error: `global_delivery_policy` and `delivery_rule` are only allowed when `Standard_Microsoft` sku is used. Profile sku:  Standard_Verizon

But please also note: Without these elements, Terraform removes caching rules that were manually created in the portal. It detects them as changes, for example:

- global_delivery_rule {
          - cache_expiration_action {
              - behavior = "Override" -> null
              - duration = "00:05:00" -> null
            }
        }

I have to ignore those using lifecycle ignore_changes.

It would be great if support for Standard Verizon could be added. If that's not feasible, perhaps at least these attributes shouldn't cause changes.

magodo commented 4 years ago

@restfulhead Thank you for submitting this!

After checking this Azure document, it turns out that delivery_rule also works for Standard_Verizon and Standard_Akamai.

Though it has some subtle limitations, e.g. can not name the rule, only url_file_extension_condition is supported, only cache_expiration_action is supported, .etc.

magodo commented 4 years ago

@restfulhead Unfortunately, the Swagger has some blockers. Until it is addressed, we can go on implementing this feature in Terraform.

raswinraaj commented 3 years ago

@restfulhead were you able to find any workaround for this? I am getting the same error. I have an existing resource with global_delivery_rule. I just changed resource tag and now it says that "Error: Error: global_delivery_policy and delivery_rule are only allowed when Standard_Microsoft sku is used" even though I havent changed anything in that block now

restfulhead commented 3 years ago

@raswinraaj Only by ignoring those attributes:

lifecycle {
    ignore_changes = [
      global_delivery_rule,
      delivery_rule
    ]
  }
Scifire commented 1 year ago

It seems that this is also an issue when changing CDN Endpoints (Standard_Verizon) which have a delivery rule defined in the portal. The ignore life cycle block work that terraform will not remove those rules without a change, but when a change should be done (e.g. change the origin path) then following error come:

Error: `global_delivery_rule` and `delivery_rule` are only allowed when `Standard_Microsoft` sku is used. Profile sku:  Standard_Verizon