From bdb8b305451362e38d1a119204bde635c0be7adc Mon Sep 17 00:00:00 2001 From: Andrew Urwin Date: Tue, 22 Jan 2019 14:03:02 +0000 Subject: [PATCH] Adding http2 to application gateway --- 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 8445629a0e38..8142f8f17a85 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, @@ -749,6 +754,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 @@ -771,11 +777,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, @@ -839,6 +847,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 3bca35c59e64..2bbc5b98b056 100644 --- a/azurerm/resource_arm_application_gateway_test.go +++ b/azurerm/resource_arm_application_gateway_test.go @@ -99,6 +99,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") @@ -422,6 +447,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 8fb8a0af8a6d..8f3080a67db0 100644 --- a/website/docs/r/application_gateway.html.markdown +++ b/website/docs/r/application_gateway.html.markdown @@ -355,6 +355,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.