terraform-provider-azurerm icon indicating copy to clipboard operation
terraform-provider-azurerm copied to clipboard

Azure Application Gateway - Url can't be set without causing Query String to be empty

Open adrianperez84 opened this issue 4 years ago • 3 comments

When writing a rewrite rule where the intent is to only update the path without rewriting the query string, Terraform will set an empty string on the query string. This is a significant problem, as it causes query strings to be lost when using rewrite rules. I'm using the latest version 2.82.0.

rewrite_rule_set { name = "rwruleset" rewrite_rule {

            name                   = "rwrule1"
            rule_sequence          = 1

         
            condition {
               
                variable           = "var_uri_path"
                pattern            = "/checkout/(.+)"
             
            }
            url {
                path               = "/{var_uri_path_1}" 
                # query_string         The query string should not be set by Terraform as empty string. 
               
            }
    } 
}

This was originally discovered here: https://github.com/hashicorp/terraform-provider-azurerm/pull/10950 . You can notice that this snippet of code will incorrectly assume that both Path and Query String needs to be rewritten.

rewrite_rule_set {
    name = "test-rewrite-ruleset"

    rewrite_rule {
      name          = "test-rewrite-rule"
      rule_sequence = 1

      condition {
        variable = "var_uri_path"
        pattern  = ".*article/(.*)/(.*)"
      }

      url {
        path         = "/article.aspx"
      }
    }
  }

image

Having inspected the state file, I think I see the problem. When no value is provided the state file shows that there is a value of "" (an empty string), which probably means the query_string is essentially being replaced by the rewrite rule.

I'm not entirely sure why this is the case, but I'll do some investigation as to why empty strings are going through when no value is provided.

Originally posted by @dhensby in https://github.com/hashicorp/terraform-provider-azurerm/issues/10950#issuecomment-822334088

adrianperez84 avatar Oct 26 '21 02:10 adrianperez84

Duplicate of #11563

dhensby avatar Oct 26 '21 08:10 dhensby

@adrianperez84 @dhensby I just submitted a PR which can circumvents the limitations we currently have by using a components option, similar to the UI:

...
   rewrite_rule_set {
     name = "${local.rewrite_rule_set_name}_1"
     rewrite_rule {
       name          = "${local.rewrite_rule_name}_1"
       rule_sequence = 1
       condition {
         variable = "var_uri_path"
         pattern  = ".*article/(.*)/(.*)"
       }
       url {
         path       = "/article.aspx"
         components = "path_only"
       }
     }
     rewrite_rule {
       name          = "${local.rewrite_rule_name}_2"
       rule_sequence = 2
       condition {
         variable = "var_uri_path"
         pattern  = ".*article2/(.*)/(.*)"
       }
       url {
         query_string = "id={var_uri_path_1}&title={var_uri_path_2}"
         components   = "query_string_only"
       }
     }
   }
...

Happy to hear your thoughts about it!

aristosvo avatar Oct 26 '21 10:10 aristosvo

This functionality has been released in v3.4.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] avatar Apr 22 '22 00:04 github-actions[bot]

This functionality has been released in v3.19.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] avatar Aug 23 '22 15:08 github-actions[bot]

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Sep 23 '22 02:09 github-actions[bot]