Skip to content

Commit

Permalink
azurerm_application_gateway - support for the globalConfiguration
Browse files Browse the repository at this point in the history
… property (hashicorp#17651)
  • Loading branch information
ms-zhenhua authored Aug 18, 2022
1 parent 4e52ce3 commit 3aff64f
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 0 deletions.
67 changes: 67 additions & 0 deletions internal/services/network/application_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,24 @@ func resourceApplicationGateway() *pluginsdk.Resource {
},
},

"global": {
Type: pluginsdk.TypeList,
MaxItems: 1,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"request_buffering_enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
"response_buffering_enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
},
},
},

//lintignore:S016,S023
"http_listener": {
Type: pluginsdk.TypeSet,
Expand Down Expand Up @@ -1573,6 +1591,11 @@ func resourceApplicationGatewayCreate(d *pluginsdk.ResourceData, meta interface{

gatewayIPConfigurations, stopApplicationGateway := expandApplicationGatewayIPConfigurations(d)

globalConfiguration, err := expandApplicationGatewayGlobalConfiguration(d.Get("global").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `global`: %+v", err)
}

httpListeners, err := expandApplicationGatewayHTTPListeners(d, id.ID())
if err != nil {
return fmt.Errorf("fail to expand `http_listener`: %+v", err)
Expand All @@ -1597,6 +1620,7 @@ func resourceApplicationGatewayCreate(d *pluginsdk.ResourceData, meta interface{
FrontendIPConfigurations: expandApplicationGatewayFrontendIPConfigurations(d, id.ID()),
FrontendPorts: expandApplicationGatewayFrontendPorts(d),
GatewayIPConfigurations: gatewayIPConfigurations,
GlobalConfiguration: globalConfiguration,
HTTPListeners: httpListeners,
PrivateLinkConfigurations: expandApplicationGatewayPrivateLinkConfigurations(d),
Probes: expandApplicationGatewayProbes(d),
Expand Down Expand Up @@ -1805,6 +1829,15 @@ func resourceApplicationGatewayUpdate(d *pluginsdk.ResourceData, meta interface{
applicationGateway.ApplicationGatewayPropertiesFormat.GatewayIPConfigurations = gatewayIPConfigurations
}

if d.HasChange("global") {
globalConfiguration, err := expandApplicationGatewayGlobalConfiguration(d.Get("global").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `global`: %+v", err)
}

applicationGateway.ApplicationGatewayPropertiesFormat.GlobalConfiguration = globalConfiguration
}

if d.HasChange("http_listener") {
httpListeners, err := expandApplicationGatewayHTTPListeners(d, id.ID())
if err != nil {
Expand Down Expand Up @@ -2064,6 +2097,10 @@ func resourceApplicationGatewayRead(d *pluginsdk.ResourceData, meta interface{})
return fmt.Errorf("setting `gateway_ip_configuration`: %+v", setErr)
}

if setErr := d.Set("global", flattenApplicationGatewayGlobalConfiguration(props.GlobalConfiguration)); setErr != nil {
return fmt.Errorf("setting `global`: %+v", setErr)
}

if setErr := d.Set("private_endpoint_connection", flattenApplicationGatewayPrivateEndpoints(props.PrivateEndpointConnections)); setErr != nil {
return fmt.Errorf("setting `private_endpoint_connection`: %+v", setErr)
}
Expand Down Expand Up @@ -2978,6 +3015,36 @@ func flattenApplicationGatewayIPConfigurations(input *[]network.ApplicationGatew
return results
}

func expandApplicationGatewayGlobalConfiguration(input []interface{}) (*network.ApplicationGatewayGlobalConfiguration, error) {
if len(input) == 0 {
return nil, nil
}

v := input[0].(map[string]interface{})
return &network.ApplicationGatewayGlobalConfiguration{
EnableRequestBuffering: utils.Bool(v["request_buffering_enabled"].(bool)),
EnableResponseBuffering: utils.Bool(v["response_buffering_enabled"].(bool)),
}, nil
}

func flattenApplicationGatewayGlobalConfiguration(input *network.ApplicationGatewayGlobalConfiguration) []interface{} {
if input == nil {
return nil
}

output := make(map[string]interface{})

if input.EnableRequestBuffering != nil {
output["request_buffering_enabled"] = *input.EnableRequestBuffering
}

if input.EnableResponseBuffering != nil {
output["response_buffering_enabled"] = *input.EnableResponseBuffering
}

return []interface{}{output}
}

func expandApplicationGatewayFrontendPorts(d *pluginsdk.ResourceData) *[]network.ApplicationGatewayFrontendPort {
vs := d.Get("frontend_port").(*pluginsdk.Set).List()
results := make([]network.ApplicationGatewayFrontendPort, 0)
Expand Down
198 changes: 198 additions & 0 deletions internal/services/network/application_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ func TestAccApplicationGateway_autoscaleConfigurationNoMaxCapacity(t *testing.T)
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.createGlobalConfiguration(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku.0.name").HasValue("Standard_v2"),
check.That(data.ResourceName).Key("sku.0.tier").HasValue("Standard_v2"),
check.That(data.ResourceName).Key("global.0.request_buffering_enabled").HasValue("true"),
check.That(data.ResourceName).Key("global.0.response_buffering_enabled").HasValue("true"),
),
},
data.ImportStep(),
{
Config: r.updateGlobalConfiguration(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku.0.name").HasValue("Standard_v2"),
check.That(data.ResourceName).Key("sku.0.tier").HasValue("Standard_v2"),
check.That(data.ResourceName).Key("global.0.request_buffering_enabled").HasValue("false"),
check.That(data.ResourceName).Key("global.0.response_buffering_enabled").HasValue("false"),
),
},
data.ImportStep(),
})
}

func TestAccApplicationGateway_zones(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test")
r := ApplicationGatewayResource{}
Expand Down Expand Up @@ -1385,6 +1415,174 @@ resource "azurerm_application_gateway" "test" {
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) createGlobalConfiguration(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-standard-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
}
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 = 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_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
}
global {
request_buffering_enabled = true
response_buffering_enabled = true
}
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
priority = 10
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) updateGlobalConfiguration(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-standard-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Static"
sku = "Standard"
}
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 = 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_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
}
global {
request_buffering_enabled = false
response_buffering_enabled = false
}
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
priority = 10
}
}
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) UserDefinedIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/application_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ The following arguments are supported:

* `fips_enabled` - (Optional) Is FIPS enabled on the Application Gateway?

* `global` - (Optional) A `global` block as defined below.

* `identity` - (Optional) An `identity` block as defined below.

* `private_link_configuration` - (Optional) One or more `private_link_configuration` blocks as defined below.
Expand Down Expand Up @@ -437,6 +439,14 @@ A `request_routing_rule` block supports the following:

---

A `global` block supports the following:

* `request_buffering_enabled` - (Required) Whether Application Gateway's Request buffer is enabled.

* `response_buffering_enabled` - (Required) Whether Application Gateway's Response buffer is enabled.

---

A `sku` block supports the following:

* `name` - (Required) The Name of the SKU to use for this Application Gateway. Possible values are `Standard_Small`, `Standard_Medium`, `Standard_Large`, `Standard_v2`, `WAF_Medium`, `WAF_Large`, and `WAF_v2`.
Expand Down

0 comments on commit 3aff64f

Please sign in to comment.