Skip to content

Commit

Permalink
Update resource_ibm_is_vpn_gateway_connection_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm committed May 31, 2024
1 parent 2702764 commit feaa6c4
Showing 1 changed file with 254 additions and 0 deletions.
254 changes: 254 additions & 0 deletions ibm/service/vpc/resource_ibm_is_vpn_gateway_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,166 @@ func TestAccIBMISVPNGatewayConnection_multiple(t *testing.T) {
},
})
}
func TestAccIBMISVPNGatewayConnection_advanced(t *testing.T) {
var VPNGatewayConnection string
var VPNGatewayConnection2 string
vpcname1 := fmt.Sprintf("tfvpngc-vpc-%d", acctest.RandIntRange(100, 200))
subnetname1 := fmt.Sprintf("tfvpngc-subnet-%d", acctest.RandIntRange(100, 200))
vpnname1 := fmt.Sprintf("tfvpngc-vpn-%d", acctest.RandIntRange(100, 200))
name1 := fmt.Sprintf("tfvpngc-createname-%d", acctest.RandIntRange(100, 200))

vpcname2 := fmt.Sprintf("tfvpngc-vpc-%d", acctest.RandIntRange(100, 200))
subnetname2 := fmt.Sprintf("tfvpngc-subnet-%d", acctest.RandIntRange(100, 200))
vpnname2 := fmt.Sprintf("tfvpngc-vpn-%d", acctest.RandIntRange(100, 200))
name2 := fmt.Sprintf("tfvpngc-createname-%d", acctest.RandIntRange(100, 200))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISVPNGatewayConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVPNGatewayConnectionAdvanceConfig(vpcname1, subnetname1, vpnname1, name1, vpcname2, subnetname2, vpnname2, name2),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISVPNGatewayConnectionExists("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", VPNGatewayConnection),
testAccCheckIBMISVPNGatewayConnectionExists("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", VPNGatewayConnection2),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "name", name1),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "mode", "policy"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "action"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "admin_state_up"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "authentication_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "created_at"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "establish_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "href"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "id"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "interval"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "preshared_key"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "resource_type", "vpn_gateway_connection"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "status"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "name", name2),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "mode", "route"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "action"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "admin_state_up"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "authentication_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "created_at"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "establish_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "href"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "id"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "interval"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "preshared_key"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "resource_type", "vpn_gateway_connection"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "status"),
),
},
},
})
}
func TestAccIBMISVPNGatewayConnection_breakingchange(t *testing.T) {
var VPNGatewayConnection string
var VPNGatewayConnection2 string
vpcname1 := fmt.Sprintf("tfvpngc-vpc-%d", acctest.RandIntRange(100, 200))
subnetname1 := fmt.Sprintf("tfvpngc-subnet-%d", acctest.RandIntRange(100, 200))
vpnname1 := fmt.Sprintf("tfvpngc-vpn-%d", acctest.RandIntRange(100, 200))
name1 := fmt.Sprintf("tfvpngc-createname-%d", acctest.RandIntRange(100, 200))

vpcname2 := fmt.Sprintf("tfvpngc-vpc-%d", acctest.RandIntRange(100, 200))
subnetname2 := fmt.Sprintf("tfvpngc-subnet-%d", acctest.RandIntRange(100, 200))
vpnname2 := fmt.Sprintf("tfvpngc-vpn-%d", acctest.RandIntRange(100, 200))
name2 := fmt.Sprintf("tfvpngc-createname-%d", acctest.RandIntRange(100, 200))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISVPNGatewayConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISVPNGatewayConnectionBreakingChangeConfig(vpcname1, subnetname1, vpnname1, name1, vpcname2, subnetname2, vpnname2, name2),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISVPNGatewayConnectionExists("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", VPNGatewayConnection),
testAccCheckIBMISVPNGatewayConnectionExists("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", VPNGatewayConnection2),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "name", name1),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "mode", "policy"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "action"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "admin_state_up"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "authentication_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "created_at"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "establish_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "href"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "id"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "interval"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "preshared_key"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "resource_type", "vpn_gateway_connection"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection1", "status"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "name", name2),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "mode", "route"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "action"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "admin_state_up"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "authentication_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "created_at"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "establish_mode"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "href"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "id"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "interval"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "preshared_key"),
resource.TestCheckResourceAttr(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "resource_type", "vpn_gateway_connection"),
resource.TestCheckResourceAttrSet(
"ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection2", "status"),
),
},
},
})
}

func testAccCheckIBMISVPNGatewayConnectionDestroy(s *terraform.State) error {

Expand Down Expand Up @@ -552,6 +712,100 @@ func testAccCheckIBMISVPNGatewayConnectionMultipleConfig(vpc1, subnet1, vpnname1
}
`, vpc1, subnet1, acc.ISZoneName, vpnname1, name1, vpc2, subnet2, acc.ISZoneName, vpnname2, name2)

}
func testAccCheckIBMISVPNGatewayConnectionBreakingChangeConfig(vpc1, subnet1, vpnname1, name1, vpc2, subnet2, vpnname2, name2 string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc1" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet1" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc1.id
zone = "%s"
total_ipv4_address_count = 64
}
resource "ibm_is_vpn_gateway" "testacc_VPNGateway1" {
name = "%s"
subnet = ibm_is_subnet.testacc_subnet1.id
mode = "policy"
}
resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection1" {
name = "%s"
vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway1.id
peer_cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
peer_address = cidrhost(ibm_is_subnet.testacc_subnet1.ipv4_cidr_block, 14)
local_cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
preshared_key = "VPNDemoPassword"
}
resource "ibm_is_vpc" "testacc_vpc2" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet2" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc2.id
zone = "%s"
total_ipv4_address_count = 64
}
resource "ibm_is_vpn_gateway" "testacc_VPNGateway2" {
name = "%s"
subnet = ibm_is_subnet.testacc_subnet2.id
mode = "route"
}
resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection2" {
name = "%s"
vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway2.id
peer_address = cidrhost(ibm_is_subnet.testacc_subnet2.ipv4_cidr_block, 15)
preshared_key = "VPNDemoPassword"
}
`, vpc1, subnet1, acc.ISZoneName, vpnname1, name1, vpc2, subnet2, acc.ISZoneName, vpnname2, name2)

}
func testAccCheckIBMISVPNGatewayConnectionAdvanceConfig(vpc1, subnet1, vpnname1, name1, vpc2, subnet2, vpnname2, name2 string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc1" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet1" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc1.id
zone = "%s"
total_ipv4_address_count = 64
}
resource "ibm_is_vpn_gateway" "testacc_VPNGateway1" {
name = "%s"
subnet = ibm_is_subnet.testacc_subnet1.id
mode = "policy"
}
resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection1" {
name = "%s"
vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway1.id
peer_cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
peer_address = cidrhost(ibm_is_subnet.testacc_subnet1.ipv4_cidr_block, 14)
local_cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
preshared_key = "VPNDemoPassword"
}
resource "ibm_is_vpc" "testacc_vpc2" {
name = "%s"
}
resource "ibm_is_subnet" "testacc_subnet2" {
name = "%s"
vpc = ibm_is_vpc.testacc_vpc2.id
zone = "%s"
total_ipv4_address_count = 64
}
resource "ibm_is_vpn_gateway" "testacc_VPNGateway2" {
name = "%s"
subnet = ibm_is_subnet.testacc_subnet2.id
mode = "route"
}
resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection2" {
name = "%s"
vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway2.id
peer_address = cidrhost(ibm_is_subnet.testacc_subnet2.ipv4_cidr_block, 15)
preshared_key = "VPNDemoPassword"
}
`, vpc1, subnet1, acc.ISZoneName, vpnname1, name1, vpc2, subnet2, acc.ISZoneName, vpnname2, name2)

}

func testAccCheckIBMISVPNGatewayConnectionRouteUpdate(vpc1, subnet1, vpnname1, name1, vpc2, subnet2, vpnname2, name2 string) string {
Expand Down

0 comments on commit feaa6c4

Please sign in to comment.