From 10eb60d11ae270dc0f49956e4de4d10a88afe797 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 23 Jan 2019 06:36:52 +0000 Subject: [PATCH] Adding http2 to application gateway (#2735) --- azurerm/resource_arm_application_gateway.go | 11 ++- .../resource_arm_application_gateway_test.go | 97 +++++++++++++++++++ .../docs/r/application_gateway.html.markdown | 2 + 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/resource_arm_application_gateway.go index 0cab82f6c2b6..badb8f9557b5 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/resource_arm_application_gateway.go @@ -33,6 +33,11 @@ func resourceArmApplicationGateway() *schema.Resource { "location": locationSchema(), + "enable_http2": { + Type: schema.TypeBool, + Optional: true, + }, + "resource_group_name": { Type: schema.TypeString, Required: true, @@ -761,6 +766,7 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte } location := azureRMNormalizeLocation(d.Get("location").(string)) + enablehttp2 := d.Get("enable_http2").(bool) tags := d.Get("tags").(map[string]interface{}) // Gateway ID is needed to link sub-resources together in expand functions @@ -783,11 +789,13 @@ func resourceArmApplicationGatewayCreateUpdate(d *schema.ResourceData, meta inte gateway := network.ApplicationGateway{ Location: utils.String(location), - Tags: expandTags(tags), + + Tags: expandTags(tags), ApplicationGatewayPropertiesFormat: &network.ApplicationGatewayPropertiesFormat{ AuthenticationCertificates: authenticationCertificates, BackendAddressPools: backendAddressPools, BackendHTTPSettingsCollection: backendHTTPSettingsCollection, + EnableHTTP2: utils.Bool(enablehttp2), FrontendIPConfigurations: frontendIPConfigurations, FrontendPorts: frontendPorts, GatewayIPConfigurations: gatewayIPConfigurations, @@ -865,6 +873,7 @@ func resourceArmApplicationGatewayRead(d *schema.ResourceData, meta interface{}) d.Set("name", applicationGateway.Name) d.Set("resource_group_name", id.ResourceGroup) + d.Set("enable_http2", applicationGateway.EnableHTTP2) if location := applicationGateway.Location; location != nil { d.Set("location", azureRMNormalizeLocation(*location)) } diff --git a/azurerm/resource_arm_application_gateway_test.go b/azurerm/resource_arm_application_gateway_test.go index a7ef6bfaf5eb..0d39043b490c 100644 --- a/azurerm/resource_arm_application_gateway_test.go +++ b/azurerm/resource_arm_application_gateway_test.go @@ -38,6 +38,31 @@ func TestAccAzureRMApplicationGateway_basic(t *testing.T) { }) } +func TestAccAzureRMApplicationGateway_http2(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_http2(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationGatewayExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "enable_http2", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMApplicationGateway_requiresImport(t *testing.T) { if !requireResourcesToBeImported { t.Skip("Skipping since resources aren't required to be imported") @@ -411,6 +436,78 @@ resource "azurerm_application_gateway" "test" { `, template, rInt) } +func testAccAzureRMApplicationGateway_http2(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_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + enable_http2 = true + + 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_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" + } + + 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) +} + func testAccAzureRMApplicationGateway_requiresImport(rInt int, location string) string { template := testAccAzureRMApplicationGateway_basic(rInt, location) return fmt.Sprintf(` diff --git a/website/docs/r/application_gateway.html.markdown b/website/docs/r/application_gateway.html.markdown index 172acba16309..f8fb46713552 100644 --- a/website/docs/r/application_gateway.html.markdown +++ b/website/docs/r/application_gateway.html.markdown @@ -359,6 +359,8 @@ The following attributes are exported: * `gateway_ip_configuration` - A list of `gateway_ip_configuration` blocks as defined below. +* `http2_enabled` - (Optional) Is HTTP2 enabled on the application gateway resource? Defaults to `false`. + * `http_listener` - A list of `http_listener` blocks as defined below. * `probe` - A `probe` block as defined below.