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: can combine include_path with target_url #6175

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,7 @@ func expandApplicationGatewayRedirectConfigurations(d *schema.ResourceData, gate
ApplicationGatewayRedirectConfigurationPropertiesFormat: &network.ApplicationGatewayRedirectConfigurationPropertiesFormat{
RedirectType: network.ApplicationGatewayRedirectType(redirectType),
IncludeQueryString: utils.Bool(includeQueryString),
IncludePath: utils.Bool(includePath),
},
}

Expand All @@ -3055,16 +3056,11 @@ func expandApplicationGatewayRedirectConfigurations(d *schema.ResourceData, gate
return nil, fmt.Errorf("Conflict between `target_listener_name` and `target_url` (redirection is either to URL or target listener)")
}

if targetUrl != "" && includePath {
return nil, fmt.Errorf("`include_path` is not a valid option when `target_url` is set")
}

if targetListenerName != "" {
targetListenerID := fmt.Sprintf("%s/httpListeners/%s", gatewayID, targetListenerName)
output.ApplicationGatewayRedirectConfigurationPropertiesFormat.TargetListener = &network.SubResource{
ID: utils.String(targetListenerID),
}
output.ApplicationGatewayRedirectConfigurationPropertiesFormat.IncludePath = utils.Bool(includePath)
}

if targetUrl != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,25 @@ func TestAccAzureRMApplicationGateway_V2SKUCapacity(t *testing.T) {
})
}

