From 7404d3656e2761e9a4a07606771b01ad3cde0dca Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Wed, 1 May 2019 11:50:06 +0100 Subject: [PATCH 01/12] Application gateway: Autoscale configuration --- azurerm/resource_arm_application_gateway.go | 68 +++++- .../resource_arm_application_gateway_test.go | 222 ++++++++++++++++++ 2 files changed, 284 insertions(+), 6 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 58c7966848a7..e91854ce4b4f 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -547,7 +547,23 @@ func resourceArmApplicationGateway() *schema.Resource { }, }, }, - + "autoscale_configuration": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "min_capacity": { + Type: schema.TypeInt, + Required: true, + }, + "max_capacity": { + Type: schema.TypeInt, + Optional: true, + }, + }, + }, + }, "sku": { Type: schema.TypeList, Required: true, @@ -583,7 +599,7 @@ func resourceArmApplicationGateway() *schema.Resource { "capacity": { Type: schema.TypeInt, - Required: true, + Optional: true, ValidateFunc: validation.IntBetween(1, 10), }, }, @@ -997,6 +1013,7 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte requestRoutingRules := expandApplicationGatewayRequestRoutingRules(d, gatewayID) redirectConfigurations := expandApplicationGatewayRedirectConfigurations(d, gatewayID) sku := expandApplicationGatewaySku(d) + autoscaleConfiguration := expandAutoscaleConfiguration(d) sslCertificates := expandApplicationGatewaySslCertificates(d) sslPolicy := expandApplicationGatewaySslPolicy(d) customErrorConfigurations := expandApplicationGatewayCustomErrorConfigurations(d.Get("custom_error_configuration").([]interface{})) @@ -1025,6 +1042,7 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte SslPolicy: sslPolicy, CustomErrorConfigurations: customErrorConfigurations, URLPathMaps: urlPathMaps, + AutoscaleConfiguration: autoscaleConfiguration, }, } @@ -1177,6 +1195,10 @@ func resourceArmApplicationGatewayRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `sku`: %+v", setErr) } + if setErr := d.Set("autoscale_configuration", flattenAutoscaleConfiguration(props.AutoscaleConfiguration)); setErr != nil { + return fmt.Errorf("Error setting `autoscale_configuration`: %+v", setErr) + } + if setErr := d.Set("ssl_certificate", flattenApplicationGatewaySslCertificates(props.SslCertificates, d)); setErr != nil { return fmt.Errorf("Error setting `ssl_certificate`: %+v", setErr) } @@ -2282,6 +2304,35 @@ func flattenApplicationGatewayRedirectConfigurations(input *[]network.Applicatio return results, nil } +func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGatewayAutoscaleConfiguration { + vs := d.Get("autoscale_configuration").([]interface{}) + v := vs[0].(map[string]interface{}) + + minCapacity := int32(v["min_capacity"].(int)) + maxCapacity := int32(v["max_capacity"].(int)) + + configuration := network.ApplicationGatewayAutoscaleConfiguration{ + MinCapacity: utils.Int32(minCapacity), + } + + if maxCapacity != 0 { + configuration.MaxCapacity = utils.Int32(maxCapacity) + } + + return &configuration +} + +func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { + result := make(map[string]interface{}) + + result["min_capacity"] = int32(*input.MinCapacity) + if input.MaxCapacity != nil { + result["max_capacity"] = int32(*input.MaxCapacity) + } + + return []interface{}{result} +} + func expandApplicationGatewaySku(d *schema.ResourceData) *network.ApplicationGatewaySku { vs := d.Get("sku").([]interface{}) v := vs[0].(map[string]interface{}) @@ -2290,11 +2341,16 @@ func expandApplicationGatewaySku(d *schema.ResourceData) *network.ApplicationGat tier := v["tier"].(string) capacity := int32(v["capacity"].(int)) - return &network.ApplicationGatewaySku{ - Name: network.ApplicationGatewaySkuName(name), - Tier: network.ApplicationGatewayTier(tier), - Capacity: utils.Int32(capacity), + sku := network.ApplicationGatewaySku{ + Name: network.ApplicationGatewaySkuName(name), + Tier: network.ApplicationGatewayTier(tier), + } + + if capacity != 0 { + sku.Capacity = utils.Int32(capacity) } + + return &sku } func flattenApplicationGatewaySku(input *network.ApplicationGatewaySku) []interface{} { diff --git a/azurerm/resource_arm_application_gateway_test.go b/azurerm/resource_arm_application_gateway_test.go index 31079575000b..6d4ef4fefc04 100644 --- a/azurerm/resource_arm_application_gateway_test.go +++ b/azurerm/resource_arm_application_gateway_test.go @@ -39,6 +39,63 @@ func TestAccAzureRMApplicationGateway_basic(t *testing.T) { }) } +func TestAccAzureRMApplicationGateway_autoscaleConfiguration(t *testing.T) { + resourceName := "azurerm_application_gateway.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationGatewayExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "2"), + resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.max_capacity", "10"), + resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(t *testing.T) { + resourceName := "azurerm_application_gateway.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationGatewayExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "2"), + resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMApplicationGateway_zones(t *testing.T) { resourceName := "azurerm_application_gateway.test" ri := tf.AccRandTimeInt() @@ -744,6 +801,171 @@ resource "azurerm_application_gateway" "test" { `, template, rInt, rInt) } +func testAccAzureRMApplicationGateway_autoscaleConfiguration(rInt int, location string) string { + template := testAccAzureRMApplicationGateway_template(rInt, location) + 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" + } + + autoscale_configuration { + min_capacity = 2 + max_capacity = 10 + } + + 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}" + } +} +`, template, rInt, rInt) +} + +func testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(rInt int, location string) string { + template := testAccAzureRMApplicationGateway_template(rInt, location) + 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" + } + + autoscale_configuration { + min_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 + } + + 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}" + } +} +`, template, rInt, rInt) +} + func testAccAzureRMApplicationGateway_overridePath(rInt int, location string) string { template := testAccAzureRMApplicationGateway_template(rInt, location) return fmt.Sprintf(` From 6d2ef8bc1082ddd2f3b40e99988dc0e6e24e2406 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Wed, 1 May 2019 14:22:50 +0100 Subject: [PATCH 02/12] Hopefully fix lint --- azurerm/resource_arm_application_gateway.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index e91854ce4b4f..54d6d057e145 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2325,9 +2325,9 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) - result["min_capacity"] = int32(*input.MinCapacity) + result["min_capacity"] = *input.MinCapacity if input.MaxCapacity != nil { - result["max_capacity"] = int32(*input.MaxCapacity) + result["max_capacity"] = *input.MaxCapacity } return []interface{}{result} From 706a6e46747e89f3b49ac559438db2917e646e8b Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Thu, 2 May 2019 19:29:02 +0100 Subject: [PATCH 03/12] Update docs --- website/docs/r/application_gateway.html.markdown | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/website/docs/r/application_gateway.html.markdown b/website/docs/r/application_gateway.html.markdown index c90463dc6147..723518b4c1ff 100644 --- a/website/docs/r/application_gateway.html.markdown +++ b/website/docs/r/application_gateway.html.markdown @@ -165,6 +165,8 @@ The following arguments are supported: * `redirect_configuration` - (Optional) A `redirect_configuration` block as defined below. +* `autoscale_configuration` - (Optional) A `autoscale_configuration` block as defined below. + --- A `authentication_certificate` block supports the following: @@ -352,7 +354,7 @@ A `sku` block supports the following: * `tier` - (Required) The Tier of the SKU to use for this Application Gateway. Possible values are `Standard`, `Standard_v2`, `WAF` and `WAF_v2`. -* `capacity` - (Required) The Capacity of the SKU to use for this Application Gateway - which must be between 1 and 10. +* `capacity` - (Required) The Capacity of the SKU to use for this Application Gateway - which must be between 1 and 10, optional if `autoscale_configuration` is set --- @@ -421,6 +423,14 @@ A `redirect_configuration` block supports the following: * `include_query_string` - (Optional) Whether or not to include the query string in the redirected Url. Default to `false` +--- + +A `autoscale_configuration` block supports the following: + +* `min_capacity` - (Required) Minimum capacity for autoscaling. + +* `max_capacity` - (Optional) Maximum capacity for autoscaling. + ## Attributes Reference The following attributes are exported: From 13aaadabb09ed2381218ec577f5a99ba34284de4 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 7 May 2019 07:49:16 +0100 Subject: [PATCH 04/12] Add nil check for `min_capacity` Co-Authored-By: timja --- azurerm/resource_arm_application_gateway.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 54d6d057e145..0d6bc598b0b8 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2325,7 +2325,9 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) - result["min_capacity"] = *input.MinCapacity + if v := input.MinCapacity; v != nil { + result["min_capacity"]= *v + } if input.MaxCapacity != nil { result["max_capacity"] = *input.MaxCapacity } From a15e2c648f4cc53aa82fb0fbf755874030216ade Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 7 May 2019 10:44:53 +0100 Subject: [PATCH 05/12] Push additional validation --- azurerm/resource_arm_application_gateway.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 0d6bc598b0b8..d34538fe98ae 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -556,10 +556,12 @@ func resourceArmApplicationGateway() *schema.Resource { "min_capacity": { Type: schema.TypeInt, Required: true, + ValidateFunc: validation.IntBetween(2, 10), }, "max_capacity": { Type: schema.TypeInt, Optional: true, + ValidateFunc: validation.IntBetween(2, 100), }, }, }, From ccdbdce340db5ac1160050e2c45ddec7b79e961d Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 7 May 2019 15:59:29 +0100 Subject: [PATCH 06/12] Add update test --- azurerm/resource_arm_application_gateway.go | 14 ++++++------- .../resource_arm_application_gateway_test.go | 21 ++++++++++++++----- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index d34538fe98ae..da90d48464f0 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -554,13 +554,13 @@ func resourceArmApplicationGateway() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "min_capacity": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, ValidateFunc: validation.IntBetween(2, 10), }, "max_capacity": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeInt, + Optional: true, ValidateFunc: validation.IntBetween(2, 100), }, }, @@ -2327,9 +2327,9 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) - if v := input.MinCapacity; v != nil { - result["min_capacity"]= *v - } + if v := input.MinCapacity; v != nil { + result["min_capacity"] = *v + } if input.MaxCapacity != nil { result["max_capacity"] = *input.MaxCapacity } diff --git a/azurerm/resource_arm_application_gateway_test.go b/azurerm/resource_arm_application_gateway_test.go index 6d4ef4fefc04..a17f054d68ee 100644 --- a/azurerm/resource_arm_application_gateway_test.go +++ b/azurerm/resource_arm_application_gateway_test.go @@ -49,7 +49,7 @@ func TestAccAzureRMApplicationGateway_autoscaleConfiguration(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, testLocation()), + Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, testLocation(), 2, 10), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApplicationGatewayExists(resourceName), resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), @@ -59,6 +59,17 @@ func TestAccAzureRMApplicationGateway_autoscaleConfiguration(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), ), }, + { + Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, testLocation(), 4, 12), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationGatewayExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "4"), + resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.max_capacity", "12"), + resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + ), + }, { ResourceName: resourceName, ImportState: true, @@ -801,7 +812,7 @@ resource "azurerm_application_gateway" "test" { `, template, rInt, rInt) } -func testAccAzureRMApplicationGateway_autoscaleConfiguration(rInt int, location string) string { +func testAccAzureRMApplicationGateway_autoscaleConfiguration(rInt int, location string, minCapacity int, maxCapacity int) string { template := testAccAzureRMApplicationGateway_template(rInt, location) return fmt.Sprintf(` %s @@ -835,8 +846,8 @@ resource "azurerm_application_gateway" "test" { } autoscale_configuration { - min_capacity = 2 - max_capacity = 10 + min_capacity = %d + max_capacity = %d } gateway_ip_configuration { @@ -881,7 +892,7 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, rInt, rInt, minCapacity, maxCapacity) } func testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(rInt int, location string) string { From 0fb439ee54837db6586499bd27d70a258c3c3936 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 7 May 2019 19:22:25 +0100 Subject: [PATCH 07/12] Update azurerm/resource_arm_application_gateway.go Co-Authored-By: timja --- azurerm/resource_arm_application_gateway.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index da90d48464f0..23066c05678e 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2308,7 +2308,10 @@ func flattenApplicationGatewayRedirectConfigurations(input *[]network.Applicatio func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGatewayAutoscaleConfiguration { vs := d.Get("autoscale_configuration").([]interface{}) - v := vs[0].(map[string]interface{}) + if len(vs) == 0 { + return nil + } + v := vs[0].(map[string]interface{}) minCapacity := int32(v["min_capacity"].(int)) maxCapacity := int32(v["max_capacity"].(int)) From 84b725e95b9202807c878c1d04577d71e8323c39 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 7 May 2019 19:22:55 +0100 Subject: [PATCH 08/12] Formatting --- azurerm/resource_arm_application_gateway.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 23066c05678e..5cb4124b5d00 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2308,10 +2308,10 @@ func flattenApplicationGatewayRedirectConfigurations(input *[]network.Applicatio func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGatewayAutoscaleConfiguration { vs := d.Get("autoscale_configuration").([]interface{}) - if len(vs) == 0 { - return nil - } - v := vs[0].(map[string]interface{}) + if len(vs) == 0 { + return nil + } + v := vs[0].(map[string]interface{}) minCapacity := int32(v["min_capacity"].(int)) maxCapacity := int32(v["max_capacity"].(int)) From c785e605f2fb28b7a7ff911f3e9e56fc364a39f0 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 7 May 2019 19:52:36 +0100 Subject: [PATCH 09/12] Update azurerm/resource_arm_application_gateway.go Co-Authored-By: timja --- azurerm/resource_arm_application_gateway.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 5cb4124b5d00..363d4848a590 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2329,7 +2329,9 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) - + if input == nil { + return []interface{}{result} + } if v := input.MinCapacity; v != nil { result["min_capacity"] = *v } From daa30ee22f84e555fbc1731502fbcd1978cc562e Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 7 May 2019 19:52:56 +0100 Subject: [PATCH 10/12] Format --- azurerm/resource_arm_application_gateway.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 363d4848a590..69ea64e7ea0a 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2329,9 +2329,9 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) - if input == nil { - return []interface{}{result} - } + if input == nil { + return []interface{}{result} + } if v := input.MinCapacity; v != nil { result["min_capacity"] = *v } From ea1af3a208a6ec147261e141ad260b728089d7a3 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 7 May 2019 12:33:31 -0700 Subject: [PATCH 11/12] Update resource_arm_application_gateway.go --- azurerm/resource_arm_application_gateway.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 69ea64e7ea0a..cbd3e448af47 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -2330,7 +2330,7 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) if input == nil { - return []interface{}{result} + return []interface{}{} } if v := input.MinCapacity; v != nil { result["min_capacity"] = *v From 991232b9c62c6b2c4e5ddd69b398c9a7437ba7f8 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Tue, 7 May 2019 20:55:59 +0100 Subject: [PATCH 12/12] Fix naming of functions --- azurerm/resource_arm_application_gateway.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 69ea64e7ea0a..04b5ceb2997a 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -1015,7 +1015,7 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte requestRoutingRules := expandApplicationGatewayRequestRoutingRules(d, gatewayID) redirectConfigurations := expandApplicationGatewayRedirectConfigurations(d, gatewayID) sku := expandApplicationGatewaySku(d) - autoscaleConfiguration := expandAutoscaleConfiguration(d) + autoscaleConfiguration := expandApplicationGatewayAutoscaleConfiguration(d) sslCertificates := expandApplicationGatewaySslCertificates(d) sslPolicy := expandApplicationGatewaySslPolicy(d) customErrorConfigurations := expandApplicationGatewayCustomErrorConfigurations(d.Get("custom_error_configuration").([]interface{})) @@ -1197,7 +1197,7 @@ func resourceArmApplicationGatewayRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `sku`: %+v", setErr) } - if setErr := d.Set("autoscale_configuration", flattenAutoscaleConfiguration(props.AutoscaleConfiguration)); setErr != nil { + if setErr := d.Set("autoscale_configuration", flattenApplicationGatewayAutoscaleConfiguration(props.AutoscaleConfiguration)); setErr != nil { return fmt.Errorf("Error setting `autoscale_configuration`: %+v", setErr) } @@ -2306,7 +2306,7 @@ func flattenApplicationGatewayRedirectConfigurations(input *[]network.Applicatio return results, nil } -func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGatewayAutoscaleConfiguration { +func expandApplicationGatewayAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGatewayAutoscaleConfiguration { vs := d.Get("autoscale_configuration").([]interface{}) if len(vs) == 0 { return nil @@ -2327,7 +2327,7 @@ func expandAutoscaleConfiguration(d *schema.ResourceData) *network.ApplicationGa return &configuration } -func flattenAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { +func flattenApplicationGatewayAutoscaleConfiguration(input *network.ApplicationGatewayAutoscaleConfiguration) []interface{} { result := make(map[string]interface{}) if input == nil { return []interface{}{result}