Skip to content

Commit

Permalink
Support application gateway backend pools for network interface
Browse files Browse the repository at this point in the history
Both network interface data source and resource now supports
configuration of applicaiton gateway backed pool ids.
  • Loading branch information
abn committed Mar 27, 2018
1 parent 1099c2b commit 558de7e
Show file tree
Hide file tree
Showing 5 changed files with 192 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
2 changes: 2 additions & 0 deletions website/docs/r/network_interface.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ The `ip_configuration` block supports:

* `public_ip_address_id` - (Optional) Reference to a Public IP Address to associate with this NIC

* `application_gateway_backend_address_pools_ids` - (Optional) List of Application Gateway Backend Address Pool IDs references to which this NIC belongs

* `load_balancer_backend_address_pools_ids` - (Optional) List of Load Balancer Backend Address Pool IDs references to which this NIC belongs

* `load_balancer_inbound_nat_rules_ids` - (Optional) List of Load Balancer Inbound Nat Rules IDs involving this NIC
Expand Down

0 comments on commit 558de7e

Please sign in to comment.