2016-01-09 21:01:30 +01:00
|
|
|
package azurerm
|
|
|
|
|
2016-06-02 01:54:20 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAzureRMNetworkInterface_basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAzureRMNetworkInterface_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-29 18:14:20 +02:00
|
|
|
func TestAccAzureRMNetworkInterface_disappears(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAzureRMNetworkInterface_basic,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
testCheckAzureRMNetworkInterfaceDisappears("azurerm_network_interface.test"),
|
|
|
|
),
|
|
|
|
ExpectNonEmptyPlan: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-06-02 01:54:20 +02:00
|
|
|
func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAzureRMNetworkInterface_ipForwarding,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_network_interface.test", "enable_ip_forwarding", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccAzureRMNetworkInterface_withTags(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccAzureRMNetworkInterface_withTags,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-06-10 17:07:02 +02:00
|
|
|
"azurerm_network_interface.test", "tags.%", "2"),
|
2016-06-02 01:54:20 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_network_interface.test", "tags.environment", "Production"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_network_interface.test", "tags.cost_center", "MSFT"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccAzureRMNetworkInterface_withTagsUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-06-10 17:07:02 +02:00
|
|
|
"azurerm_network_interface.test", "tags.%", "1"),
|
2016-06-02 01:54:20 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"azurerm_network_interface.test", "tags.environment", "staging"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
///TODO: Re-enable this test when https://github.com/Azure/azure-sdk-for-go/issues/259 is fixed
|
|
|
|
//func TestAccAzureRMNetworkInterface_addingIpConfigurations(t *testing.T) {
|
2016-01-09 21:01:30 +01:00
|
|
|
//
|
|
|
|
// resource.Test(t, resource.TestCase{
|
|
|
|
// PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
// Providers: testAccProviders,
|
|
|
|
// CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
|
|
|
// Steps: []resource.TestStep{
|
|
|
|
// resource.TestStep{
|
|
|
|
// Config: testAccAzureRMNetworkInterface_basic,
|
|
|
|
// Check: resource.ComposeTestCheckFunc(
|
|
|
|
// testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
2016-06-01 22:17:21 +02:00
|
|
|
// resource.TestCheckResourceAttr(
|
2016-06-02 01:54:20 +02:00
|
|
|
// "azurerm_network_interface.test", "ip_configuration.#", "1"),
|
2016-06-01 22:17:21 +02:00
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
//
|
|
|
|
// resource.TestStep{
|
2016-06-02 01:54:20 +02:00
|
|
|
// Config: testAccAzureRMNetworkInterface_extraIpConfiguration,
|
2016-06-01 22:17:21 +02:00
|
|
|
// Check: resource.ComposeTestCheckFunc(
|
|
|
|
// testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
|
|
|
// resource.TestCheckResourceAttr(
|
2016-06-02 01:54:20 +02:00
|
|
|
// "azurerm_network_interface.test", "ip_configuration.#", "2"),
|
2016-01-09 21:01:30 +01:00
|
|
|
// ),
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// })
|
|
|
|
//}
|
2016-06-02 01:54:20 +02:00
|
|
|
|
|
|
|
func testCheckAzureRMNetworkInterfaceExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Ensure we have enough information in state to look up in API
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
|
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
if !hasResourceGroup {
|
|
|
|
return fmt.Errorf("Bad: no resource group found in state for availability set: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
|
|
|
|
|
|
|
resp, err := conn.Get(resourceGroup, name, "")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bad: Get on ifaceClient: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
|
|
return fmt.Errorf("Bad: Network Interface %q (resource group: %q) does not exist", name, resourceGroup)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 18:14:20 +02:00
|
|
|
func testCheckAzureRMNetworkInterfaceDisappears(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Ensure we have enough information in state to look up in API
|
|
|
|
rs, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
|
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
if !hasResourceGroup {
|
|
|
|
return fmt.Errorf("Bad: no resource group found in state for availability set: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
|
|
|
|
|
|
|
_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Bad: Delete on ifaceClient: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 01:54:20 +02:00
|
|
|
func testCheckAzureRMNetworkInterfaceDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "azurerm_network_interface" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name := rs.Primary.Attributes["name"]
|
|
|
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
|
|
|
|
|
|
resp, err := conn.Get(resourceGroup, name, "")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusNotFound {
|
|
|
|
return fmt.Errorf("Network Interface still exists:\n%#v", resp.Properties)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAzureRMNetworkInterface_basic = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acceptanceTestResourceGroup1"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acceptanceTestVirtualNetwork1"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "testsubnet"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acceptanceTestNetworkInterface1"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "testconfiguration1"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMNetworkInterface_ipForwarding = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acceptanceTestResourceGroup1"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acceptanceTestVirtualNetwork1"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "testsubnet"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acceptanceTestNetworkInterface1"
|
|
|
|
location = "West US"
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMNetworkInterface_withTags = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acceptanceTestResourceGroup1"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acceptanceTestVirtualNetwork1"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "testsubnet"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acceptanceTestNetworkInterface1"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "testconfiguration1"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "Production"
|
|
|
|
cost_center = "MSFT"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
var testAccAzureRMNetworkInterface_withTagsUpdate = `
|
|
|
|
resource "azurerm_resource_group" "test" {
|
|
|
|
name = "acceptanceTestResourceGroup1"
|
|
|
|
location = "West US"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "test" {
|
|
|
|
name = "acceptanceTestVirtualNetwork1"
|
|
|
|
address_space = ["10.0.0.0/16"]
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_subnet" "test" {
|
|
|
|
name = "testsubnet"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
address_prefix = "10.0.2.0/24"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_interface" "test" {
|
|
|
|
name = "acceptanceTestNetworkInterface1"
|
|
|
|
location = "West US"
|
|
|
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
|
|
|
|
ip_configuration {
|
|
|
|
name = "testconfiguration1"
|
|
|
|
subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
private_ip_address_allocation = "dynamic"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
environment = "staging"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
//TODO: Re-enable this test when https://github.com/Azure/azure-sdk-for-go/issues/259 is fixed
|
|
|
|
//var testAccAzureRMNetworkInterface_extraIpConfiguration = `
|
2016-01-09 21:01:30 +01:00
|
|
|
//resource "azurerm_resource_group" "test" {
|
|
|
|
// name = "acceptanceTestResourceGroup1"
|
|
|
|
// location = "West US"
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//resource "azurerm_virtual_network" "test" {
|
|
|
|
// name = "acceptanceTestVirtualNetwork1"
|
|
|
|
// address_space = ["10.0.0.0/16"]
|
|
|
|
// location = "West US"
|
|
|
|
// resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//resource "azurerm_subnet" "test" {
|
|
|
|
// name = "testsubnet"
|
|
|
|
// resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
// virtual_network_name = "${azurerm_virtual_network.test.name}"
|
|
|
|
// address_prefix = "10.0.2.0/24"
|
|
|
|
//}
|
|
|
|
//
|
2016-06-02 01:54:20 +02:00
|
|
|
//resource "azurerm_subnet" "test1" {
|
|
|
|
// name = "testsubnet1"
|
2016-01-09 21:01:30 +01:00
|
|
|
// resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
// virtual_network_name = "${azurerm_virtual_network.test.name}"
|
2016-06-02 01:54:20 +02:00
|
|
|
// address_prefix = "10.0.1.0/24"
|
2016-01-09 21:01:30 +01:00
|
|
|
//}
|
|
|
|
//
|
|
|
|
//resource "azurerm_network_interface" "test" {
|
|
|
|
// name = "acceptanceTestNetworkInterface1"
|
|
|
|
// location = "West US"
|
|
|
|
// resource_group_name = "${azurerm_resource_group.test.name}"
|
|
|
|
//
|
|
|
|
// ip_configuration {
|
|
|
|
// name = "testconfiguration1"
|
|
|
|
// subnet_id = "${azurerm_subnet.test.id}"
|
|
|
|
// private_ip_address_allocation = "dynamic"
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ip_configuration {
|
2016-06-02 01:54:20 +02:00
|
|
|
// name = "testconfiguration2"
|
|
|
|
// subnet_id = "${azurerm_subnet.test1.id}"
|
2016-01-09 21:01:30 +01:00
|
|
|
// private_ip_address_allocation = "dynamic"
|
2016-06-02 01:54:20 +02:00
|
|
|
// primary = true
|
2016-01-09 21:01:30 +01:00
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//`
|