Skip to content

Commit

Permalink
azurerm_application_gateway - support priority property (#13498)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Harvey <[email protected]>
Co-authored-by: Adrian DX002 <[email protected]>

Fixes #13247
  • Loading branch information
gingerninja80 authored Oct 28, 2021
1 parent 2f25469 commit 64fce73
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/services/network/application_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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 @@ -2864,6 +2870,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 @@ -2875,6 +2882,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 @@ -2929,9 +2937,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 All @@ -2955,6 +2976,10 @@ func flattenApplicationGatewayRequestRoutingRules(input *[]network.ApplicationGa
output["name"] = *config.Name
}

if config.Priority != nil {
output["priority"] = *config.Priority
}

if pool := props.BackendAddressPool; pool != nil {
if pool.ID != nil {
poolId, err := parse.BackendAddressPoolID(*pool.ID)
Expand Down
Loading

0 comments on commit 64fce73

Please sign in to comment.