Azure_application_gateway rewrite rule with block condition... then

how to make this work on the terraform configuration yml file?
in the document of terraform provider azure.there is just only a simple example.some complex scenarios are not covered at all.

image

2 Likes

We are facing the same issue as well. We are not able to define condition-based URL rewrite rule.
Could not find any example as well.

Same error here. June 2021. It’s not possible to create a rewrite rule for the application gateway on Azure through Terraform.

I tried the following code:

rewrite_rule_set {
name = var.rewrite_rule_set_name
dynamic “rewrite_rule” {
iterator = rw_rule
for_each = var.rewrite_rules
content {
name = rw_rule.value.name
rule_sequence = rw_rule.value.rule_sequence
condition{
ignore_case = rw_rule.value.ignore_case
negate = rw_rule.value.negate
pattern = rw_rule.value.pattern
variable = rw_rule.value.variable
}
}
}

and included the rewrite_rule_set_name in my path rules.
Using “terraform apply”, I get this error:

Error: Error Creating/Updating Application Gateway ‘[gatewayname]’: network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400 – Original Error: Code=‘ApplicationGatewayRewriteRuleSetActionSetInRewriteRuleCannotBeEmpty’ Message=‘ActionSet is a required field in a RewriteRule.’ Details=

Unfortunately… creating the action_set{} section in the rewrite_rule_set doesn’t solve the issue, since Terraform doesn’t recognise it.

terraform version 0.14.0

Hi,

I hope you made it by now.
For anyone looking for a way to use rewrite rules via Terraform, feel free to include my example in your Azure application gateway’s definition:

rewrite_rule_set {
    name = "Rewrite-Rule-Set-Name"

    rewrite_rule {
      name          = "First rule"
      rule_sequence = 100

      condition{
        ignore_case = true
        negate      = false
        pattern     = ".*/*-service/(.*)"
        variable    = "var_uri_path"
      }

      url{
        path         = "{var_uri_path_1}"
        reroute      = false
        query_string = null  # using this we configure a rule that checks only the URL path, not both URL path and query string
      }
    }

    rewrite_rule {
      name          = "Second rule"
      rule_sequence = 100

      condition{
        ignore_case = true
        negate      = false
        pattern     = ".*/*-client/(.*)"
        variable    = "var_uri_path"
      }

      url{
        path         = "{var_uri_path_1}"
        reroute      = false
        query_string = null  # using this we configure a rule that checks only the URL path, not both URL path and query string
      }
    }
  }