Skip to content

Commit

Permalink
Adding http2 to application gateway (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostinthewires authored and katbyte committed Jan 23, 2019
1 parent 84926dc commit 10eb60d
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
11 changes: 10 additions & 1 deletion azurerm/resource_arm_application_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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))
}
Expand Down
97 changes: 97 additions & 0 deletions azurerm/resource_arm_application_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/application_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 10eb60d

Please sign in to comment.