func TestAccAzureRMApplicationGateway_IncludePathWithTargetURL(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMApplicationGatewayDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMApplicationGateway_includePathWithTargetURL(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApplicationGatewayExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMApplicationGatewayExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ApplicationGatewaysClient
Expand Down Expand Up @@ -3268,8 +3287,8 @@ locals {

resource "azurerm_application_gateway" "test" {
name = "acctestag-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "WAF_Medium"
Expand All @@ -3289,44 +3308,44 @@ resource "azurerm_application_gateway" "test" {

gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = "${azurerm_subnet.test.id}"
subnet_id = azurerm_subnet.test.id
}

frontend_port {
name = "${local.frontend_port_name}"
name = local.frontend_port_name
port = 80
}

frontend_ip_configuration {
name = "${local.frontend_ip_configuration_name}"
public_ip_address_id = "${azurerm_public_ip.test.id}"
name = local.frontend_ip_configuration_name
public_ip_address_id = azurerm_public_ip.test.id
}

backend_address_pool {
name = "${local.backend_address_pool_name}"
name = local.backend_address_pool_name
}

backend_http_settings {
name = "${local.http_setting_name}"
name = local.http_setting_name
cookie_based_affinity = "Disabled"
port = 80
protocol = "Http"
request_timeout = 1
}

http_listener {
name = "${local.listener_name}"
frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}"
frontend_port_name = "${local.frontend_port_name}"
name = local.listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name
protocol = "Http"
}

request_routing_rule {
name = "${local.request_routing_rule_name}"
name = local.request_routing_rule_name
rule_type = "Basic"
http_listener_name = "${local.listener_name}"
backend_address_pool_name = "${local.backend_address_pool_name}"
backend_http_settings_name = "${local.http_setting_name}"
http_listener_name = local.listener_name
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
}
}
`, template, data.RandomInteger)
Expand Down Expand Up @@ -4658,16 +4677,16 @@ locals {

resource "azurerm_public_ip" "test_standard" {
name = "acctest-pubip-%d-standard"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "Standard"
allocation_method = "Static"
}

resource "azurerm_application_gateway" "test" {
name = "acctestag-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "Standard_v2"
Expand All @@ -4677,45 +4696,175 @@ resource "azurerm_application_gateway" "test" {

gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = "${azurerm_subnet.test.id}"
subnet_id = azurerm_subnet.test.id
}

frontend_port {
name = "${local.frontend_port_name}"
name = local.frontend_port_name
port = 80
}

frontend_ip_configuration {
name = "${local.frontend_ip_configuration_name}"
public_ip_address_id = "${azurerm_public_ip.test_standard.id}"
name = local.frontend_ip_configuration_name
public_ip_address_id = azurerm_public_ip.test_standard.id
}

backend_address_pool {
name = "${local.backend_address_pool_name}"
name = local.backend_address_pool_name
}

backend_http_settings {
name = "${local.http_setting_name}"
name = local.http_setting_name
cookie_based_affinity = "Disabled"
port = 80
protocol = "Http"
request_timeout = 1
}

http_listener {
name = "${local.listener_name}"
frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}"
frontend_port_name = "${local.frontend_port_name}"
name = local.listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name
protocol = "Http"
}

request_routing_rule {
name = "${local.request_routing_rule_name}"
name = local.request_routing_rule_name
rule_type = "Basic"
http_listener_name = "${local.listener_name}"
backend_address_pool_name = "${local.backend_address_pool_name}"
backend_http_settings_name = "${local.http_setting_name}"
http_listener_name = local.listener_name
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
}
}
`, template, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMApplicationGateway_includePathWithTargetURL(data acceptance.TestData) string {
template := testAccAzureRMApplicationGateway_template(data)
return fmt.Sprintf(`
%s

# since these variables are re-used - a locals block makes this more maintainable
locals {
backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap"
frontend_port_name = "${azurerm_virtual_network.test.name}-feport"
frontend_port_name2 = "${azurerm_virtual_network.test.name}-feport2"
frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip"
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
listener_name = "${azurerm_virtual_network.test.name}-httplstn"
target_listener_name = "${azurerm_virtual_network.test.name}-trgthttplstn"
request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt"
path_rule_name = "${azurerm_virtual_network.test.name}-pathrule1"
path_rule_name2 = "${azurerm_virtual_network.test.name}-pathrule2"
url_path_map_name = "${azurerm_virtual_network.test.name}-urlpath1"
redirect_configuration_name = "${azurerm_virtual_network.test.name}-PathRedirect"
redirect_configuration_name2 = "${azurerm_virtual_network.test.name}-PathRedirect2"
target_url = "http://www.example.com"
}

resource "azurerm_application_gateway" "test" {
name = "acctestag-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location

sku {
name = "Standard_Small"
tier = "Standard"
capacity = 2
}

gateway_ip_configuration {
name = "my-gateway-ip-configuration"
subnet_id = azurerm_subnet.test.id
}

frontend_port {
name = local.frontend_port_name
port = 80
}

frontend_port {
name = local.frontend_port_name2
port = 8888
}

frontend_ip_configuration {
name = local.frontend_ip_configuration_name
public_ip_address_id = azurerm_public_ip.test.id
}

backend_address_pool {
name = local.backend_address_pool_name
}

backend_http_settings {
name = local.http_setting_name
cookie_based_affinity = "Disabled"
port = 80
protocol = "Http"
request_timeout = 1
}

http_listener {
name = local.listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name
protocol = "Http"
}

http_listener {
name = local.target_listener_name
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name2
protocol = "Http"
}

request_routing_rule {
name = local.request_routing_rule_name
rule_type = "PathBasedRouting"
url_path_map_name = local.url_path_map_name
http_listener_name = local.listener_name
}

url_path_map {
name = local.url_path_map_name
default_backend_address_pool_name = local.backend_address_pool_name
default_backend_http_settings_name = local.http_setting_name

path_rule {
name = local.path_rule_name
redirect_configuration_name = local.redirect_configuration_name

paths = [
"/test",
]
}

path_rule {
name = local.path_rule_name2
redirect_configuration_name = local.redirect_configuration_name2

paths = [
"/test2",
]
}
}

redirect_configuration {
name = local.redirect_configuration_name
redirect_type = "Found"
target_url = local.target_url
include_query_string = true
include_path = true
}

redirect_configuration {
name = local.redirect_configuration_name2
redirect_type = "Permanent"
target_listener_name = local.target_listener_name
include_path = false
include_query_string = false
}
}
`, template, data.RandomInteger)
}