From af5baf7b13186de0adb833aac3e2d24194d5db25 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sat, 31 Dec 2016 11:09:56 -0700 Subject: [PATCH] provider/openstack: Network and Object Storage Acceptance Test Cleanup (#10967) * provider/openstack: Updating Networking acceptance tests * provider/openstack: Updating Object Storage acceptance tests --- .../resource_openstack_lb_pool_v1_test.go | 8 +- ...openstack_networking_floatingip_v2_test.go | 144 +++---- ...ce_openstack_networking_network_v2_test.go | 187 ++++----- ...ource_openstack_networking_port_v2_test.go | 221 +++++----- ...ack_networking_router_interface_v2_test.go | 117 +++--- ...enstack_networking_router_route_v2_test.go | 378 +++++++++--------- ...rce_openstack_networking_router_v2_test.go | 76 ++-- ...nstack_networking_secgroup_rule_v2_test.go | 126 +++--- ...e_openstack_networking_secgroup_v2_test.go | 34 +- ...rce_openstack_networking_subnet_v2_test.go | 186 +++++---- ...enstack_objectstorage_container_v1_test.go | 46 ++- 11 files changed, 801 insertions(+), 722 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go b/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go index e94fc773b..b621d3da3 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v1_test.go @@ -58,8 +58,8 @@ func TestAccLBV1Pool_fullstack(t *testing.T) { resource.TestStep{ Config: testAccLBV1Pool_fullstack_1, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2), @@ -71,8 +71,8 @@ func TestAccLBV1Pool_fullstack(t *testing.T) { resource.TestStep{ Config: testAccLBV1Pool_fullstack_2, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2), diff --git a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2_test.go index bbffe022f..b8b31e8b9 100644 --- a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2_test.go @@ -2,7 +2,6 @@ package openstack import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -13,7 +12,7 @@ import ( ) func TestAccNetworkingV2FloatingIP_basic(t *testing.T) { - var floatingIP floatingips.FloatingIP + var fip floatingips.FloatingIP resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -23,7 +22,7 @@ func TestAccNetworkingV2FloatingIP_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2FloatingIP_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2FloatingIPExists(t, "openstack_networking_floatingip_v2.foo", &floatingIP), + testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip), ), }, }, @@ -33,20 +32,6 @@ func TestAccNetworkingV2FloatingIP_basic(t *testing.T) { func TestAccNetworkingV2FloatingIP_attach(t *testing.T) { var instance servers.Server var fip floatingips.FloatingIP - var testAccNetworkV2FloatingIP_attach = fmt.Sprintf(` - resource "openstack_networking_floatingip_v2" "myip" { - } - - resource "openstack_compute_instance_v2" "foo" { - name = "terraform-test" - security_groups = ["default"] - floating_ip = "${openstack_networking_floatingip_v2.myip.address}" - - network { - uuid = "%s" - } - }`, - os.Getenv("OS_NETWORK_ID")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -56,8 +41,8 @@ func TestAccNetworkingV2FloatingIP_attach(t *testing.T) { resource.TestStep{ Config: testAccNetworkV2FloatingIP_attach, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2FloatingIPExists(t, "openstack_networking_floatingip_v2.myip", &fip), - testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.foo", &instance), + testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip), + testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), testAccCheckNetworkingV2InstanceFloatingIPAttach(&instance, &fip), ), }, @@ -67,48 +52,6 @@ func TestAccNetworkingV2FloatingIP_attach(t *testing.T) { func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) { var fip floatingips.FloatingIP - var testAccNetworkingV2FloatingIP_fixedip_bind = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } - - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } - - resource "openstack_networking_router_interface_v2" "router_interface_1" { - router_id = "${openstack_networking_router_v2.router_1.id}" - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - } - - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - external_gateway = "%s" - } - - resource "openstack_networking_port_v2" "port_1" { - network_id = "${openstack_networking_subnet_v2.subnet_1.network_id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.10" - } - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.20" - } - } - - resource "openstack_networking_floatingip_v2" "ip_1" { - pool = "%s" - port_id = "${openstack_networking_port_v2.port_1.id}" - fixed_ip = "${openstack_networking_port_v2.port_1.fixed_ip.1.ip_address}" - }`, - os.Getenv("OS_EXTGW_ID"), os.Getenv("OS_POOL_NAME")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -118,8 +61,8 @@ func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2FloatingIP_fixedip_bind, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2FloatingIPExists(t, "openstack_networking_floatingip_v2.ip_1", &fip), - testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(t, &fip, "192.168.199.20"), + testAccCheckNetworkingV2FloatingIPExists("openstack_networking_floatingip_v2.fip_1", &fip), + testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(&fip, "192.168.199.20"), ), }, }, @@ -130,7 +73,7 @@ func testAccCheckNetworkingV2FloatingIPDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2FloatingIPDestroy) Error creating OpenStack floating IP: %s", err) + return fmt.Errorf("Error creating OpenStack floating IP: %s", err) } for _, rs := range s.RootModule().Resources { @@ -147,7 +90,7 @@ func testAccCheckNetworkingV2FloatingIPDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2FloatingIPExists(t *testing.T, n string, kp *floatingips.FloatingIP) resource.TestCheckFunc { +func testAccCheckNetworkingV2FloatingIPExists(n string, kp *floatingips.FloatingIP) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -161,7 +104,7 @@ func testAccCheckNetworkingV2FloatingIPExists(t *testing.T, n string, kp *floati config := testAccProvider.Meta().(*Config) networkClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2FloatingIPExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := floatingips.Get(networkClient, rs.Primary.ID).Extract() @@ -179,7 +122,7 @@ func testAccCheckNetworkingV2FloatingIPExists(t *testing.T, n string, kp *floati } } -func testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(t *testing.T, fip *floatingips.FloatingIP, fixed_ip string) resource.TestCheckFunc { +func testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(fip *floatingips.FloatingIP, fixed_ip string) resource.TestCheckFunc { return func(s *terraform.State) error { if fip.FixedIP != fixed_ip { return fmt.Errorf("Floating ip associated with wrong fixed ip") @@ -211,6 +154,67 @@ func testAccCheckNetworkingV2InstanceFloatingIPAttach( } } -var testAccNetworkingV2FloatingIP_basic = ` - resource "openstack_networking_floatingip_v2" "foo" { - }` +const testAccNetworkingV2FloatingIP_basic = ` +resource "openstack_networking_floatingip_v2" "fip_1" { +} +` + +var testAccNetworkV2FloatingIP_attach = fmt.Sprintf(` +resource "openstack_networking_floatingip_v2" "fip_1" { +} + +resource "openstack_compute_instance_v2" "instance_1" { + name = "instance_1" + security_groups = ["default"] + floating_ip = "${openstack_networking_floatingip_v2.fip_1.address}" + + network { + uuid = "%s" + } +} +`, OS_NETWORK_ID) + +var testAccNetworkingV2FloatingIP_fixedip_bind = fmt.Sprintf(` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_networking_router_interface_v2" "router_interface_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} + +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + external_gateway = "%s" +} + +resource "openstack_networking_port_v2" "port_1" { + admin_state_up = "true" + network_id = "${openstack_networking_subnet_v2.subnet_1.network_id}" + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.10" + } + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.20" + } +} + +resource "openstack_networking_floatingip_v2" "fip_1" { + pool = "%s" + port_id = "${openstack_networking_port_v2.port_1.id}" + fixed_ip = "${openstack_networking_port_v2.port_1.fixed_ip.1.ip_address}" +} +`, OS_EXTGW_ID, OS_POOL_NAME) diff --git a/builtin/providers/openstack/resource_openstack_networking_network_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_network_v2_test.go index 9679a83ff..14415f884 100644 --- a/builtin/providers/openstack/resource_openstack_networking_network_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_network_v2_test.go @@ -26,13 +26,14 @@ func TestAccNetworkingV2Network_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Network_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), ), }, resource.TestStep{ Config: testAccNetworkingV2Network_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_networking_network_v2.foo", "name", "network_2"), + resource.TestCheckResourceAttr( + "openstack_networking_network_v2.network_1", "name", "network_2"), ), }, }, @@ -44,28 +45,6 @@ func TestAccNetworkingV2Network_netstack(t *testing.T) { var subnet subnets.Subnet var router routers.Router - var testAccNetworkingV2Network_netstack = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_1" - admin_state_up = "true" - } - - resource "openstack_networking_subnet_v2" "foo" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.foo.id}" - cidr = "192.168.10.0/24" - ip_version = 4 - } - - resource "openstack_networking_router_v2" "foo" { - name = "router_1" - } - - resource "openstack_networking_router_interface_v2" "foo" { - router_id = "${openstack_networking_router_v2.foo.id}" - subnet_id = "${openstack_networking_subnet_v2.foo.id}" - }`) - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -74,10 +53,11 @@ func TestAccNetworkingV2Network_netstack(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Network_netstack, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.foo", &subnet), - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.foo", &router), - testAccCheckNetworkingV2RouterInterfaceExists(t, "openstack_networking_router_interface_v2.foo"), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), + testAccCheckNetworkingV2RouterInterfaceExists( + "openstack_networking_router_interface_v2.ri_1"), ), }, }, @@ -91,50 +71,6 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) { var secgroup secgroups.SecurityGroup var subnet subnets.Subnet - var testAccNetworkingV2Network_fullstack = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_1" - admin_state_up = "true" - } - - resource "openstack_networking_subnet_v2" "foo" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.foo.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } - - resource "openstack_compute_secgroup_v2" "foo" { - name = "secgroup_1" - description = "a security group" - rule { - from_port = 22 - to_port = 22 - ip_protocol = "tcp" - cidr = "0.0.0.0/0" - } - } - - resource "openstack_networking_port_v2" "foo" { - name = "port_1" - network_id = "${openstack_networking_network_v2.foo.id}" - admin_state_up = "true" - security_group_ids = ["${openstack_compute_secgroup_v2.foo.id}"] - fixed_ip { - "subnet_id" = "${openstack_networking_subnet_v2.foo.id}" - "ip_address" = "192.168.199.23" - } - } - - resource "openstack_compute_instance_v2" "foo" { - name = "terraform-test" - security_groups = ["${openstack_compute_secgroup_v2.foo.name}"] - - network { - port = "${openstack_networking_port_v2.foo.id}" - } - }`) - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -143,11 +79,11 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Network_fullstack, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.foo", &subnet), - testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.foo", &secgroup), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.foo", &port), - testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.foo", &instance), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.port_1", &port), + testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), ), }, }, @@ -158,7 +94,7 @@ func testAccCheckNetworkingV2NetworkDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2NetworkDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -175,7 +111,7 @@ func testAccCheckNetworkingV2NetworkDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2NetworkExists(t *testing.T, n string, network *networks.Network) resource.TestCheckFunc { +func testAccCheckNetworkingV2NetworkExists(n string, network *networks.Network) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -189,7 +125,7 @@ func testAccCheckNetworkingV2NetworkExists(t *testing.T, n string, network *netw config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2NetworkExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := networks.Get(networkingClient, rs.Primary.ID).Extract() @@ -207,14 +143,85 @@ func testAccCheckNetworkingV2NetworkExists(t *testing.T, n string, network *netw } } -var testAccNetworkingV2Network_basic = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_1" - admin_state_up = "true" - }`) +const testAccNetworkingV2Network_basic = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} +` -var testAccNetworkingV2Network_update = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_2" - admin_state_up = "true" - }`) +const testAccNetworkingV2Network_update = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_2" + admin_state_up = "true" +} +` + +const testAccNetworkingV2Network_netstack = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.10.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" +} + +resource "openstack_networking_router_interface_v2" "ri_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" +} +` + +const testAccNetworkingV2Network_fullstack = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} + +resource "openstack_compute_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "a security group" + rule { + from_port = 22 + to_port = 22 + ip_protocol = "tcp" + cidr = "0.0.0.0/0" + } +} + +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + security_group_ids = ["${openstack_compute_secgroup_v2.secgroup_1.id}"] + network_id = "${openstack_networking_network_v2.network_1.id}" + + fixed_ip { + "subnet_id" = "${openstack_networking_subnet_v2.subnet_1.id}" + "ip_address" = "192.168.199.23" + } +} + +resource "openstack_compute_instance_v2" "instance_1" { + name = "instance_1" + security_groups = ["${openstack_compute_secgroup_v2.secgroup_1.name}"] + + network { + port = "${openstack_networking_port_v2.port_1.id}" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_port_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_port_v2_test.go index a318f82a5..7eb2bdb07 100644 --- a/builtin/providers/openstack/resource_openstack_networking_port_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_port_v2_test.go @@ -25,9 +25,9 @@ func TestAccNetworkingV2Port_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Port_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.foo", &subnet), - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.foo", &port), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.port_1", &port), ), }, }, @@ -47,9 +47,9 @@ func TestAccNetworkingV2Port_noip(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Port_noip, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.foo", &subnet), - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.foo", &network), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.foo", &port), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.port_1", &port), ), }, }, @@ -69,11 +69,11 @@ func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Port_allowedAddressPairs, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.vrrp_subnet", &subnet), - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.vrrp_network", &network), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_1", &vrrp_port_1), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_2", &vrrp_port_2), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.instance_port", &instance_port), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.vrrp_subnet", &subnet), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.vrrp_network", &network), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.vrrp_port_1", &vrrp_port_1), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.vrrp_port_2", &vrrp_port_2), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.instance_port", &instance_port), ), }, }, @@ -84,7 +84,7 @@ func testAccCheckNetworkingV2PortDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2PortDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -101,7 +101,7 @@ func testAccCheckNetworkingV2PortDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port) resource.TestCheckFunc { +func testAccCheckNetworkingV2PortExists(n string, port *ports.Port) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -115,7 +115,7 @@ func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2PortExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := ports.Get(networkingClient, rs.Primary.ID).Extract() @@ -133,108 +133,117 @@ func testAccCheckNetworkingV2PortExists(t *testing.T, n string, port *ports.Port } } -var testAccNetworkingV2Port_basic = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_1" - admin_state_up = "true" - } +const testAccNetworkingV2Port_basic = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "foo" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.foo.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - resource "openstack_networking_port_v2" "foo" { - name = "port_1" - network_id = "${openstack_networking_network_v2.foo.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.foo.id}" - ip_address = "192.168.199.23" - } - }`) +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" -var testAccNetworkingV2Port_noip = fmt.Sprintf(` - resource "openstack_networking_network_v2" "foo" { - name = "network_1" - admin_state_up = "true" - } - resource "openstack_networking_subnet_v2" "foo" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.foo.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } - resource "openstack_networking_port_v2" "foo" { - name = "port_1" - network_id = "${openstack_networking_network_v2.foo.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.foo.id}" - } - }`) + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.23" + } +} +` -var testAccNetworkingV2Port_allowedAddressPairs = fmt.Sprintf(` - resource "openstack_networking_network_v2" "vrrp_network" { - name = "vrrp_network" - admin_state_up = "true" - } +const testAccNetworkingV2Port_noip = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "vrrp_subnet" { - name = "vrrp_subnet" - network_id = "${openstack_networking_network_v2.vrrp_network.id}" - cidr = "10.0.0.0/24" - ip_version = 4 +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - allocation_pools { - start = "10.0.0.2" - end = "10.0.0.200" - } - } +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" - resource "openstack_networking_router_v2" "vrrp_router" { - name = "vrrp_router" - } + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + } +} +` - resource "openstack_networking_router_interface_v2" "vrrp_interface" { - router_id = "${openstack_networking_router_v2.vrrp_router.id}" - subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" - } +const testAccNetworkingV2Port_allowedAddressPairs = ` +resource "openstack_networking_network_v2" "vrrp_network" { + name = "vrrp_network" + admin_state_up = "true" +} - resource "openstack_networking_port_v2" "vrrp_port_1" { - name = "vrrp_port_1" - network_id = "${openstack_networking_network_v2.vrrp_network.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" - ip_address = "10.0.0.202" - } - } +resource "openstack_networking_subnet_v2" "vrrp_subnet" { + name = "vrrp_subnet" + cidr = "10.0.0.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.vrrp_network.id}" - resource "openstack_networking_port_v2" "vrrp_port_2" { - name = "vrrp_port_2" - network_id = "${openstack_networking_network_v2.vrrp_network.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" - ip_address = "10.0.0.201" - } - } + allocation_pools { + start = "10.0.0.2" + end = "10.0.0.200" + } +} - resource "openstack_networking_port_v2" "instance_port" { - name = "instance_port" - network_id = "${openstack_networking_network_v2.vrrp_network.id}" - admin_state_up = "true" +resource "openstack_networking_router_v2" "vrrp_router" { + name = "vrrp_router" +} - allowed_address_pairs { - ip_address = "${openstack_networking_port_v2.vrrp_port_1.fixed_ip.0.ip_address}" - mac_address = "${openstack_networking_port_v2.vrrp_port_1.mac_address}" - } +resource "openstack_networking_router_interface_v2" "vrrp_interface" { + router_id = "${openstack_networking_router_v2.vrrp_router.id}" + subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" +} - allowed_address_pairs { - ip_address = "${openstack_networking_port_v2.vrrp_port_2.fixed_ip.0.ip_address}" - mac_address = "${openstack_networking_port_v2.vrrp_port_2.mac_address}" - } - }`) +resource "openstack_networking_port_v2" "vrrp_port_1" { + name = "vrrp_port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.vrrp_network.id}" + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" + ip_address = "10.0.0.202" + } +} + +resource "openstack_networking_port_v2" "vrrp_port_2" { + name = "vrrp_port_2" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.vrrp_network.id}" + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}" + ip_address = "10.0.0.201" + } +} + +resource "openstack_networking_port_v2" "instance_port" { + name = "instance_port" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.vrrp_network.id}" + + allowed_address_pairs { + ip_address = "${openstack_networking_port_v2.vrrp_port_1.fixed_ip.0.ip_address}" + mac_address = "${openstack_networking_port_v2.vrrp_port_1.mac_address}" + } + + allowed_address_pairs { + ip_address = "${openstack_networking_port_v2.vrrp_port_2.fixed_ip.0.ip_address}" + mac_address = "${openstack_networking_port_v2.vrrp_port_2.mac_address}" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_router_interface_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_router_interface_v2_test.go index 28b4b0580..0f41db18b 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_interface_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_interface_v2_test.go @@ -26,10 +26,10 @@ func TestAccNetworkingV2RouterInterface_basic_subnet(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2RouterInterface_basic_subnet, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.router_1", &router), - testAccCheckNetworkingV2RouterInterfaceExists(t, "openstack_networking_router_interface_v2.int_1"), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), + testAccCheckNetworkingV2RouterInterfaceExists("openstack_networking_router_interface_v2.int_1"), ), }, }, @@ -50,11 +50,11 @@ func TestAccNetworkingV2RouterInterface_basic_port(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2RouterInterface_basic_port, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.router_1", &router), - testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.port_1", &port), - testAccCheckNetworkingV2RouterInterfaceExists(t, "openstack_networking_router_interface_v2.int_1"), + testAccCheckNetworkingV2NetworkExists("openstack_networking_network_v2.network_1", &network), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), + testAccCheckNetworkingV2PortExists("openstack_networking_port_v2.port_1", &port), + testAccCheckNetworkingV2RouterInterfaceExists("openstack_networking_router_interface_v2.int_1"), ), }, }, @@ -65,7 +65,7 @@ func testAccCheckNetworkingV2RouterInterfaceDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterInterfaceDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -82,7 +82,7 @@ func testAccCheckNetworkingV2RouterInterfaceDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2RouterInterfaceExists(t *testing.T, n string) resource.TestCheckFunc { +func testAccCheckNetworkingV2RouterInterfaceExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -96,7 +96,7 @@ func testAccCheckNetworkingV2RouterInterfaceExists(t *testing.T, n string) resou config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterInterfaceExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := ports.Get(networkingClient, rs.Primary.ID).Extract() @@ -112,56 +112,59 @@ func testAccCheckNetworkingV2RouterInterfaceExists(t *testing.T, n string) resou } } -var testAccNetworkingV2RouterInterface_basic_subnet = fmt.Sprintf(` - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - admin_state_up = "true" - } +const testAccNetworkingV2RouterInterface_basic_subnet = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" +} - resource "openstack_networking_router_interface_v2" "int_1" { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - router_id = "${openstack_networking_router_v2.router_1.id}" - } +resource "openstack_networking_router_interface_v2" "int_1" { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + router_id = "${openstack_networking_router_v2.router_1.id}" +} - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - }`) +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} +` -var testAccNetworkingV2RouterInterface_basic_port = fmt.Sprintf(` - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - admin_state_up = "true" - } +const testAccNetworkingV2RouterInterface_basic_port = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" +} - resource "openstack_networking_router_interface_v2" "int_1" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_1.id}" - } +resource "openstack_networking_router_interface_v2" "int_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_1.id}" +} - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - resource "openstack_networking_port_v2" "port_1" { - name = "port_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.1" - } - }`) +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.1" + } +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_router_route_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_router_route_v2_test.go index a785a1edb..e5965c20e 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_route_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_route_v2_test.go @@ -24,34 +24,43 @@ func TestAccNetworkingV2RouterRoute_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2RouterRoute_create, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.router_1", &router), - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network[0]), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet[0]), - testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.network_1", &network[1]), - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet[1]), - testAccCheckNetworkingV2RouterInterfaceExists(t, "openstack_networking_router_interface_v2.int_1"), - testAccCheckNetworkingV2RouterInterfaceExists(t, "openstack_networking_router_interface_v2.int_2"), - testAccCheckNetworkingV2RouterRouteExists(t, "openstack_networking_router_route_v2.router_route_1"), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), + testAccCheckNetworkingV2NetworkExists( + "openstack_networking_network_v2.network_1", &network[0]), + testAccCheckNetworkingV2SubnetExists( + "openstack_networking_subnet_v2.subnet_1", &subnet[0]), + testAccCheckNetworkingV2NetworkExists( + "openstack_networking_network_v2.network_1", &network[1]), + testAccCheckNetworkingV2SubnetExists( + "openstack_networking_subnet_v2.subnet_1", &subnet[1]), + testAccCheckNetworkingV2RouterInterfaceExists( + "openstack_networking_router_interface_v2.int_1"), + testAccCheckNetworkingV2RouterInterfaceExists( + "openstack_networking_router_interface_v2.int_2"), + testAccCheckNetworkingV2RouterRouteExists( + "openstack_networking_router_route_v2.router_route_1"), ), }, resource.TestStep{ Config: testAccNetworkingV2RouterRoute_update, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2RouterRouteExists(t, "openstack_networking_router_route_v2.router_route_1"), - testAccCheckNetworkingV2RouterRouteExists(t, "openstack_networking_router_route_v2.router_route_2"), + testAccCheckNetworkingV2RouterRouteExists( + "openstack_networking_router_route_v2.router_route_1"), + testAccCheckNetworkingV2RouterRouteExists( + "openstack_networking_router_route_v2.router_route_2"), ), }, resource.TestStep{ Config: testAccNetworkingV2RouterRoute_destroy, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2RouterRouteEmpty(t, "openstack_networking_router_v2.router_1"), + testAccCheckNetworkingV2RouterRouteEmpty("openstack_networking_router_v2.router_1"), ), }, }, }) } -func testAccCheckNetworkingV2RouterRouteEmpty(t *testing.T, n string) resource.TestCheckFunc { +func testAccCheckNetworkingV2RouterRouteEmpty(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -65,7 +74,7 @@ func testAccCheckNetworkingV2RouterRouteEmpty(t *testing.T, n string) resource.T config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterRouteExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } router, err := routers.Get(networkingClient, rs.Primary.ID).Extract() @@ -85,7 +94,7 @@ func testAccCheckNetworkingV2RouterRouteEmpty(t *testing.T, n string) resource.T } } -func testAccCheckNetworkingV2RouterRouteExists(t *testing.T, n string) resource.TestCheckFunc { +func testAccCheckNetworkingV2RouterRouteExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -99,7 +108,7 @@ func testAccCheckNetworkingV2RouterRouteExists(t *testing.T, n string) resource. config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterRouteExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } router, err := routers.Get(networkingClient, rs.Primary.Attributes["router_id"]).Extract() @@ -125,200 +134,209 @@ func testAccCheckNetworkingV2RouterRouteExists(t *testing.T, n string) resource. } } -var testAccNetworkingV2RouterRoute_create = fmt.Sprintf(` - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - admin_state_up = "true" - } +const testAccNetworkingV2RouterRoute_create = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" +} - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - resource "openstack_networking_port_v2" "port_1" { - name = "port_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.1" - } - } +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" - resource "openstack_networking_router_interface_v2" "int_1" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_1.id}" - } + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.1" + } +} - resource "openstack_networking_network_v2" "network_2" { - name = "network_2" - admin_state_up = "true" - } +resource "openstack_networking_router_interface_v2" "int_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_1.id}" +} - resource "openstack_networking_subnet_v2" "subnet_2" { - network_id = "${openstack_networking_network_v2.network_2.id}" - cidr = "192.168.200.0/24" - ip_version = 4 - } +resource "openstack_networking_network_v2" "network_2" { + name = "network_2" + admin_state_up = "true" +} - resource "openstack_networking_port_v2" "port_2" { - name = "port_2" - network_id = "${openstack_networking_network_v2.network_2.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" - ip_address = "192.168.200.1" - } - } +resource "openstack_networking_subnet_v2" "subnet_2" { + cidr = "192.168.200.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_2.id}" +} - resource "openstack_networking_router_interface_v2" "int_2" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_2.id}" - } +resource "openstack_networking_port_v2" "port_2" { + name = "port_2" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_2.id}" - resource "openstack_networking_router_route_v2" "router_route_1" { - depends_on = ["openstack_networking_router_interface_v2.int_1"] - router_id = "${openstack_networking_router_v2.router_1.id}" + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" + ip_address = "192.168.200.1" + } +} - destination_cidr = "10.0.1.0/24" - next_hop = "192.168.199.254" - }`) +resource "openstack_networking_router_interface_v2" "int_2" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_2.id}" +} -var testAccNetworkingV2RouterRoute_update = fmt.Sprintf(` - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - admin_state_up = "true" - } +resource "openstack_networking_router_route_v2" "router_route_1" { + destination_cidr = "10.0.1.0/24" + next_hop = "192.168.199.254" - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } + depends_on = ["openstack_networking_router_interface_v2.int_1"] + router_id = "${openstack_networking_router_v2.router_1.id}" +} +` - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } +const testAccNetworkingV2RouterRoute_update = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" +} - resource "openstack_networking_port_v2" "port_1" { - name = "port_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.1" - } - } +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_router_interface_v2" "int_1" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_1.id}" - } +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - resource "openstack_networking_network_v2" "network_2" { - name = "network_2" - admin_state_up = "true" - } +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" - resource "openstack_networking_subnet_v2" "subnet_2" { - network_id = "${openstack_networking_network_v2.network_2.id}" - cidr = "192.168.200.0/24" - ip_version = 4 - } + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.1" + } +} - resource "openstack_networking_port_v2" "port_2" { - name = "port_2" - network_id = "${openstack_networking_network_v2.network_2.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" - ip_address = "192.168.200.1" - } - } +resource "openstack_networking_router_interface_v2" "int_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_1.id}" +} - resource "openstack_networking_router_interface_v2" "int_2" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_2.id}" - } +resource "openstack_networking_network_v2" "network_2" { + name = "network_2" + admin_state_up = "true" +} - resource "openstack_networking_router_route_v2" "router_route_1" { - depends_on = ["openstack_networking_router_interface_v2.int_1"] - router_id = "${openstack_networking_router_v2.router_1.id}" +resource "openstack_networking_subnet_v2" "subnet_2" { + cidr = "192.168.200.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_2.id}" +} - destination_cidr = "10.0.1.0/24" - next_hop = "192.168.199.254" - } +resource "openstack_networking_port_v2" "port_2" { + name = "port_2" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_2.id}" - resource "openstack_networking_router_route_v2" "router_route_2" { - depends_on = ["openstack_networking_router_interface_v2.int_2"] - router_id = "${openstack_networking_router_v2.router_1.id}" + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" + ip_address = "192.168.200.1" + } +} - destination_cidr = "10.0.2.0/24" - next_hop = "192.168.200.254" - }`) +resource "openstack_networking_router_interface_v2" "int_2" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_2.id}" +} -var testAccNetworkingV2RouterRoute_destroy = fmt.Sprintf(` - resource "openstack_networking_router_v2" "router_1" { - name = "router_1" - admin_state_up = "true" - } +resource "openstack_networking_router_route_v2" "router_route_1" { + destination_cidr = "10.0.1.0/24" + next_hop = "192.168.199.254" - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } + depends_on = ["openstack_networking_router_interface_v2.int_1"] + router_id = "${openstack_networking_router_v2.router_1.id}" +} - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - ip_version = 4 - } +resource "openstack_networking_router_route_v2" "router_route_2" { + destination_cidr = "10.0.2.0/24" + next_hop = "192.168.200.254" - resource "openstack_networking_port_v2" "port_1" { - name = "port_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" - ip_address = "192.168.199.1" - } - } + depends_on = ["openstack_networking_router_interface_v2.int_2"] + router_id = "${openstack_networking_router_v2.router_1.id}" +} +` - resource "openstack_networking_router_interface_v2" "int_1" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_1.id}" - } +const testAccNetworkingV2RouterRoute_destroy = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" +} - resource "openstack_networking_network_v2" "network_2" { - name = "network_2" - admin_state_up = "true" - } +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} - resource "openstack_networking_subnet_v2" "subnet_2" { - network_id = "${openstack_networking_network_v2.network_2.id}" - cidr = "192.168.200.0/24" - ip_version = 4 - } +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + ip_version = 4 + network_id = "${openstack_networking_network_v2.network_1.id}" +} - resource "openstack_networking_port_v2" "port_2" { - name = "port_2" - network_id = "${openstack_networking_network_v2.network_2.id}" - admin_state_up = "true" - fixed_ip { - subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" - ip_address = "192.168.200.1" - } - } +resource "openstack_networking_port_v2" "port_1" { + name = "port_1" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_1.id}" - resource "openstack_networking_router_interface_v2" "int_2" { - router_id = "${openstack_networking_router_v2.router_1.id}" - port_id = "${openstack_networking_port_v2.port_2.id}" - }`) + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" + ip_address = "192.168.199.1" + } +} + +resource "openstack_networking_router_interface_v2" "int_1" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_1.id}" +} + +resource "openstack_networking_network_v2" "network_2" { + name = "network_2" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_2" { + ip_version = 4 + cidr = "192.168.200.0/24" + network_id = "${openstack_networking_network_v2.network_2.id}" +} + +resource "openstack_networking_port_v2" "port_2" { + name = "port_2" + admin_state_up = "true" + network_id = "${openstack_networking_network_v2.network_2.id}" + + fixed_ip { + subnet_id = "${openstack_networking_subnet_v2.subnet_2.id}" + ip_address = "192.168.200.1" + } +} + +resource "openstack_networking_router_interface_v2" "int_2" { + router_id = "${openstack_networking_router_v2.router_1.id}" + port_id = "${openstack_networking_port_v2.port_2.id}" +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_router_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_router_v2_test.go index e6a798692..bff9c4fbd 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_v2_test.go @@ -2,7 +2,6 @@ package openstack import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform/helper/resource" @@ -22,13 +21,14 @@ func TestAccNetworkingV2Router_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Router_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.foo", &router), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), ), }, resource.TestStep{ Config: testAccNetworkingV2Router_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_networking_router_v2.foo", "name", "router_2"), + resource.TestCheckResourceAttr( + "openstack_networking_router_v2.router_1", "name", "router_2"), ), }, }, @@ -37,22 +37,6 @@ func TestAccNetworkingV2Router_basic(t *testing.T) { func TestAccNetworkingV2Router_update_external_gw(t *testing.T) { var router routers.Router - externalGateway := os.Getenv("OS_EXTGW_ID") - - var testAccNetworkingV2Router_update_external_gw_1 = fmt.Sprintf(` - resource "openstack_networking_router_v2" "foo" { - name = "router" - admin_state_up = "true" - distributed = "false" - }`) - - var testAccNetworkingV2Router_update_external_gw_2 = fmt.Sprintf(` - resource "openstack_networking_router_v2" "foo" { - name = "router" - admin_state_up = "true" - distributed = "false" - external_gateway = "%s" - }`, externalGateway) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -62,13 +46,14 @@ func TestAccNetworkingV2Router_update_external_gw(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Router_update_external_gw_1, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2RouterExists(t, "openstack_networking_router_v2.foo", &router), + testAccCheckNetworkingV2RouterExists("openstack_networking_router_v2.router_1", &router), ), }, resource.TestStep{ Config: testAccNetworkingV2Router_update_external_gw_2, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_networking_router_v2.foo", "external_gateway", externalGateway), + resource.TestCheckResourceAttr( + "openstack_networking_router_v2.router_1", "external_gateway", OS_EXTGW_ID), ), }, }, @@ -79,7 +64,7 @@ func testAccCheckNetworkingV2RouterDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -96,7 +81,7 @@ func testAccCheckNetworkingV2RouterDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2RouterExists(t *testing.T, n string, router *routers.Router) resource.TestCheckFunc { +func testAccCheckNetworkingV2RouterExists(n string, router *routers.Router) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -110,7 +95,7 @@ func testAccCheckNetworkingV2RouterExists(t *testing.T, n string, router *router config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2RouterExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := routers.Get(networkingClient, rs.Primary.ID).Extract() @@ -128,16 +113,35 @@ func testAccCheckNetworkingV2RouterExists(t *testing.T, n string, router *router } } -var testAccNetworkingV2Router_basic = fmt.Sprintf(` - resource "openstack_networking_router_v2" "foo" { - name = "router" - admin_state_up = "true" - distributed = "false" - }`) +const testAccNetworkingV2Router_basic = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_1" + admin_state_up = "true" + distributed = "false" +} +` -var testAccNetworkingV2Router_update = fmt.Sprintf(` - resource "openstack_networking_router_v2" "foo" { - name = "router_2" - admin_state_up = "true" - distributed = "false" - }`) +const testAccNetworkingV2Router_update = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router_2" + admin_state_up = "true" + distributed = "false" +} +` + +const testAccNetworkingV2Router_update_external_gw_1 = ` +resource "openstack_networking_router_v2" "router_1" { + name = "router" + admin_state_up = "true" + distributed = "false" +} +` + +var testAccNetworkingV2Router_update_external_gw_2 = fmt.Sprintf(` +resource "openstack_networking_router_v2" "router_1" { + name = "router" + admin_state_up = "true" + distributed = "false" + external_gateway = "%s" +} +`, OS_EXTGW_ID) diff --git a/builtin/providers/openstack/resource_openstack_networking_secgroup_rule_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_secgroup_rule_v2_test.go index 5d3d7e972..bdc787c06 100644 --- a/builtin/providers/openstack/resource_openstack_networking_secgroup_rule_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_secgroup_rule_v2_test.go @@ -12,10 +12,10 @@ import ( ) func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) { - var security_group_1 groups.SecGroup - var security_group_2 groups.SecGroup - var security_group_rule_1 rules.SecGroupRule - var security_group_rule_2 rules.SecGroupRule + var secgroup_1 groups.SecGroup + var secgroup_2 groups.SecGroup + var secgroup_rule_1 rules.SecGroupRule + var secgroup_rule_2 rules.SecGroupRule resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -25,10 +25,14 @@ func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2SecGroupRule_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SecGroupExists(t, "openstack_networking_secgroup_v2.sg_foo", &security_group_1), - testAccCheckNetworkingV2SecGroupExists(t, "openstack_networking_secgroup_v2.sg_bar", &security_group_2), - testAccCheckNetworkingV2SecGroupRuleExists(t, "openstack_networking_secgroup_rule_v2.sr_foo", &security_group_rule_1), - testAccCheckNetworkingV2SecGroupRuleExists(t, "openstack_networking_secgroup_rule_v2.sr_bar", &security_group_rule_2), + testAccCheckNetworkingV2SecGroupExists( + "openstack_networking_secgroup_v2.secgroup_1", &secgroup_1), + testAccCheckNetworkingV2SecGroupExists( + "openstack_networking_secgroup_v2.secgroup_2", &secgroup_2), + testAccCheckNetworkingV2SecGroupRuleExists( + "openstack_networking_secgroup_rule_v2.secgroup_rule_1", &secgroup_rule_1), + testAccCheckNetworkingV2SecGroupRuleExists( + "openstack_networking_secgroup_rule_v2.secgroup_rule_2", &secgroup_rule_2), ), }, }, @@ -36,8 +40,8 @@ func TestAccNetworkingV2SecGroupRule_basic(t *testing.T) { } func TestAccNetworkingV2SecGroupRule_lowerCaseCIDR(t *testing.T) { - var security_group_1 groups.SecGroup - var security_group_rule_1 rules.SecGroupRule + var secgroup_1 groups.SecGroup + var secgroup_rule_1 rules.SecGroupRule resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -47,10 +51,12 @@ func TestAccNetworkingV2SecGroupRule_lowerCaseCIDR(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2SecGroupRule_lowerCaseCIDR, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SecGroupExists(t, "openstack_networking_secgroup_v2.sg_foo", &security_group_1), - testAccCheckNetworkingV2SecGroupRuleExists(t, "openstack_networking_secgroup_rule_v2.sr_foo", &security_group_rule_1), + testAccCheckNetworkingV2SecGroupExists( + "openstack_networking_secgroup_v2.secgroup_1", &secgroup_1), + testAccCheckNetworkingV2SecGroupRuleExists( + "openstack_networking_secgroup_rule_v2.secgroup_rule_1", &secgroup_rule_1), resource.TestCheckResourceAttr( - "openstack_networking_secgroup_rule_v2.sr_foo", "remote_ip_prefix", "2001:558:fc00::/39"), + "openstack_networking_secgroup_rule_v2.secgroup_rule_1", "remote_ip_prefix", "2001:558:fc00::/39"), ), }, }, @@ -61,7 +67,7 @@ func testAccCheckNetworkingV2SecGroupRuleDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SecGroupRuleDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -78,7 +84,7 @@ func testAccCheckNetworkingV2SecGroupRuleDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2SecGroupRuleExists(t *testing.T, n string, security_group_rule *rules.SecGroupRule) resource.TestCheckFunc { +func testAccCheckNetworkingV2SecGroupRuleExists(n string, security_group_rule *rules.SecGroupRule) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -92,7 +98,7 @@ func testAccCheckNetworkingV2SecGroupRuleExists(t *testing.T, n string, security config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SecGroupRuleExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := rules.Get(networkingClient, rs.Primary.ID).Extract() @@ -110,45 +116,51 @@ func testAccCheckNetworkingV2SecGroupRuleExists(t *testing.T, n string, security } } -var testAccNetworkingV2SecGroupRule_basic = fmt.Sprintf(` - resource "openstack_networking_secgroup_v2" "sg_foo" { - name = "security_group_1" - description = "terraform security group rule acceptance test" - } - resource "openstack_networking_secgroup_v2" "sg_bar" { - name = "security_group_2" - description = "terraform security group rule acceptance test" - } - resource "openstack_networking_secgroup_rule_v2" "sr_foo" { - direction = "ingress" - ethertype = "IPv4" - port_range_max = 22 - port_range_min = 22 - protocol = "tcp" - remote_ip_prefix = "0.0.0.0/0" - security_group_id = "${openstack_networking_secgroup_v2.sg_foo.id}" - } - resource "openstack_networking_secgroup_rule_v2" "sr_bar" { - direction = "ingress" - ethertype = "IPv4" - port_range_max = 80 - port_range_min = 80 - protocol = "tcp" - remote_group_id = "${openstack_networking_secgroup_v2.sg_foo.id}" - security_group_id = "${openstack_networking_secgroup_v2.sg_bar.id}" - }`) +const testAccNetworkingV2SecGroupRule_basic = ` +resource "openstack_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "terraform security group rule acceptance test" +} -var testAccNetworkingV2SecGroupRule_lowerCaseCIDR = fmt.Sprintf(` - resource "openstack_networking_secgroup_v2" "sg_foo" { - name = "security_group_1" - description = "terraform security group rule acceptance test" - } - resource "openstack_networking_secgroup_rule_v2" "sr_foo" { - direction = "ingress" - ethertype = "IPv6" - port_range_max = 22 - port_range_min = 22 - protocol = "tcp" - remote_ip_prefix = "2001:558:FC00::/39" - security_group_id = "${openstack_networking_secgroup_v2.sg_foo.id}" - }`) +resource "openstack_networking_secgroup_v2" "secgroup_2" { + name = "secgroup_2" + description = "terraform security group rule acceptance test" +} + +resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_1" { + direction = "ingress" + ethertype = "IPv4" + port_range_max = 22 + port_range_min = 22 + protocol = "tcp" + remote_ip_prefix = "0.0.0.0/0" + security_group_id = "${openstack_networking_secgroup_v2.secgroup_1.id}" +} + +resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_2" { + direction = "ingress" + ethertype = "IPv4" + port_range_max = 80 + port_range_min = 80 + protocol = "tcp" + remote_group_id = "${openstack_networking_secgroup_v2.secgroup_1.id}" + security_group_id = "${openstack_networking_secgroup_v2.secgroup_2.id}" +} +` + +const testAccNetworkingV2SecGroupRule_lowerCaseCIDR = ` +resource "openstack_networking_secgroup_v2" "secgroup_1" { + name = "secgroup_1" + description = "terraform security group rule acceptance test" +} + +resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_1" { + direction = "ingress" + ethertype = "IPv6" + port_range_max = 22 + port_range_min = 22 + protocol = "tcp" + remote_ip_prefix = "2001:558:FC00::/39" + security_group_id = "${openstack_networking_secgroup_v2.secgroup_1.id}" +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_secgroup_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_secgroup_v2_test.go index 1662f1e62..12e6c18f8 100644 --- a/builtin/providers/openstack/resource_openstack_networking_secgroup_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_secgroup_v2_test.go @@ -21,13 +21,15 @@ func TestAccNetworkingV2SecGroup_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2SecGroup_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SecGroupExists(t, "openstack_networking_secgroup_v2.foo", &security_group), + testAccCheckNetworkingV2SecGroupExists( + "openstack_networking_secgroup_v2.secgroup_1", &security_group), ), }, resource.TestStep{ Config: testAccNetworkingV2SecGroup_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_networking_secgroup_v2.foo", "name", "security_group_2"), + resource.TestCheckResourceAttr( + "openstack_networking_secgroup_v2.secgroup_1", "name", "security_group_2"), ), }, }, @@ -38,7 +40,7 @@ func testAccCheckNetworkingV2SecGroupDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SecGroupDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -55,7 +57,7 @@ func testAccCheckNetworkingV2SecGroupDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2SecGroupExists(t *testing.T, n string, security_group *groups.SecGroup) resource.TestCheckFunc { +func testAccCheckNetworkingV2SecGroupExists(n string, security_group *groups.SecGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -69,7 +71,7 @@ func testAccCheckNetworkingV2SecGroupExists(t *testing.T, n string, security_gro config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SecGroupExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := groups.Get(networkingClient, rs.Primary.ID).Extract() @@ -87,14 +89,16 @@ func testAccCheckNetworkingV2SecGroupExists(t *testing.T, n string, security_gro } } -var testAccNetworkingV2SecGroup_basic = fmt.Sprintf(` - resource "openstack_networking_secgroup_v2" "foo" { - name = "security_group" - description = "terraform security group acceptance test" - }`) +const testAccNetworkingV2SecGroup_basic = ` +resource "openstack_networking_secgroup_v2" "secgroup_1" { + name = "security_group" + description = "terraform security group acceptance test" +} +` -var testAccNetworkingV2SecGroup_update = fmt.Sprintf(` - resource "openstack_networking_secgroup_v2" "foo" { - name = "security_group_2" - description = "terraform security group acceptance test" - }`) +const testAccNetworkingV2SecGroup_update = ` +resource "openstack_networking_secgroup_v2" "secgroup_1" { + name = "security_group_2" + description = "terraform security group acceptance test" +} +` diff --git a/builtin/providers/openstack/resource_openstack_networking_subnet_v2_test.go b/builtin/providers/openstack/resource_openstack_networking_subnet_v2_test.go index b02087ab7..942d30755 100644 --- a/builtin/providers/openstack/resource_openstack_networking_subnet_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_networking_subnet_v2_test.go @@ -21,15 +21,18 @@ func TestAccNetworkingV2Subnet_basic(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Subnet_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), ), }, resource.TestStep{ Config: testAccNetworkingV2Subnet_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "name", "subnet_1"), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "gateway_ip", "192.168.199.1"), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "name", "subnet_1"), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "gateway_ip", "192.168.199.1"), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"), ), }, }, @@ -47,8 +50,9 @@ func TestAccNetworkingV2Subnet_enableDHCP(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Subnet_enableDHCP, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"), ), }, }, @@ -66,8 +70,9 @@ func TestAccNetworkingV2Subnet_disableDHCP(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Subnet_disableDHCP, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "false"), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "false"), ), }, }, @@ -85,8 +90,9 @@ func TestAccNetworkingV2Subnet_noGateway(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Subnet_noGateway, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "gateway_ip", ""), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "gateway_ip", ""), ), }, }, @@ -104,8 +110,9 @@ func TestAccNetworkingV2Subnet_impliedGateway(t *testing.T) { resource.TestStep{ Config: testAccNetworkingV2Subnet_impliedGateway, Check: resource.ComposeTestCheckFunc( - testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet), - resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "gateway_ip", "192.168.199.1"), + testAccCheckNetworkingV2SubnetExists("openstack_networking_subnet_v2.subnet_1", &subnet), + resource.TestCheckResourceAttr( + "openstack_networking_subnet_v2.subnet_1", "gateway_ip", "192.168.199.1"), ), }, }, @@ -116,7 +123,7 @@ func testAccCheckNetworkingV2SubnetDestroy(s *terraform.State) error { config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SubnetDestroy) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } for _, rs := range s.RootModule().Resources { @@ -133,7 +140,7 @@ func testAccCheckNetworkingV2SubnetDestroy(s *terraform.State) error { return nil } -func testAccCheckNetworkingV2SubnetExists(t *testing.T, n string, subnet *subnets.Subnet) resource.TestCheckFunc { +func testAccCheckNetworkingV2SubnetExists(n string, subnet *subnets.Subnet) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -147,7 +154,7 @@ func testAccCheckNetworkingV2SubnetExists(t *testing.T, n string, subnet *subnet config := testAccProvider.Meta().(*Config) networkingClient, err := config.networkingV2Client(OS_REGION_NAME) if err != nil { - return fmt.Errorf("(testAccCheckNetworkingV2SubnetExists) Error creating OpenStack networking client: %s", err) + return fmt.Errorf("Error creating OpenStack networking client: %s", err) } found, err := subnets.Get(networkingClient, rs.Primary.ID).Extract() @@ -165,84 +172,93 @@ func testAccCheckNetworkingV2SubnetExists(t *testing.T, n string, subnet *subnet } } -var testAccNetworkingV2Subnet_basic = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" +const testAccNetworkingV2Subnet_basic = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + cidr = "192.168.199.0/24" + network_id = "${openstack_networking_network_v2.network_1.id}" + + allocation_pools { + start = "192.168.199.100" + end = "192.168.199.200" } +} +` - resource "openstack_networking_subnet_v2" "subnet_1" { - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - allocation_pools { - start = "192.168.199.100" - end = "192.168.199.200" - } - }`) +const testAccNetworkingV2Subnet_update = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} -var testAccNetworkingV2Subnet_update = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + gateway_ip = "192.168.199.1" + network_id = "${openstack_networking_network_v2.network_1.id}" + + allocation_pools { + start = "192.168.199.100" + end = "192.168.199.200" } +} +` - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "subnet_1" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - gateway_ip = "192.168.199.1" - allocation_pools { - start = "192.168.199.100" - end = "192.168.199.200" - } - }`) +const testAccNetworkingV2Subnet_enableDHCP = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} -var testAccNetworkingV2Subnet_enableDHCP = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + gateway_ip = "192.168.199.1" + enable_dhcp = true + network_id = "${openstack_networking_network_v2.network_1.id}" +} +` - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "tf-test-subnet" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - gateway_ip = "192.168.199.1" - enable_dhcp = true - }`) +const testAccNetworkingV2Subnet_disableDHCP = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} -var testAccNetworkingV2Subnet_disableDHCP = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + enable_dhcp = false + network_id = "${openstack_networking_network_v2.network_1.id}" +} +` - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "tf-test-subnet" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - enable_dhcp = false - }`) +const testAccNetworkingV2Subnet_noGateway = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} -var testAccNetworkingV2Subnet_noGateway = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "tf-test-subnet" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - no_gateway = true - }`) +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + no_gateway = true + network_id = "${openstack_networking_network_v2.network_1.id}" +} +` -var testAccNetworkingV2Subnet_impliedGateway = fmt.Sprintf(` - resource "openstack_networking_network_v2" "network_1" { - name = "network_1" - admin_state_up = "true" - } - resource "openstack_networking_subnet_v2" "subnet_1" { - name = "tf-test-subnet" - network_id = "${openstack_networking_network_v2.network_1.id}" - cidr = "192.168.199.0/24" - }`) +const testAccNetworkingV2Subnet_impliedGateway = ` +resource "openstack_networking_network_v2" "network_1" { + name = "network_1" + admin_state_up = "true" +} +resource "openstack_networking_subnet_v2" "subnet_1" { + name = "subnet_1" + cidr = "192.168.199.0/24" + network_id = "${openstack_networking_network_v2.network_1.id}" +} +` diff --git a/builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go b/builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go index 4e6ef693c..e344dd115 100644 --- a/builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go +++ b/builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go @@ -10,7 +10,6 @@ import ( ) func TestAccObjectStorageV1Container_basic(t *testing.T) { - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -19,14 +18,17 @@ func TestAccObjectStorageV1Container_basic(t *testing.T) { resource.TestStep{ Config: testAccObjectStorageV1Container_basic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_objectstorage_container_v1.container_1", "name", "tf-test-container"), - resource.TestCheckResourceAttr("openstack_objectstorage_container_v1.container_1", "content_type", "application/json"), + resource.TestCheckResourceAttr( + "openstack_objectstorage_container_v1.container_1", "name", "container_1"), + resource.TestCheckResourceAttr( + "openstack_objectstorage_container_v1.container_1", "content_type", "application/json"), ), }, resource.TestStep{ Config: testAccObjectStorageV1Container_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("openstack_objectstorage_container_v1.container_1", "content_type", "text/plain"), + resource.TestCheckResourceAttr( + "openstack_objectstorage_container_v1.container_1", "content_type", "text/plain"), ), }, }, @@ -54,22 +56,22 @@ func testAccCheckObjectStorageV1ContainerDestroy(s *terraform.State) error { return nil } -var testAccObjectStorageV1Container_basic = fmt.Sprintf(` - resource "openstack_objectstorage_container_v1" "container_1" { - name = "tf-test-container" - metadata { - test = "true" - } - content_type = "application/json" - } -`) +const testAccObjectStorageV1Container_basic = ` +resource "openstack_objectstorage_container_v1" "container_1" { + name = "container_1" + metadata { + test = "true" + } + content_type = "application/json" +} +` -var testAccObjectStorageV1Container_update = fmt.Sprintf(` - resource "openstack_objectstorage_container_v1" "container_1" { - name = "tf-test-container" - metadata { - test = "true" - } - content_type = "text/plain" - } -`) +const testAccObjectStorageV1Container_update = ` +resource "openstack_objectstorage_container_v1" "container_1" { + name = "container_1" + metadata { + test = "true" + } + content_type = "text/plain" +} +`