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 priority property #13498

Merged
merged 7 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 21 additions & 0 deletions internal/services/network/application_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ func resourceApplicationGateway() *pluginsdk.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},

"priority": {
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 20000),
},

"backend_address_pool_id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -2869,6 +2875,7 @@ func flattenApplicationGatewayProbes(input *[]network.ApplicationGatewayProbe) [
func expandApplicationGatewayRequestRoutingRules(d *pluginsdk.ResourceData, gatewayID string) (*[]network.ApplicationGatewayRequestRoutingRule, error) {
vs := d.Get("request_routing_rule").(*pluginsdk.Set).List()
results := make([]network.ApplicationGatewayRequestRoutingRule, 0)
priorityset := false

for _, raw := range vs {
v := raw.(map[string]interface{})
Expand All @@ -2880,6 +2887,7 @@ func expandApplicationGatewayRequestRoutingRules(d *pluginsdk.ResourceData, gate
backendAddressPoolName := v["backend_address_pool_name"].(string)
backendHTTPSettingsName := v["backend_http_settings_name"].(string)
redirectConfigName := v["redirect_configuration_name"].(string)
priority := int32(v["priority"].(int))

rule := network.ApplicationGatewayRequestRoutingRule{
Name: utils.String(name),
Expand Down Expand Up @@ -2934,9 +2942,22 @@ func expandApplicationGatewayRequestRoutingRules(d *pluginsdk.ResourceData, gate
}
}

if priority != 0 {
rule.ApplicationGatewayRequestRoutingRulePropertiesFormat.Priority = &priority
priorityset = true
}

results = append(results, rule)
}

if priorityset {
for _, rule := range results {
if rule.ApplicationGatewayRequestRoutingRulePropertiesFormat.Priority == nil {
return nil, fmt.Errorf("If you wish to use rule priority, you will have to specify rule-priority field values for all the existing request routing rules.")
}
}
}

return &results, nil
}

Expand Down
327 changes: 327 additions & 0 deletions internal/services/network/application_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,32 @@ func TestAccApplicationGateway_sslProfileWithClientCertificateVerification(t *te
})
}

func TestAccApplicationGateway_requestRoutingRulePriority(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test")
r := ApplicationGatewayResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.requestRoutingRulePriorityEmpty(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
Config: r.requestRoutingRulePrioritySet(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("request_routing_rule.0.priority").HasValue("1"),
check.That(data.ResourceName).Key("request_routing_rule.1.priority").HasValue("20000"),
),
},
{
Config: r.requestRoutingRulePriorityValidation(data),
ExpectError: acceptance.RequiresImportError("azurerm_application_gateway"),
},
})
}

func (t ApplicationGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ApplicationGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -6540,3 +6566,304 @@ resource "azurerm_application_gateway" "test" {
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) requestRoutingRulePriorityEmpty(data acceptance.TestData) string {
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_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"
request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt"
}

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

sku {
name = "Standard_v2"
tier = "Standard_v2"
capacity = 1
}

ssl_policy {
policy_type = "Custom"
min_protocol_version = "TLSv1_1"
cipher_suites = ["TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"]
}

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

frontend_port {
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
}

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

request_routing_rule {
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
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) requestRoutingRulePrioritySet(data acceptance.TestData) string {
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_1 = "${azurerm_virtual_network.test.name}-feport-1"
frontend_port_name_2 = "${azurerm_virtual_network.test.name}-feport-2"
frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip"
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
listener_name_1 = "${azurerm_virtual_network.test.name}-httplstn-1"
listener_name_2 = "${azurerm_virtual_network.test.name}-httplstn-2"
request_routing_rule_name_1 = "${azurerm_virtual_network.test.name}-rqrt-1"
request_routing_rule_name_2 = "${azurerm_virtual_network.test.name}-rqrt-2"
}

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

sku {
name = "Standard_v2"
tier = "Standard_v2"
capacity = 1
}

ssl_policy {
policy_type = "Custom"
min_protocol_version = "TLSv1_1"
cipher_suites = ["TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"]
}

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

frontend_port {
name = local.frontend_port_name_1
port = 80
}

frontend_port {
name = local.frontend_port_name_2
port = 8080
}

frontend_ip_configuration {
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
}

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_1
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name_1
protocol = "Http"
}

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

request_routing_rule {
name = local.request_routing_rule_name_1
rule_type = "Basic"
http_listener_name = local.listener_name_1
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
priority = 1
}

request_routing_rule {
name = local.request_routing_rule_name_2
rule_type = "Basic"
http_listener_name = local.listener_name_2
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
priority = 20000
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) requestRoutingRulePriorityValidation(data acceptance.TestData) string {
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_1 = "${azurerm_virtual_network.test.name}-feport-1"
frontend_port_name_2 = "${azurerm_virtual_network.test.name}-feport-2"
frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip"
http_setting_name = "${azurerm_virtual_network.test.name}-be-htst"
listener_name_1 = "${azurerm_virtual_network.test.name}-httplstn-1"
listener_name_2 = "${azurerm_virtual_network.test.name}-httplstn-2"
request_routing_rule_name_1 = "${azurerm_virtual_network.test.name}-rqrt-1"
request_routing_rule_name_2 = "${azurerm_virtual_network.test.name}-rqrt-2"
}

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

sku {
name = "Standard_v2"
tier = "Standard_v2"
capacity = 1
}

ssl_policy {
policy_type = "Custom"
min_protocol_version = "TLSv1_1"
cipher_suites = ["TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_GCM_SHA256"]
}

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

frontend_port {
name = local.frontend_port_name_1
port = 80
}

frontend_port {
name = local.frontend_port_name_2
port = 8080
}

frontend_ip_configuration {
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
}

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_1
frontend_ip_configuration_name = local.frontend_ip_configuration_name
frontend_port_name = local.frontend_port_name_1
protocol = "Http"
}

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

request_routing_rule {
name = local.request_routing_rule_name_1
rule_type = "Basic"
http_listener_name = local.listener_name_1
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
priority = 1
}

request_routing_rule {
name = local.request_routing_rule_name_2
rule_type = "Basic"
http_listener_name = local.listener_name_2
backend_address_pool_name = local.backend_address_pool_name
backend_http_settings_name = local.http_setting_name
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}
Loading