From d108576c236b0de530b44029599337ccd0ff831a Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Thu, 14 Nov 2024 04:23:19 +0000 Subject: [PATCH] fix app gateway check for rewrite_rule block --- .../services/network/application_gateway_resource.go | 12 ++++++++++-- .../network/application_gateway_resource_test.go | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/services/network/application_gateway_resource.go b/internal/services/network/application_gateway_resource.go index 84dcf51195f4..6512e8908f71 100644 --- a/internal/services/network/application_gateway_resource.go +++ b/internal/services/network/application_gateway_resource.go @@ -4725,9 +4725,17 @@ func checkBasicSkuFeatures(d *pluginsdk.ResourceDiff) error { return fmt.Errorf("The Application Gateway does not support `trusted_client_certificate` blocks for the selected SKU tier %q", applicationgateways.ApplicationGatewaySkuNameBasic) } - _, hasRewriteRuleSetConfig := d.GetOk("rewrite_rule_set") + rewriteRuleSet, hasRewriteRuleSetConfig := d.GetOk("rewrite_rule_set") if hasRewriteRuleSetConfig { - return fmt.Errorf("The Application Gateway does not support `rewrite_rule_set` blocks for the selected SKU tier %q", applicationgateways.ApplicationGatewaySkuNameBasic) + for _, ruleSet := range rewriteRuleSet.([]interface{}) { + rs := ruleSet.(map[string]interface{}) + for _, rule := range rs["rewrite_rule"].([]interface{}) { + r := rule.(map[string]interface{}) + if len(r["url"].([]interface{})) > 0 { + return fmt.Errorf("The Application Gateway does not support `url` inside the `rewrite_rule` blocks for the selected SKU tier %q", applicationgateways.ApplicationGatewaySkuNameBasic) + } + } + } } return nil diff --git a/internal/services/network/application_gateway_resource_test.go b/internal/services/network/application_gateway_resource_test.go index b8ea99a4efbd..3c39264bacf0 100644 --- a/internal/services/network/application_gateway_resource_test.go +++ b/internal/services/network/application_gateway_resource_test.go @@ -1678,6 +1678,18 @@ resource "azurerm_application_gateway" "test" { backend_address_pool_name = local.backend_address_pool_name backend_http_settings_name = local.http_setting_name } + + rewrite_rule_set { + name = "add_headers_for_signin" + rewrite_rule { + name = "SetHeaders" + rule_sequence = 100 + request_header_configuration { + header_name = "X-Forwarded-Prefix" + header_value = "/adminportal" + } + } + } } `, r.template(data), data.RandomInteger) }