Skip to content

Commit

Permalink
Merge pull request #1027 from abn/application-gateway-backend-pools
Browse files Browse the repository at this point in the history
Support application gateway backend pool configuration
  • Loading branch information
tombuildsstuff committed Mar 28, 2018
2 parents 9605fb3 + 558de7e commit ef8baa4
Show file tree
Hide file tree
Showing 8 changed files with 460 additions and 0 deletions.
7 changes: 7 additions & 0 deletions azurerm/data_source_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func dataSourceArmNetworkInterface() *schema.Resource {
Computed: true,
},

"application_gateway_backend_address_pools_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"load_balancer_backend_address_pools_ids": {
Type: schema.TypeSet,
Computed: true,
Expand Down
21 changes: 21 additions & 0 deletions azurerm/import_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ func TestAccAzureRMNetworkInterface_importMultipleLoadBalancers(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_importApplicationGateway(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_applicationGatewayBackendPool(rInt, testLocation()),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMNetworkInterface_importPublicIP(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
Expand Down
31 changes: 31 additions & 0 deletions azurerm/resource_arm_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func resourceArmNetworkInterface() *schema.Resource {
Computed: true,
},

"application_gateway_backend_address_pools_ids": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"load_balancer_backend_address_pools_ids": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -471,6 +479,14 @@ func flattenNetworkInterfaceIPConfigurations(ipConfigs *[]network.InterfaceIPCon
niIPConfig["primary"] = *props.Primary
}

var poolsAG []interface{}
if props.ApplicationGatewayBackendAddressPools != nil {
for _, pool := range *props.ApplicationGatewayBackendAddressPools {
poolsAG = append(poolsAG, *pool.ID)
}
}
niIPConfig["application_gateway_backend_address_pools_ids"] = schema.NewSet(schema.HashString, poolsAG)

var pools []interface{}
if props.LoadBalancerBackendAddressPools != nil {
for _, pool := range *props.LoadBalancerBackendAddressPools {
Expand Down Expand Up @@ -551,6 +567,21 @@ func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]ne
properties.Primary = &b
}

if v, ok := data["application_gateway_backend_address_pools_ids"]; ok {
var ids []network.ApplicationGatewayBackendAddressPool
pools := v.(*schema.Set).List()
for _, p := range pools {
pool_id := p.(string)
id := network.ApplicationGatewayBackendAddressPool{
ID: &pool_id,
}

ids = append(ids, id)
}

properties.ApplicationGatewayBackendAddressPools = &ids
}

if v, ok := data["load_balancer_backend_address_pools_ids"]; ok {
var ids []network.BackendAddressPool
pools := v.(*schema.Set).List()
Expand Down
131 changes: 131 additions & 0 deletions azurerm/resource_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,25 @@ func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_applicationGateway(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_applicationGatewayBackendPool(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.application_gateway_backend_address_pools_ids.#", "1"),
),
},
},
})
}

func TestAccAzureRMNetworkInterface_withTags(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
Expand Down Expand Up @@ -903,6 +922,118 @@ resource "azurerm_network_interface" "test2" {
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMNetworkInterface_applicationGatewayBackendPool(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctest-vnet-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
address_space = ["10.254.0.0/16"]
location = "${azurerm_resource_group.test.location}"
}
resource "azurerm_subnet" "gateway" {
name = "subnet-gateway-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.254.0.0/24"
}
resource "azurerm_subnet" "test" {
name = "subnet-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.254.1.0/24"
}
resource "azurerm_public_ip" "test" {
name = "acctest-pubip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "dynamic"
}
resource "azurerm_application_gateway" "test" {
name = "acctestgw-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku {
name = "Standard_Medium"
tier = "Standard"
capacity = 1
}
gateway_ip_configuration {
name = "gw-ip-config1"
subnet_id = "${azurerm_subnet.gateway.id}"
}
frontend_port {
name = "port-8080"
port = 8080
}
frontend_ip_configuration {
name = "ip-config-public"
public_ip_address_id = "${azurerm_public_ip.test.id}"
}
backend_address_pool {
name = "pool-1"
}
backend_http_settings {
name = "backend-http-1"
port = 8080
protocol = "Http"
cookie_based_affinity = "Enabled"
request_timeout = 30
}
http_listener {
name = "listener-1"
frontend_ip_configuration_name = "ip-config-public"
frontend_port_name = "port-8080"
protocol = "Http"
}
request_routing_rule {
name = "rule-basic-1"
rule_type = "Basic"
http_listener_name = "listener-1"
backend_address_pool_name = "pool-1"
backend_http_settings_name = "backend-http-1"
}
tags {
environment = "tf01"
}
}
resource "azurerm_network_interface" "test" {
name = "acctestnic-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
enable_ip_forwarding = true
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
application_gateway_backend_address_pools_ids = [
"${azurerm_application_gateway.test.backend_address_pool.0.id}",
]
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMNetworkInterface_bug7986(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
27 changes: 27 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
Required: true,
},

"application_gateway_backend_address_pool_ids": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"load_balancer_backend_address_pool_ids": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -940,6 +947,14 @@ func flattenAzureRmVirtualMachineScaleSetNetworkProfile(profile *compute.Virtual
config["subnet_id"] = *properties.Subnet.ID
}

addressPools := make([]interface{}, 0)
if properties.ApplicationGatewayBackendAddressPools != nil {
for _, pool := range *properties.ApplicationGatewayBackendAddressPools {
addressPools = append(addressPools, *pool.ID)
}
}
config["application_gateway_backend_address_pool_ids"] = schema.NewSet(schema.HashString, addressPools)

if properties.LoadBalancerBackendAddressPools != nil {
addressPools := make([]interface{}, 0, len(*properties.LoadBalancerBackendAddressPools))
for _, pool := range *properties.LoadBalancerBackendAddressPools {
Expand Down Expand Up @@ -1271,6 +1286,18 @@ func expandAzureRmVirtualMachineScaleSetNetworkProfile(d *schema.ResourceData) *
},
}

if v := ipconfig["application_gateway_backend_address_pool_ids"]; v != nil {
pools := v.(*schema.Set).List()
resources := make([]compute.SubResource, 0, len(pools))
for _, p := range pools {
id := p.(string)
resources = append(resources, compute.SubResource{
ID: &id,
})
}
ipConfiguration.ApplicationGatewayBackendAddressPools = &resources
}

if v := ipconfig["load_balancer_backend_address_pool_ids"]; v != nil {
pools := v.(*schema.Set).List()
resources := make([]compute.SubResource, 0, len(pools))
Expand Down
Loading

0 comments on commit ef8baa4

Please sign in to comment.