provider/openstack: Updating LBaaSV1 acceptance tests (#10979)

This commit is contained in:
Joe Topjian 2017-01-02 06:46:15 -07:00 committed by Paul Stack
parent af5baf7b13
commit 414b566d2e
4 changed files with 356 additions and 360 deletions

View File

@ -20,7 +20,7 @@ func TestAccLBV1Member_basic(t *testing.T) {
resource.TestStep{ resource.TestStep{
Config: testAccLBV1Member_basic, Config: testAccLBV1Member_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1MemberExists(t, "openstack_lb_member_v1.member_1", &member), testAccCheckLBV1MemberExists("openstack_lb_member_v1.member_1", &member),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -37,7 +37,7 @@ func testAccCheckLBV1MemberDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1MemberDestroy) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
@ -54,7 +54,7 @@ func testAccCheckLBV1MemberDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckLBV1MemberExists(t *testing.T, n string, member *members.Member) resource.TestCheckFunc { func testAccCheckLBV1MemberExists(n string, member *members.Member) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
@ -68,7 +68,7 @@ func testAccCheckLBV1MemberExists(t *testing.T, n string, member *members.Member
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1MemberExists) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
found, err := members.Get(networkingClient, rs.Primary.ID).Extract() found, err := members.Get(networkingClient, rs.Primary.ID).Extract()
@ -86,54 +86,56 @@ func testAccCheckLBV1MemberExists(t *testing.T, n string, member *members.Member
} }
} }
var testAccLBV1Member_basic = fmt.Sprintf(` const testAccLBV1Member_basic = `
resource "openstack_networking_network_v2" "network_1" { resource "openstack_networking_network_v2" "network_1" {
name = "network_1" name = "network_1"
admin_state_up = "true" admin_state_up = "true"
} }
resource "openstack_networking_subnet_v2" "subnet_1" { resource "openstack_networking_subnet_v2" "subnet_1" {
network_id = "${openstack_networking_network_v2.network_1.id}" cidr = "192.168.199.0/24"
cidr = "192.168.199.0/24" ip_version = 4
ip_version = 4 network_id = "${openstack_networking_network_v2.network_1.id}"
} }
resource "openstack_lb_pool_v1" "pool_1" { resource "openstack_lb_pool_v1" "pool_1" {
name = "tf_test_lb_pool" name = "pool_1"
protocol = "HTTP" protocol = "HTTP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" lb_method = "ROUND_ROBIN"
lb_method = "ROUND_ROBIN" subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
} }
resource "openstack_lb_member_v1" "member_1" { resource "openstack_lb_member_v1" "member_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}" address = "192.168.199.10"
address = "192.168.199.10" port = 80
port = 80 admin_state_up = true
admin_state_up = true pool_id = "${openstack_lb_pool_v1.pool_1.id}"
}`) }
`
var testAccLBV1Member_update = fmt.Sprintf(` const testAccLBV1Member_update = `
resource "openstack_networking_network_v2" "network_1" { resource "openstack_networking_network_v2" "network_1" {
name = "network_1" name = "network_1"
admin_state_up = "true" admin_state_up = "true"
} }
resource "openstack_networking_subnet_v2" "subnet_1" { resource "openstack_networking_subnet_v2" "subnet_1" {
network_id = "${openstack_networking_network_v2.network_1.id}" cidr = "192.168.199.0/24"
cidr = "192.168.199.0/24" ip_version = 4
ip_version = 4 network_id = "${openstack_networking_network_v2.network_1.id}"
} }
resource "openstack_lb_pool_v1" "pool_1" { resource "openstack_lb_pool_v1" "pool_1" {
name = "tf_test_lb_pool" name = "pool_1"
protocol = "HTTP" protocol = "HTTP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" lb_method = "ROUND_ROBIN"
lb_method = "ROUND_ROBIN" subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
} }
resource "openstack_lb_member_v1" "member_1" { resource "openstack_lb_member_v1" "member_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}" address = "192.168.199.10"
address = "192.168.199.10" port = 80
port = 80 admin_state_up = false
admin_state_up = false pool_id = "${openstack_lb_pool_v1.pool_1.id}"
}`) }
`

View File

@ -21,7 +21,7 @@ func TestAccLBV1Monitor_basic(t *testing.T) {
resource.TestStep{ resource.TestStep{
Config: testAccLBV1Monitor_basic, Config: testAccLBV1Monitor_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1MonitorExists(t, "openstack_lb_monitor_v1.monitor_1", &monitor), testAccCheckLBV1MonitorExists("openstack_lb_monitor_v1.monitor_1", &monitor),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -38,7 +38,7 @@ func testAccCheckLBV1MonitorDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1MonitorDestroy) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
@ -55,7 +55,7 @@ func testAccCheckLBV1MonitorDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckLBV1MonitorExists(t *testing.T, n string, monitor *monitors.Monitor) resource.TestCheckFunc { func testAccCheckLBV1MonitorExists(n string, monitor *monitors.Monitor) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
@ -69,7 +69,7 @@ func testAccCheckLBV1MonitorExists(t *testing.T, n string, monitor *monitors.Mon
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1MonitorExists) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
found, err := monitors.Get(networkingClient, rs.Primary.ID).Extract() found, err := monitors.Get(networkingClient, rs.Primary.ID).Extract()
@ -87,24 +87,24 @@ func testAccCheckLBV1MonitorExists(t *testing.T, n string, monitor *monitors.Mon
} }
} }
var testAccLBV1Monitor_basic = fmt.Sprintf(` const testAccLBV1Monitor_basic = `
resource "openstack_lb_monitor_v1" "monitor_1" { resource "openstack_lb_monitor_v1" "monitor_1" {
region = "%s" region = "%s"
type = "PING" type = "PING"
delay = 30 delay = 30
timeout = 5 timeout = 5
max_retries = 3 max_retries = 3
admin_state_up = "true" admin_state_up = "true"
}`, }
OS_REGION_NAME) `
var testAccLBV1Monitor_update = fmt.Sprintf(` const testAccLBV1Monitor_update = `
resource "openstack_lb_monitor_v1" "monitor_1" { resource "openstack_lb_monitor_v1" "monitor_1" {
region = "%s" region = "%s"
type = "PING" type = "PING"
delay = 20 delay = 20
timeout = 5 timeout = 5
max_retries = 3 max_retries = 3
admin_state_up = "true" admin_state_up = "true"
}`, }
OS_REGION_NAME) `

View File

@ -27,14 +27,14 @@ func TestAccLBV1Pool_basic(t *testing.T) {
resource.TestStep{ resource.TestStep{
Config: testAccLBV1Pool_basic, Config: testAccLBV1Pool_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1PoolExists(t, "openstack_lb_pool_v1.pool_1", &pool), testAccCheckLBV1PoolExists("openstack_lb_pool_v1.pool_1", &pool),
resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "lb_provider", "haproxy"), resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "lb_provider", "haproxy"),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccLBV1Pool_update, Config: testAccLBV1Pool_update,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "name", "tf_test_lb_pool_updated"), resource.TestCheckResourceAttr("openstack_lb_pool_v1.pool_1", "name", "pool_1"),
), ),
}, },
}, },
@ -63,9 +63,9 @@ func TestAccLBV1Pool_fullstack(t *testing.T) {
testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup), testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup),
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1),
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2),
testAccCheckLBV1PoolExists(t, "openstack_lb_pool_v1.pool_1", &pool), testAccCheckLBV1PoolExists("openstack_lb_pool_v1.pool_1", &pool),
testAccCheckLBV1MonitorExists(t, "openstack_lb_monitor_v1.monitor_1", &monitor), testAccCheckLBV1MonitorExists("openstack_lb_monitor_v1.monitor_1", &monitor),
testAccCheckLBV1VIPExists(t, "openstack_lb_vip_v1.vip_1", &vip), testAccCheckLBV1VIPExists("openstack_lb_vip_v1.vip_1", &vip),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -76,9 +76,9 @@ func TestAccLBV1Pool_fullstack(t *testing.T) {
testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup), testAccCheckComputeV2SecGroupExists("openstack_compute_secgroup_v2.secgroup_1", &secgroup),
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance1),
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2), testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_2", &instance2),
testAccCheckLBV1PoolExists(t, "openstack_lb_pool_v1.pool_1", &pool), testAccCheckLBV1PoolExists("openstack_lb_pool_v1.pool_1", &pool),
testAccCheckLBV1MonitorExists(t, "openstack_lb_monitor_v1.monitor_1", &monitor), testAccCheckLBV1MonitorExists("openstack_lb_monitor_v1.monitor_1", &monitor),
testAccCheckLBV1VIPExists(t, "openstack_lb_vip_v1.vip_1", &vip), testAccCheckLBV1VIPExists("openstack_lb_vip_v1.vip_1", &vip),
), ),
}, },
}, },
@ -89,7 +89,7 @@ func testAccCheckLBV1PoolDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1PoolDestroy) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
@ -106,7 +106,7 @@ func testAccCheckLBV1PoolDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckLBV1PoolExists(t *testing.T, n string, pool *pools.Pool) resource.TestCheckFunc { func testAccCheckLBV1PoolExists(n string, pool *pools.Pool) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
@ -120,7 +120,7 @@ func testAccCheckLBV1PoolExists(t *testing.T, n string, pool *pools.Pool) resour
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1PoolExists) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
found, err := pools.Get(networkingClient, rs.Primary.ID).Extract() found, err := pools.Get(networkingClient, rs.Primary.ID).Extract()
@ -138,222 +138,222 @@ func testAccCheckLBV1PoolExists(t *testing.T, n string, pool *pools.Pool) resour
} }
} }
var testAccLBV1Pool_basic = fmt.Sprintf(` const testAccLBV1Pool_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"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
lb_provider = "haproxy"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
`
const testAccLBV1Pool_update = `
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"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
`
const testAccLBV1Pool_fullstack_1 = `
name = "network_1"
admin_state_up = "true"
resource "openstack_networking_network_v2" "network_1" { resource "openstack_networking_network_v2" "network_1" {
region = "%s" }
name = "network_1"
admin_state_up = "true" 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_compute_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "Rules for secgroup_1"
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
} }
resource "openstack_networking_subnet_v2" "subnet_1" { rule {
region = "%s" from_port = 80
network_id = "${openstack_networking_network_v2.network_1.id}" to_port = 80
cidr = "192.168.199.0/24" ip_protocol = "tcp"
ip_version = 4 cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
network {
uuid = "${openstack_networking_network_v2.network_1.id}"
}
}
resource "openstack_compute_instance_v2" "instance_2" {
name = "instance_2"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
network {
uuid = "${openstack_networking_network_v2.network_1.id}"
}
}
resource "openstack_lb_monitor_v1" "monitor_1" {
type = "TCP"
delay = 30
timeout = 5
max_retries = 3
admin_state_up = "true"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "TCP"
lb_method = "ROUND_ROBIN"
monitor_ids = ["${openstack_lb_monitor_v1.monitor_1.id}"]
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_member_v1" "member_1" {
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_1.access_ip_v4}"
}
resource "openstack_lb_member_v1" "member_2" {
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_2.access_ip_v4}"
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1"
protocol = "TCP"
port = 80
admin_state_up = true
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
}
`
const testAccLBV1Pool_fullstack_2 = `
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"
ip_version = 4
network_id = "${openstack_networking_network_v2.network_1.id}"
}
resource "openstack_compute_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "Rules for secgroup_1"
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
} }
resource "openstack_lb_pool_v1" "pool_1" { rule {
region = "%s" from_port = 80
name = "tf_test_lb_pool" to_port = 80
protocol = "HTTP" ip_protocol = "tcp"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}" cidr = "0.0.0.0/0"
lb_method = "ROUND_ROBIN"
lb_provider = "haproxy"
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)
var testAccLBV1Pool_update = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
region = "%s"
name = "network_1"
admin_state_up = "true"
} }
}
resource "openstack_networking_subnet_v2" "subnet_1" { resource "openstack_compute_instance_v2" "instance_1" {
region = "%s" name = "instance_1"
network_id = "${openstack_networking_network_v2.network_1.id}" security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
cidr = "192.168.199.0/24"
ip_version = 4 network {
uuid = "${openstack_networking_network_v2.network_1.id}"
} }
}
resource "openstack_lb_pool_v1" "pool_1" { resource "openstack_compute_instance_v2" "instance_2" {
region = "%s" name = "instance_2"
name = "tf_test_lb_pool_updated" security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
protocol = "HTTP" user_data = "#cloud-config\ndisable_root: false"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
lb_method = "ROUND_ROBIN"
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)
var testAccLBV1Pool_fullstack_1 = fmt.Sprintf(` network {
resource "openstack_networking_network_v2" "network_1" { uuid = "${openstack_networking_network_v2.network_1.id}"
name = "network_1" }
admin_state_up = "true" }
}
resource "openstack_networking_subnet_v2" "subnet_1" { resource "openstack_lb_monitor_v1" "monitor_1" {
network_id = "${openstack_networking_network_v2.network_1.id}" type = "TCP"
cidr = "192.168.199.0/24" delay = 30
ip_version = 4 timeout = 5
} max_retries = 3
admin_state_up = "true"
}
resource "openstack_compute_secgroup_v2" "secgroup_1" { resource "openstack_lb_pool_v1" "pool_1" {
name = "secgroup_1" name = "pool_1"
description = "Rules for secgroup_1" protocol = "TCP"
lb_method = "ROUND_ROBIN"
monitor_ids = ["${openstack_lb_monitor_v1.monitor_1.id}"]
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
rule { resource "openstack_lb_member_v1" "member_1" {
from_port = -1 port = 80
to_port = -1 admin_state_up = true
ip_protocol = "icmp" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
cidr = "0.0.0.0/0" address = "${openstack_compute_instance_v2.instance_1.access_ip_v4}"
} }
rule { resource "openstack_lb_member_v1" "member_2" {
from_port = 80 port = 80
to_port = 80 admin_state_up = true
ip_protocol = "tcp" pool_id = "${openstack_lb_pool_v1.pool_1.id}"
cidr = "0.0.0.0/0" address = "${openstack_compute_instance_v2.instance_2.access_ip_v4}"
} }
}
resource "openstack_compute_instance_v2" "instance_1" { resource "openstack_lb_vip_v1" "vip_1" {
name = "instance_1" name = "vip_1"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"] protocol = "TCP"
network { port = 80
uuid = "${openstack_networking_network_v2.network_1.id}" admin_state_up = true
} subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
} pool_id = "${openstack_lb_pool_v1.pool_1.id}"
}
resource "openstack_compute_instance_v2" "instance_2" { `
name = "instance_2"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
network {
uuid = "${openstack_networking_network_v2.network_1.id}"
}
}
resource "openstack_lb_monitor_v1" "monitor_1" {
type = "TCP"
delay = 30
timeout = 5
max_retries = 3
admin_state_up = "true"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "TCP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
lb_method = "ROUND_ROBIN"
monitor_ids = ["${openstack_lb_monitor_v1.monitor_1.id}"]
}
resource "openstack_lb_member_v1" "member_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_1.access_ip_v4}"
port = 80
admin_state_up = true
}
resource "openstack_lb_member_v1" "member_2" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_2.access_ip_v4}"
port = 80
admin_state_up = true
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
protocol = "TCP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
admin_state_up = true
}`)
var testAccLBV1Pool_fullstack_2 = fmt.Sprintf(`
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_compute_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "Rules for secgroup_1"
rule {
from_port = -1
to_port = -1
ip_protocol = "icmp"
cidr = "0.0.0.0/0"
}
rule {
from_port = 80
to_port = 80
ip_protocol = "tcp"
cidr = "0.0.0.0/0"
}
}
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
network {
uuid = "${openstack_networking_network_v2.network_1.id}"
}
}
resource "openstack_compute_instance_v2" "instance_2" {
name = "instance_2"
security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"]
user_data = "#cloud-config\ndisable_root: false"
network {
uuid = "${openstack_networking_network_v2.network_1.id}"
}
}
resource "openstack_lb_monitor_v1" "monitor_1" {
type = "TCP"
delay = 30
timeout = 5
max_retries = 3
admin_state_up = "true"
}
resource "openstack_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "TCP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
lb_method = "ROUND_ROBIN"
monitor_ids = ["${openstack_lb_monitor_v1.monitor_1.id}"]
}
resource "openstack_lb_member_v1" "member_1" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_1.access_ip_v4}"
port = 80
admin_state_up = true
}
resource "openstack_lb_member_v1" "member_2" {
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
address = "${openstack_compute_instance_v2.instance_2.access_ip_v4}"
port = 80
admin_state_up = true
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
protocol = "TCP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
admin_state_up = true
}`)

View File

@ -21,13 +21,13 @@ func TestAccLBV1VIP_basic(t *testing.T) {
resource.TestStep{ resource.TestStep{
Config: testAccLBV1VIP_basic, Config: testAccLBV1VIP_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckLBV1VIPExists(t, "openstack_lb_vip_v1.vip_1", &vip), testAccCheckLBV1VIPExists("openstack_lb_vip_v1.vip_1", &vip),
), ),
}, },
resource.TestStep{ resource.TestStep{
Config: testAccLBV1VIP_update, Config: testAccLBV1VIP_update,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("openstack_lb_vip_v1.vip_1", "name", "tf_test_lb_vip_updated"), resource.TestCheckResourceAttr("openstack_lb_vip_v1.vip_1", "name", "vip_1_updated"),
), ),
}, },
}, },
@ -38,7 +38,7 @@ func testAccCheckLBV1VIPDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1VIPDestroy) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
@ -55,7 +55,7 @@ func testAccCheckLBV1VIPDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckLBV1VIPExists(t *testing.T, n string, vip *vips.VirtualIP) resource.TestCheckFunc { func testAccCheckLBV1VIPExists(n string, vip *vips.VirtualIP) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
@ -69,7 +69,7 @@ func testAccCheckLBV1VIPExists(t *testing.T, n string, vip *vips.VirtualIP) reso
config := testAccProvider.Meta().(*Config) config := testAccProvider.Meta().(*Config)
networkingClient, err := config.networkingV2Client(OS_REGION_NAME) networkingClient, err := config.networkingV2Client(OS_REGION_NAME)
if err != nil { if err != nil {
return fmt.Errorf("(testAccCheckLBV1VIPExists) Error creating OpenStack networking client: %s", err) return fmt.Errorf("Error creating OpenStack networking client: %s", err)
} }
found, err := vips.Get(networkingClient, rs.Primary.ID).Extract() found, err := vips.Get(networkingClient, rs.Primary.ID).Extract()
@ -87,74 +87,68 @@ func testAccCheckLBV1VIPExists(t *testing.T, n string, vip *vips.VirtualIP) reso
} }
} }
var testAccLBV1VIP_basic = fmt.Sprintf(` const testAccLBV1VIP_basic = `
resource "openstack_networking_network_v2" "network_1" { resource "openstack_networking_network_v2" "network_1" {
region = "%s" name = "network_1"
name = "network_1" admin_state_up = "true"
admin_state_up = "true" }
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_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1"
protocol = "HTTP"
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
persistence {
type = "SOURCE_IP"
} }
}
`
resource "openstack_networking_subnet_v2" "subnet_1" { const testAccLBV1VIP_update = `
region = "%s" resource "openstack_networking_network_v2" "network_1" {
network_id = "${openstack_networking_network_v2.network_1.id}" name = "network_1"
cidr = "192.168.199.0/24" admin_state_up = "true"
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_lb_pool_v1" "pool_1" {
name = "pool_1"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
resource "openstack_lb_vip_v1" "vip_1" {
name = "vip_1_updated"
protocol = "HTTP"
port = 80
admin_state_up = true
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
persistence {
type = "SOURCE_IP"
} }
}
resource "openstack_lb_pool_v1" "pool_1" { `
region = "%s"
name = "tf_test_lb_pool"
protocol = "HTTP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
lb_method = "ROUND_ROBIN"
}
resource "openstack_lb_vip_v1" "vip_1" {
region = "RegionOne"
name = "tf_test_lb_vip"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
protocol = "HTTP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
admin_state_up = true
persistence {
type = "SOURCE_IP"
}
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)
var testAccLBV1VIP_update = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
region = "%s"
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
region = "%s"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
ip_version = 4
}
resource "openstack_lb_pool_v1" "pool_1" {
region = "%s"
name = "tf_test_lb_pool"
protocol = "HTTP"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
lb_method = "ROUND_ROBIN"
}
resource "openstack_lb_vip_v1" "vip_1" {
region = "RegionOne"
name = "tf_test_lb_vip_updated"
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
protocol = "HTTP"
port = 80
pool_id = "${openstack_lb_pool_v1.pool_1.id}"
admin_state_up = true
persistence {
type = "SOURCE_IP"
}
}`,
OS_REGION_NAME, OS_REGION_NAME, OS_REGION_NAME)