provider/openstack: Updating FWaaS and LBaaS v2 Acceptance Tests (#10959)
* provider/openstack: Updating FWaaS acceptance tests * provider/openstack: Updating LBaaS v2 acceptance tests
This commit is contained in:
parent
64051f9214
commit
b55cf9d601
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccOpenStackFWFirewallV1_importBasic(t *testing.T) {
|
func TestAccOpenStackFWFirewallV1_importBasic(t *testing.T) {
|
||||||
resourceName := "openstack_fw_firewall_v1.accept_test"
|
resourceName := "openstack_fw_firewall_v1.fw_1"
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -15,7 +15,7 @@ func TestAccOpenStackFWFirewallV1_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWFirewallV1Destroy,
|
CheckDestroy: testAccCheckFWFirewallV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallConfig,
|
Config: testAccFWFirewallV1_basic_1,
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccOpenStackFWPolicyV1_importBasic(t *testing.T) {
|
func TestAccOpenStackFWPolicyV1_importBasic(t *testing.T) {
|
||||||
resourceName := "openstack_fw_policy_v1.accept_test"
|
resourceName := "openstack_fw_policy_v1.policy_1"
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -15,7 +15,7 @@ func TestAccOpenStackFWPolicyV1_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallPolicyConfigAddRules,
|
Config: testAccFWPolicyV1_addRules,
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccOpenStackFWRuleV1_importBasic(t *testing.T) {
|
func TestAccOpenStackFWRuleV1_importBasic(t *testing.T) {
|
||||||
resourceName := "openstack_fw_rule_v1.accept_test"
|
resourceName := "openstack_fw_rule_v1.rule_1"
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -15,7 +15,7 @@ func TestAccOpenStackFWRuleV1_importBasic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallRuleConfig,
|
Config: testAccFWRuleV1_basic_2,
|
||||||
},
|
},
|
||||||
|
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccFWFirewallV1_basic(t *testing.T) {
|
func TestAccFWFirewallV1_basic(t *testing.T) {
|
||||||
|
|
||||||
var policyID *string
|
var policyID *string
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
@ -21,15 +20,16 @@ func TestAccFWFirewallV1_basic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWFirewallV1Destroy,
|
CheckDestroy: testAccCheckFWFirewallV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallConfig,
|
Config: testAccFWFirewallV1_basic_1,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckFWFirewallV1Exists("openstack_fw_firewall_v1.accept_test", "", "", policyID),
|
testAccCheckFWFirewallV1Exists("openstack_fw_firewall_v1.fw_1", "", "", policyID),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallConfigUpdated,
|
Config: testAccFWFirewallV1_basic_2,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckFWFirewallV1Exists("openstack_fw_firewall_v1.accept_test", "accept_test", "terraform acceptance test", policyID),
|
testAccCheckFWFirewallV1Exists(
|
||||||
|
"openstack_fw_firewall_v1.fw_1", "fw_1", "terraform acceptance test", policyID),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -37,11 +37,10 @@ func TestAccFWFirewallV1_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWFirewallV1Destroy(s *terraform.State) error {
|
func testAccCheckFWFirewallV1Destroy(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("(testAccCheckOpenstackFirewallDestroy) 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 {
|
||||||
if rs.Type != "openstack_firewall" {
|
if rs.Type != "openstack_firewall" {
|
||||||
|
@ -60,9 +59,7 @@ func testAccCheckFWFirewallV1Destroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string, policyID *string) resource.TestCheckFunc {
|
func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string, policyID *string) 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 {
|
||||||
return fmt.Errorf("Not found: %s", n)
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
@ -75,7 +72,7 @@ func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string,
|
||||||
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("(testAccCheckFirewallExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Exists) Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var found *firewalls.Firewall
|
var found *firewalls.Firewall
|
||||||
|
@ -93,17 +90,21 @@ func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string,
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if found.Name != expectedName {
|
switch {
|
||||||
return fmt.Errorf("Expected Name to be <%s> but found <%s>", expectedName, found.Name)
|
case found.Name != expectedName:
|
||||||
|
err = fmt.Errorf("Expected Name to be <%s> but found <%s>", expectedName, found.Name)
|
||||||
|
case found.Description != expectedDescription:
|
||||||
|
err = fmt.Errorf("Expected Description to be <%s> but found <%s>",
|
||||||
|
expectedDescription, found.Description)
|
||||||
|
case found.PolicyID == "":
|
||||||
|
err = fmt.Errorf("Policy should not be empty")
|
||||||
|
case policyID != nil && found.PolicyID == *policyID:
|
||||||
|
err = fmt.Errorf("Policy had not been correctly updated. Went from <%s> to <%s>",
|
||||||
|
expectedName, found.Name)
|
||||||
}
|
}
|
||||||
if found.Description != expectedDescription {
|
|
||||||
return fmt.Errorf("Expected Description to be <%s> but found <%s>", expectedDescription, found.Description)
|
if err != nil {
|
||||||
}
|
return err
|
||||||
if found.PolicyID == "" {
|
|
||||||
return fmt.Errorf("Policy should not be empty")
|
|
||||||
}
|
|
||||||
if policyID != nil && found.PolicyID == *policyID {
|
|
||||||
return fmt.Errorf("Policy had not been correctly updated. Went from <%s> to <%s>", expectedName, found.Name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
policyID = &found.PolicyID
|
policyID = &found.PolicyID
|
||||||
|
@ -112,25 +113,25 @@ func testAccCheckFWFirewallV1Exists(n, expectedName, expectedDescription string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testFirewallConfig = `
|
const testAccFWFirewallV1_basic_1 = `
|
||||||
resource "openstack_fw_firewall_v1" "accept_test" {
|
resource "openstack_fw_firewall_v1" "fw_1" {
|
||||||
policy_id = "${openstack_fw_policy_v1.accept_test_policy_1.id}"
|
policy_id = "${openstack_fw_policy_v1.policy_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_fw_policy_v1" "accept_test_policy_1" {
|
resource "openstack_fw_policy_v1" "policy_1" {
|
||||||
name = "policy-1"
|
name = "policy_1"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallConfigUpdated = `
|
const testAccFWFirewallV1_basic_2 = `
|
||||||
resource "openstack_fw_firewall_v1" "accept_test" {
|
resource "openstack_fw_firewall_v1" "fw_1" {
|
||||||
name = "accept_test"
|
name = "fw_1"
|
||||||
description = "terraform acceptance test"
|
description = "terraform acceptance test"
|
||||||
policy_id = "${openstack_fw_policy_v1.accept_test_policy_2.id}"
|
policy_id = "${openstack_fw_policy_v1.policy_2.id}"
|
||||||
admin_state_up = true
|
admin_state_up = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_fw_policy_v1" "accept_test_policy_2" {
|
resource "openstack_fw_policy_v1" "policy_2" {
|
||||||
name = "policy-2"
|
name = "policy_2"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
@ -18,11 +18,10 @@ func TestAccFWPolicyV1_basic(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallPolicyConfig,
|
Config: testAccFWPolicyV1_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckFWPolicyV1Exists(
|
testAccCheckFWPolicyV1Exists(
|
||||||
"openstack_fw_policy_v1.accept_test",
|
"openstack_fw_policy_v1.policy_1", "", "", 0),
|
||||||
"", "", 0),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -36,11 +35,10 @@ func TestAccFWPolicyV1_addRules(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallPolicyConfigAddRules,
|
Config: testAccFWPolicyV1_addRules,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckFWPolicyV1Exists(
|
testAccCheckFWPolicyV1Exists(
|
||||||
"openstack_fw_policy_v1.accept_test",
|
"openstack_fw_policy_v1.policy_1", "policy_1", "terraform acceptance test", 2),
|
||||||
"accept_test", "terraform acceptance test", 2),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -54,11 +52,10 @@ func TestAccFWPolicyV1_deleteRules(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
CheckDestroy: testAccCheckFWPolicyV1Destroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testFirewallPolicyUpdateDeleteRule,
|
Config: testAccFWPolicyV1_deleteRules,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckFWPolicyV1Exists(
|
testAccCheckFWPolicyV1Exists(
|
||||||
"openstack_fw_policy_v1.accept_test",
|
"openstack_fw_policy_v1.policy_1", "policy_1", "terraform acceptance test", 1),
|
||||||
"accept_test", "terraform acceptance test", 1),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -66,11 +63,10 @@ func TestAccFWPolicyV1_deleteRules(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWPolicyV1Destroy(s *terraform.State) error {
|
func testAccCheckFWPolicyV1Destroy(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("(testAccCheckOpenstackFirewallPolicyDestroy) 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 {
|
||||||
if rs.Type != "openstack_fw_policy_v1" {
|
if rs.Type != "openstack_fw_policy_v1" {
|
||||||
|
@ -88,9 +84,7 @@ func testAccCheckFWPolicyV1Destroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) resource.TestCheckFunc {
|
func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) 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 {
|
||||||
return fmt.Errorf("Not found: %s", n)
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
@ -103,7 +97,7 @@ func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) re
|
||||||
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("(testAccCheckFirewallPolicyExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var found *policies.Policy
|
var found *policies.Policy
|
||||||
|
@ -121,59 +115,59 @@ func testAccCheckFWPolicyV1Exists(n, name, description string, ruleCount int) re
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if name != found.Name {
|
switch {
|
||||||
return fmt.Errorf("Expected name <%s>, but found <%s>", name, found.Name)
|
case name != found.Name:
|
||||||
|
err = fmt.Errorf("Expected name <%s>, but found <%s>", name, found.Name)
|
||||||
|
case description != found.Description:
|
||||||
|
err = fmt.Errorf("Expected description <%s>, but found <%s>", description, found.Description)
|
||||||
|
case ruleCount != len(found.Rules):
|
||||||
|
err = fmt.Errorf("Expected rule count <%d>, but found <%d>", ruleCount, len(found.Rules))
|
||||||
}
|
}
|
||||||
|
|
||||||
if description != found.Description {
|
if err != nil {
|
||||||
return fmt.Errorf("Expected description <%s>, but found <%s>", description, found.Description)
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
if ruleCount != len(found.Rules) {
|
|
||||||
return fmt.Errorf("Expected rule count <%d>, but found <%d>", ruleCount, len(found.Rules))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testFirewallPolicyConfig = `
|
const testAccFWPolicyV1_basic = `
|
||||||
resource "openstack_fw_policy_v1" "accept_test" {
|
resource "openstack_fw_policy_v1" "policy_1" {
|
||||||
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallPolicyConfigAddRules = `
|
const testAccFWPolicyV1_addRules = `
|
||||||
resource "openstack_fw_policy_v1" "accept_test" {
|
resource "openstack_fw_policy_v1" "policy_1" {
|
||||||
name = "accept_test"
|
name = "policy_1"
|
||||||
description = "terraform acceptance test"
|
description = "terraform acceptance test"
|
||||||
rules = [
|
rules = [
|
||||||
"${openstack_fw_rule_v1.accept_test_udp_deny.id}",
|
"${openstack_fw_rule_v1.udp_deny.id}",
|
||||||
"${openstack_fw_rule_v1.accept_test_tcp_allow.id}"
|
"${openstack_fw_rule_v1.tcp_allow.id}"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_fw_rule_v1" "accept_test_tcp_allow" {
|
resource "openstack_fw_rule_v1" "tcp_allow" {
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
action = "allow"
|
action = "allow"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_fw_rule_v1" "accept_test_udp_deny" {
|
resource "openstack_fw_rule_v1" "udp_deny" {
|
||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
action = "deny"
|
action = "deny"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallPolicyUpdateDeleteRule = `
|
const testAccFWPolicyV1_deleteRules = `
|
||||||
resource "openstack_fw_policy_v1" "accept_test" {
|
resource "openstack_fw_policy_v1" "policy_1" {
|
||||||
name = "accept_test"
|
name = "policy_1"
|
||||||
description = "terraform acceptance test"
|
description = "terraform acceptance test"
|
||||||
rules = [
|
rules = [
|
||||||
"${openstack_fw_rule_v1.accept_test_udp_deny.id}"
|
"${openstack_fw_rule_v1.udp_deny.id}"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_fw_rule_v1" "accept_test_udp_deny" {
|
resource "openstack_fw_rule_v1" "udp_deny" {
|
||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
action = "deny"
|
action = "deny"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,31 +13,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccFWRuleV1_basic(t *testing.T) {
|
func TestAccFWRuleV1_basic(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
rule1 := &rules.Rule{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
Name: "rule_1",
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testFirewallRuleMinimalConfig,
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckFWRuleV1Exists(
|
|
||||||
"openstack_fw_rule_v1.accept_test_minimal",
|
|
||||||
&rules.Rule{
|
|
||||||
Protocol: "udp",
|
Protocol: "udp",
|
||||||
Action: "deny",
|
Action: "deny",
|
||||||
IPVersion: 4,
|
IPVersion: 4,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}),
|
}
|
||||||
),
|
|
||||||
},
|
rule2 := &rules.Rule{
|
||||||
resource.TestStep{
|
Name: "rule_1",
|
||||||
Config: testFirewallRuleConfig,
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckFWRuleV1Exists(
|
|
||||||
"openstack_fw_rule_v1.accept_test",
|
|
||||||
&rules.Rule{
|
|
||||||
Name: "accept_test",
|
|
||||||
Protocol: "udp",
|
Protocol: "udp",
|
||||||
Action: "deny",
|
Action: "deny",
|
||||||
Description: "Terraform accept test",
|
Description: "Terraform accept test",
|
||||||
|
@ -47,16 +32,10 @@ func TestAccFWRuleV1_basic(t *testing.T) {
|
||||||
SourcePort: "444",
|
SourcePort: "444",
|
||||||
DestinationPort: "555",
|
DestinationPort: "555",
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}),
|
}
|
||||||
),
|
|
||||||
},
|
rule3 := &rules.Rule{
|
||||||
resource.TestStep{
|
Name: "rule_1",
|
||||||
Config: testFirewallRuleUpdateAllFieldsConfig,
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckFWRuleV1Exists(
|
|
||||||
"openstack_fw_rule_v1.accept_test",
|
|
||||||
&rules.Rule{
|
|
||||||
Name: "accept_test_updated_2",
|
|
||||||
Protocol: "tcp",
|
Protocol: "tcp",
|
||||||
Action: "allow",
|
Action: "allow",
|
||||||
Description: "Terraform accept test updated",
|
Description: "Terraform accept test updated",
|
||||||
|
@ -66,7 +45,29 @@ func TestAccFWRuleV1_basic(t *testing.T) {
|
||||||
SourcePort: "666",
|
SourcePort: "666",
|
||||||
DestinationPort: "777",
|
DestinationPort: "777",
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
}),
|
}
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccFWRuleV1_basic_1,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckFWRuleV1Exists("openstack_fw_rule_v1.rule_1", rule1),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccFWRuleV1_basic_2,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckFWRuleV1Exists("openstack_fw_rule_v1.rule_1", rule2),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccFWRuleV1_basic_3,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckFWRuleV1Exists("openstack_fw_rule_v1.rule_1", rule3),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -74,17 +75,7 @@ func TestAccFWRuleV1_basic(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccFWRuleV1_anyProtocol(t *testing.T) {
|
func TestAccFWRuleV1_anyProtocol(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
rule := &rules.Rule{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
|
||||||
Providers: testAccProviders,
|
|
||||||
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
|
||||||
Steps: []resource.TestStep{
|
|
||||||
resource.TestStep{
|
|
||||||
Config: testFirewallRuleAnyProtocol,
|
|
||||||
Check: resource.ComposeTestCheckFunc(
|
|
||||||
testAccCheckFWRuleV1Exists(
|
|
||||||
"openstack_fw_rule_v1.rule_1",
|
|
||||||
&rules.Rule{
|
|
||||||
Name: "rule_1",
|
Name: "rule_1",
|
||||||
Description: "Allow any protocol",
|
Description: "Allow any protocol",
|
||||||
Protocol: "",
|
Protocol: "",
|
||||||
|
@ -92,7 +83,17 @@ func TestAccFWRuleV1_anyProtocol(t *testing.T) {
|
||||||
IPVersion: 4,
|
IPVersion: 4,
|
||||||
SourceIPAddress: "192.168.199.0/24",
|
SourceIPAddress: "192.168.199.0/24",
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}),
|
}
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckFWRuleV1Destroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccFWRuleV1_anyProtocol,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckFWRuleV1Exists("openstack_fw_rule_v1.rule_1", rule),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -100,12 +101,12 @@ func TestAccFWRuleV1_anyProtocol(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWRuleV1Destroy(s *terraform.State) error {
|
func testAccCheckFWRuleV1Destroy(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("(testAccCheckOpenstackFirewallRuleDestroy) 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 {
|
||||||
if rs.Type != "openstack_firewall_rule" {
|
if rs.Type != "openstack_firewall_rule" {
|
||||||
continue
|
continue
|
||||||
|
@ -122,9 +123,7 @@ func testAccCheckFWRuleV1Destroy(s *terraform.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) resource.TestCheckFunc {
|
func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) 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 {
|
||||||
return fmt.Errorf("Not found: %s", n)
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
@ -137,7 +136,7 @@ func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) resource.TestChe
|
||||||
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("(testAccCheckFirewallRuleExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var found *rules.Rule
|
var found *rules.Rule
|
||||||
|
@ -168,16 +167,17 @@ func testAccCheckFWRuleV1Exists(n string, expected *rules.Rule) resource.TestChe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const testFirewallRuleMinimalConfig = `
|
const testAccFWRuleV1_basic_1 = `
|
||||||
resource "openstack_fw_rule_v1" "accept_test_minimal" {
|
resource "openstack_fw_rule_v1" "rule_1" {
|
||||||
|
name = "rule_1"
|
||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
action = "deny"
|
action = "deny"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallRuleConfig = `
|
const testAccFWRuleV1_basic_2 = `
|
||||||
resource "openstack_fw_rule_v1" "accept_test" {
|
resource "openstack_fw_rule_v1" "rule_1" {
|
||||||
name = "accept_test"
|
name = "rule_1"
|
||||||
description = "Terraform accept test"
|
description = "Terraform accept test"
|
||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
action = "deny"
|
action = "deny"
|
||||||
|
@ -190,9 +190,9 @@ resource "openstack_fw_rule_v1" "accept_test" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallRuleUpdateAllFieldsConfig = `
|
const testAccFWRuleV1_basic_3 = `
|
||||||
resource "openstack_fw_rule_v1" "accept_test" {
|
resource "openstack_fw_rule_v1" "rule_1" {
|
||||||
name = "accept_test_updated_2"
|
name = "rule_1"
|
||||||
description = "Terraform accept test updated"
|
description = "Terraform accept test updated"
|
||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
action = "allow"
|
action = "allow"
|
||||||
|
@ -205,7 +205,7 @@ resource "openstack_fw_rule_v1" "accept_test" {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallRuleAnyProtocol = `
|
const testAccFWRuleV1_anyProtocol = `
|
||||||
resource "openstack_fw_rule_v1" "rule_1" {
|
resource "openstack_fw_rule_v1" "rule_1" {
|
||||||
name = "rule_1"
|
name = "rule_1"
|
||||||
description = "Allow any protocol"
|
description = "Allow any protocol"
|
||||||
|
|
|
@ -20,14 +20,16 @@ func TestAccLBV2Listener_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2ListenerConfig_basic,
|
Config: TestAccLBV2ListenerConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLBV2ListenerExists(t, "openstack_lb_listener_v2.listener_1", &listener),
|
testAccCheckLBV2ListenerExists("openstack_lb_listener_v2.listener_1", &listener),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2ListenerConfig_update,
|
Config: TestAccLBV2ListenerConfig_update,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr("openstack_lb_listener_v2.listener_1", "name", "tf_test_listener_updated"),
|
resource.TestCheckResourceAttr(
|
||||||
resource.TestCheckResourceAttr("openstack_lb_listener_v2.listener_1", "connection_limit", "100"),
|
"openstack_lb_listener_v2.listener_1", "name", "listener_1_updated"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"openstack_lb_listener_v2.listener_1", "connection_limit", "100"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -38,7 +40,7 @@ func testAccCheckLBV2ListenerDestroy(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("(testAccCheckLBV2ListenerDestroy) 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 +57,7 @@ func testAccCheckLBV2ListenerDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckLBV2ListenerExists(t *testing.T, n string, listener *listeners.Listener) resource.TestCheckFunc {
|
func testAccCheckLBV2ListenerExists(n string, listener *listeners.Listener) 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 +71,7 @@ func testAccCheckLBV2ListenerExists(t *testing.T, n string, listener *listeners.
|
||||||
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("(testAccCheckLBV2ListenerExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
found, err := listeners.Get(networkingClient, rs.Primary.ID).Extract()
|
found, err := listeners.Get(networkingClient, rs.Primary.ID).Extract()
|
||||||
|
@ -87,56 +89,56 @@ func testAccCheckLBV2ListenerExists(t *testing.T, n string, listener *listeners.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAccLBV2ListenerConfig_basic = fmt.Sprintf(`
|
const TestAccLBV2ListenerConfig_basic = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
`)
|
`
|
||||||
|
|
||||||
var TestAccLBV2ListenerConfig_update = fmt.Sprintf(`
|
const TestAccLBV2ListenerConfig_update = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1_updated"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
|
||||||
name = "tf_test_listener_updated"
|
|
||||||
connection_limit = 100
|
connection_limit = 100
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
}
|
}
|
||||||
`)
|
`
|
||||||
|
|
|
@ -21,14 +21,17 @@ func TestAccLBV2LoadBalancer_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2LoadBalancerConfig_basic,
|
Config: TestAccLBV2LoadBalancerConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLBV2LoadBalancerExists(t, "openstack_lb_loadbalancer_v2.loadbalancer_1", &lb),
|
testAccCheckLBV2LoadBalancerExists("openstack_lb_loadbalancer_v2.loadbalancer_1", &lb),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2LoadBalancerConfig_update,
|
Config: TestAccLBV2LoadBalancerConfig_update,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr("openstack_lb_loadbalancer_v2.loadbalancer_1", "name", "tf_test_loadbalancer_v2_updated"),
|
resource.TestCheckResourceAttr(
|
||||||
resource.TestMatchResourceAttr("openstack_lb_loadbalancer_v2.loadbalancer_1", "vip_port_id", regexp.MustCompile("^[a-f0-9-]+")),
|
"openstack_lb_loadbalancer_v2.loadbalancer_1", "name", "loadbalancer_1_updated"),
|
||||||
|
resource.TestMatchResourceAttr(
|
||||||
|
"openstack_lb_loadbalancer_v2.loadbalancer_1", "vip_port_id",
|
||||||
|
regexp.MustCompile("^[a-f0-9-]+")),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -39,7 +42,7 @@ func testAccCheckLBV2LoadBalancerDestroy(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("(testAccCheckLBV2LoadBalancerDestroy) 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 {
|
||||||
|
@ -56,7 +59,7 @@ func testAccCheckLBV2LoadBalancerDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckLBV2LoadBalancerExists(t *testing.T, n string, lb *loadbalancers.LoadBalancer) resource.TestCheckFunc {
|
func testAccCheckLBV2LoadBalancerExists(n string, lb *loadbalancers.LoadBalancer) 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 {
|
||||||
|
@ -70,7 +73,7 @@ func testAccCheckLBV2LoadBalancerExists(t *testing.T, n string, lb *loadbalancer
|
||||||
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("(testAccCheckLBV2LoadBalancerExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
found, err := loadbalancers.Get(networkingClient, rs.Primary.ID).Extract()
|
found, err := loadbalancers.Get(networkingClient, rs.Primary.ID).Extract()
|
||||||
|
@ -88,40 +91,41 @@ func testAccCheckLBV2LoadBalancerExists(t *testing.T, n string, lb *loadbalancer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAccLBV2LoadBalancerConfig_basic = fmt.Sprintf(`
|
const TestAccLBV2LoadBalancerConfig_basic = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
}
|
||||||
}`)
|
`
|
||||||
|
|
||||||
var TestAccLBV2LoadBalancerConfig_update = fmt.Sprintf(`
|
const TestAccLBV2LoadBalancerConfig_update = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
name = "loadbalancer_1_updated"
|
||||||
name = "tf_test_loadbalancer_v2_updated"
|
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
}
|
}
|
||||||
`)
|
`
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestAccLBV2Member_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2MemberConfig_basic,
|
Config: TestAccLBV2MemberConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLBV2MemberExists(t, "openstack_lb_member_v2.member_1", &member),
|
testAccCheckLBV2MemberExists("openstack_lb_member_v2.member_1", &member),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
|
@ -37,7 +37,7 @@ func testAccCheckLBV2MemberDestroy(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("(testAccCheckLBV2MemberDestroy) 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 {
|
||||||
|
@ -45,7 +45,8 @@ func testAccCheckLBV2MemberDestroy(s *terraform.State) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := pools.GetMember(networkingClient, rs.Primary.Attributes["pool_id"], rs.Primary.ID).Extract()
|
poolId := rs.Primary.Attributes["pool_id"]
|
||||||
|
_, err := pools.GetMember(networkingClient, poolId, rs.Primary.ID).Extract()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("Member still exists: %s", rs.Primary.ID)
|
return fmt.Errorf("Member still exists: %s", rs.Primary.ID)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,7 @@ func testAccCheckLBV2MemberDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckLBV2MemberExists(t *testing.T, n string, member *pools.Member) resource.TestCheckFunc {
|
func testAccCheckLBV2MemberExists(n string, member *pools.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,10 +69,11 @@ func testAccCheckLBV2MemberExists(t *testing.T, n string, member *pools.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("(testAccCheckLBV2MemberExists) Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
found, err := pools.GetMember(networkingClient, rs.Primary.Attributes["pool_id"], rs.Primary.ID).Extract()
|
poolId := rs.Primary.Attributes["pool_id"]
|
||||||
|
found, err := pools.GetMember(networkingClient, poolId, rs.Primary.ID).Extract()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -86,82 +88,84 @@ func testAccCheckLBV2MemberExists(t *testing.T, n string, member *pools.Member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAccLBV2MemberConfig_basic = fmt.Sprintf(`
|
const TestAccLBV2MemberConfig_basic = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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" {
|
||||||
|
name = "subnet_1"
|
||||||
network_id = "${openstack_networking_network_v2.network_1.id}"
|
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
|
||||||
name = "tf_test_subnet"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "ROUND_ROBIN"
|
lb_method = "ROUND_ROBIN"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
name = "tf_test_pool"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_member_v2" "member_1" {
|
resource "openstack_lb_member_v2" "member_1" {
|
||||||
address = "192.168.199.10"
|
address = "192.168.199.10"
|
||||||
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
|
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
||||||
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
}`)
|
}
|
||||||
|
`
|
||||||
|
|
||||||
var TestAccLBV2MemberConfig_update = fmt.Sprintf(`
|
const TestAccLBV2MemberConfig_update = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "ROUND_ROBIN"
|
lb_method = "ROUND_ROBIN"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
name = "tf_test_pool"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_member_v2" "member_1" {
|
resource "openstack_lb_member_v2" "member_1" {
|
||||||
address = "192.168.199.10"
|
address = "192.168.199.10"
|
||||||
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
|
||||||
weight = 10
|
weight = 10
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
}`)
|
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
||||||
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -26,7 +26,8 @@ func TestAccLBV2Monitor_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2MonitorConfig_update,
|
Config: TestAccLBV2MonitorConfig_update,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr("openstack_lb_monitor_v2.monitor_1", "name", "tf_test_monitor_updated"),
|
resource.TestCheckResourceAttr(
|
||||||
|
"openstack_lb_monitor_v2.monitor_1", "name", "monitor_1_updated"),
|
||||||
resource.TestCheckResourceAttr("openstack_lb_monitor_v2.monitor_1", "delay", "30"),
|
resource.TestCheckResourceAttr("openstack_lb_monitor_v2.monitor_1", "delay", "30"),
|
||||||
resource.TestCheckResourceAttr("openstack_lb_monitor_v2.monitor_1", "timeout", "15"),
|
resource.TestCheckResourceAttr("openstack_lb_monitor_v2.monitor_1", "timeout", "15"),
|
||||||
),
|
),
|
||||||
|
@ -39,7 +40,7 @@ func testAccCheckLBV2MonitorDestroy(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("(testAccCheckLBV2MonitorDestroy) 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 {
|
||||||
|
@ -70,7 +71,7 @@ func testAccCheckLBV2MonitorExists(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("(testAccCheckLBV2MonitorExists) 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()
|
||||||
|
@ -88,85 +89,87 @@ func testAccCheckLBV2MonitorExists(t *testing.T, n string, monitor *monitors.Mon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAccLBV2MonitorConfig_basic = fmt.Sprintf(`
|
const TestAccLBV2MonitorConfig_basic = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "ROUND_ROBIN"
|
lb_method = "ROUND_ROBIN"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
name = "tf_test_pool"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_monitor_v2" "monitor_1" {
|
resource "openstack_lb_monitor_v2" "monitor_1" {
|
||||||
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
name = "monitor_1"
|
||||||
type = "PING"
|
type = "PING"
|
||||||
delay = 20
|
delay = 20
|
||||||
timeout = 10
|
timeout = 10
|
||||||
max_retries = 5
|
max_retries = 5
|
||||||
name = "tf_test_monitor"
|
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
||||||
}`)
|
}
|
||||||
|
`
|
||||||
|
|
||||||
var TestAccLBV2MonitorConfig_update = fmt.Sprintf(`
|
const TestAccLBV2MonitorConfig_update = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "ROUND_ROBIN"
|
lb_method = "ROUND_ROBIN"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
name = "tf_test_pool"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_monitor_v2" "monitor_1" {
|
resource "openstack_lb_monitor_v2" "monitor_1" {
|
||||||
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
name = "monitor_1_updated"
|
||||||
type = "PING"
|
type = "PING"
|
||||||
delay = 30
|
delay = 30
|
||||||
timeout = 15
|
timeout = 15
|
||||||
max_retries = 10
|
max_retries = 10
|
||||||
name = "tf_test_monitor_updated"
|
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
}`)
|
pool_id = "${openstack_lb_pool_v2.pool_1.id}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -20,13 +20,13 @@ func TestAccLBV2Pool_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2PoolConfig_basic,
|
Config: TestAccLBV2PoolConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckLBV2PoolExists(t, "openstack_lb_pool_v2.pool_1", &pool),
|
testAccCheckLBV2PoolExists("openstack_lb_pool_v2.pool_1", &pool),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: TestAccLBV2PoolConfig_update,
|
Config: TestAccLBV2PoolConfig_update,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr("openstack_lb_pool_v2.pool_1", "name", "tf_test_pool_update"),
|
resource.TestCheckResourceAttr("openstack_lb_pool_v2.pool_1", "name", "pool_1_updated"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -37,7 +37,7 @@ func testAccCheckLBV2PoolDestroy(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("(testAccCheckLBV2PoolDestroy) 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 testAccCheckLBV2PoolDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckLBV2PoolExists(t *testing.T, n string, pool *pools.Pool) resource.TestCheckFunc {
|
func testAccCheckLBV2PoolExists(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 {
|
||||||
|
@ -68,7 +68,7 @@ func testAccCheckLBV2PoolExists(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("(testAccCheckLBV2PoolExists) 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()
|
||||||
|
@ -86,67 +86,69 @@ func testAccCheckLBV2PoolExists(t *testing.T, n string, pool *pools.Pool) resour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TestAccLBV2PoolConfig_basic = fmt.Sprintf(`
|
const TestAccLBV2PoolConfig_basic = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "ROUND_ROBIN"
|
lb_method = "ROUND_ROBIN"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
name = "tf_test_pool"
|
}
|
||||||
}`)
|
`
|
||||||
|
|
||||||
var TestAccLBV2PoolConfig_update = fmt.Sprintf(`
|
const TestAccLBV2PoolConfig_update = `
|
||||||
resource "openstack_networking_network_v2" "network_1" {
|
resource "openstack_networking_network_v2" "network_1" {
|
||||||
name = "tf_test_network"
|
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}"
|
name = "subnet_1"
|
||||||
cidr = "192.168.199.0/24"
|
cidr = "192.168.199.0/24"
|
||||||
ip_version = 4
|
ip_version = 4
|
||||||
name = "tf_test_subnet"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
resource "openstack_lb_loadbalancer_v2" "loadbalancer_1" {
|
||||||
|
name = "loadbalancer_1"
|
||||||
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
vip_subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
name = "tf_test_loadbalancer_v2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_listener_v2" "listener_1" {
|
resource "openstack_lb_listener_v2" "listener_1" {
|
||||||
|
name = "listener_1"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
protocol_port = 8080
|
protocol_port = 8080
|
||||||
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
loadbalancer_id = "${openstack_lb_loadbalancer_v2.loadbalancer_1.id}"
|
||||||
name = "tf_test_listener"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "openstack_lb_pool_v2" "pool_1" {
|
resource "openstack_lb_pool_v2" "pool_1" {
|
||||||
|
name = "pool_1_updated"
|
||||||
protocol = "HTTP"
|
protocol = "HTTP"
|
||||||
lb_method = "LEAST_CONNECTIONS"
|
lb_method = "LEAST_CONNECTIONS"
|
||||||
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
|
||||||
name = "tf_test_pool_update"
|
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
}`)
|
listener_id = "${openstack_lb_listener_v2.listener_1.id}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue