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_frontdoor_rules_engine match_condition doesn't set correct operators and values and issue with variables #14130

Open aimarjs opened 2 years ago

aimarjs commented 2 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v1.0.10
on darwin_amd64
+ provider registry.terraform.io/aztfmod/azurecaf v1.2.6
+ provider registry.terraform.io/hashicorp/azurerm v2.84.0
+ provider registry.terraform.io/hashicorp/random v3.1.0

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_frontdoor_rules_engine" "geo_rule" {
  name                = "Georewrites"
  frontdoor_name      = azurerm_frontdoor.frontdoor.name
  resource_group_name = azurerm_frontdoor.frontdoor.resource_group_name

  rule {
    name     = "benlux"
    priority = 1

    match_condition {
      variable = "RemoteAddr"
      operator = "GeoMatch"
      value    = ["NL", "BE"]
    }

    match_condition {
      variable = "RequestURI"
      operator = "Equal"
      value    = ["https://frontdoorurl.azurefd.net"]
    }

    action {
      response_header {
        header_action_type = "Overwrite"
        header_name        = "location"
        value              = "/nl"
      }
    }
  }
}

Debug Output

Panic Output

Expected Behaviour

On Azure, I expected to see that the Remote Address is set as GeoMatch on the rule and the request URL is set as https://frontdoorurl.azurefd.net

Actual Behaviour

For some reason, it sets remote address as Geo Not Match, and it doesn't even change request path to remote URL image

Also, if I'm trying to set request URL then sometimes variable should be RequestURL and sometimes RequestUri

image

On Mac and Linux it breaks the thing since everything is case sensitive

Second attempt

image

Steps to Reproduce

  1. terraform apply

Important Factoids

References

ernout commented 2 years ago

It seems that the operator 'GeoNotMatch' is not mentioned in the list of parameters in the rules sourcecode in terraform. Maybe this was a feature that was added later?

https://github.com/hashicorp/terraform-provider-azurerm/blob/0a65b78cb3619fc7d1708e130f06c3f5d5e146d4/internal/services/frontdoor/frontdoor_rules_engine_rule.go

aimarjs commented 2 years ago

Any comment on this issue? Am I doing something wrong or there's is actually quite a nasty bug in the code?

bubbletroubles commented 2 years ago

It seems that RequestURI and RequestUri are specified inconsistently.