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

[BUG:] azurerm_cdn_frontdoor_rule - allow empty query_string in url_redirect_action #19927

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/services/cdn/cdn_frontdoor_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func resourceCdnFrontDoorRule() *pluginsdk.Resource {
},

// NOTE: it is valid for the query string to be an empty string.
// Leave blank to preserve the incoming query string. Issue #18249
// Leave blank to preserve the incoming query string. Issue #18249 & #19682
"query_string": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down
53 changes: 53 additions & 0 deletions internal/services/cdn/cdn_frontdoor_rule_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ func TestAccCdnFrontDoorRule_honorOrigin(t *testing.T) {
})
}

func TestAccCdnFrontDoorRule_allowEmptyQueryString(t *testing.T) {
// NOTE: Regression test case for issue #19682
data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_rule", "test")
r := CdnFrontDoorRuleResource{}
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.allowEmptyQueryString(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r CdnFrontDoorRuleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.FrontDoorRuleID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1119,3 +1134,41 @@ resource "azurerm_cdn_frontdoor_rule" "test" {
}
`, template, data.RandomInteger)
}

func (r CdnFrontDoorRuleResource) allowEmptyQueryString(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

%s

resource "azurerm_cdn_frontdoor_rule" "test" {
depends_on = [azurerm_cdn_frontdoor_origin_group.test, azurerm_cdn_frontdoor_origin.test]

name = "accTestRule%d"
cdn_frontdoor_rule_set_id = azurerm_cdn_frontdoor_rule_set.test.id

order = 0

conditions {
request_uri_condition {
match_values = ["contoso"]
negate_condition = false
operator = "Contains"
}
}

actions {
url_redirect_action {
redirect_type = "PermanentRedirect"
redirect_protocol = "MatchRequest"
query_string = ""
destination_hostname = "contoso.com"
destination_path = "/test/page"
}
}
}
`, template, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ func CdnFrontDoorUrlRedirectActionQueryString(i interface{}, k string) (_ []stri
if len(v) > 2048 {
return nil, []error{fmt.Errorf("'url_redirect_action' is invalid: %q cannot be longer than 2048 characters in length, got %d", k, len(v))}
}
} else {
return nil, []error{fmt.Errorf("'url_redirect_action' is invalid: %q must not be empty, got %q", k, v)}
}

return nil, nil
Expand Down