Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_application_gateway - support for rewriting urls with the url block #10950

Merged
merged 9 commits into from
Apr 2, 2021

Conversation

dhensby
Copy link
Contributor

@dhensby dhensby commented Mar 12, 2021

Fixes #7565

This is my first pass at trying to get URLConfiguration support into terraform (see https://docs.microsoft.com/en-us/rest/api/application-gateway/applicationgateways/get#applicationgatewayurlconfiguration).

This will allow the rewriting of URLs in application gateway.

To-dos:

  • Should we validate that at least one of url_configuration.url_path or url_configuration.url_query is supplied?
  • Update docs
  • tests??

example usage:

resource "azurerm_application_gateway" "gateway" {
  ...
  rewrite_rule_set {
    name = local.rewrite_rule_set_name

    rewrite_rule {
      name          = local.rewrite_rule_name
      rule_sequence = 1

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

      url {
        path         = "/article.aspx"
        query_string = "id={var_uri_path_1}&title={var_uri_path_2}"
      }
    }
  }
  ...
}

Test data based on example here https://docs.microsoft.com/en-us/azure/application-gateway/rewrite-url-portal

@ghost ghost added the size/S label Mar 12, 2021
@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch from a368c7c to fd38082 Compare March 12, 2021 12:34
@ghost ghost added size/M documentation and removed size/S labels Mar 12, 2021
@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch from fd38082 to 878dad0 Compare March 12, 2021 12:54
@ghost ghost added size/L and removed size/M labels Mar 12, 2021
@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch 3 times, most recently from cff0322 to 1e6bec1 Compare March 12, 2021 21:30
@dhensby dhensby marked this pull request as ready for review March 12, 2021 21:59
@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch from 1e6bec1 to 83c7e7c Compare March 12, 2021 22:12
@dhensby
Copy link
Contributor Author

dhensby commented Mar 12, 2021

I have compiled and tested this locally and successfully deployed a url_rewrite against an app gateway.

@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch 2 times, most recently from f51ae22 to 1246286 Compare March 16, 2021 10:06
@jackofallops
Copy link
Member

Hi @dhensby - Could you revert any changes to CHANGELOG.md - This file is updated by maintainers when we actually merge and should not be part of a PR content.

Thanks!

@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch from 1246286 to 30d8dc3 Compare March 18, 2021 12:21
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @dhensby - overall looks great, but i have some questions i've left inline to address before merge

@dhensby dhensby force-pushed the pulls/app-gateway-url-rewrite branch from 30d8dc3 to 89dfe38 Compare March 31, 2021 10:57
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dhensby - LGTM 👍

@katbyte katbyte merged commit 55d277e into hashicorp:master Apr 2, 2021
@katbyte katbyte changed the title Add URL Configuration support to azurerm_application_gateway azurerm_application_gateway - support for rewriting urls with the url block Apr 2, 2021
katbyte added a commit that referenced this pull request Apr 2, 2021
@ghost
Copy link

ghost commented Apr 2, 2021

This has been released in version 2.54.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.54.0"
}
# ... other configuration ...

@dhensby dhensby deleted the pulls/app-gateway-url-rewrite branch April 2, 2021 07:20
@ido-re
Copy link

ido-re commented Apr 5, 2021

Thanks for this very important update,
I think there is a minor bug in the result (below)
when using
url {
path =foo
}

the result is "Both URL path and URL query string" and not "URL path" (screenshot below)

image

@ghost ghost removed the waiting-response label Apr 5, 2021
@dhensby
Copy link
Contributor Author

dhensby commented Apr 5, 2021

I think this is just how the front end in the portal is showing it.

That option isn't actually part of the rest API, it's just how the portal shows the interface.

@ido-re
Copy link

ido-re commented Apr 19, 2021

@dhensby - after tests, the query strings are not working when it set to "Both URL path and URL query string" and not to "URL path" only.
In my tf module, the path is set to "path" only and not both "path" and "query_string" (below)

url {
path =foo
}

@dhensby
Copy link
Contributor Author

dhensby commented Apr 19, 2021

@ido-tr I don't really understand what you're saying.

I've gone through to double check this all works as expected and I don't see any issues:

Both path and query_string set:

  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"
        query_string = "id={var_uri_path_1}&title={var_uri_path_2}"
      }
    }
  }

In the portal:

2021-04-19_10-27-07_a3ba29b4-c668-4d3d-b12c-f2f22127cf90

Just query_string:

  rewrite_rule_set {
    name = "test-rewrite-ruleset"

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

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

      url {
        query_string = "id={var_uri_path_1}&title={var_uri_path_2}"
      }
    }
  }

In the portal:

2021-04-19_10-29-07_c4b041a8-848a-4790-aa00-a85df8e25b75

Just path:

  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"
      }
    }
  }

In the portal:

2021-04-19_10-33-25_0eb77c2f-bac0-4926-8b41-50c21e7ea8dc

All those are working as expected; can you provide me an example that doesn't work?

@dhensby
Copy link
Contributor Author

dhensby commented Apr 19, 2021

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.

@dhensby
Copy link
Contributor Author

dhensby commented Apr 19, 2021

OK - this is where my lack of Go/terraform knowledge is letting me down - I can't see why empty values are being passed when values are missing.

It appears it may not be possible to distinguish a missing value vs empty string for TypeString, in which case we have a bit of a problem...

@katbyte any thoughts on this?

@ido-re
Copy link

ido-re commented Apr 20, 2021

@dhensby - this is exactly my point

@ghost
Copy link

ghost commented May 2, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for URL rewrite in azurerm_application_gateway
4 participants