@@ -1539,3 +1539,110 @@ func testAccCheckIBMISVPNGatewayConnectionNullPatchConfig(vpc, subnet, vpnname,
15391539 ` , vpc , subnet , acc .ISZoneName , acc .ISCIDR , vpnname , ikepolicyname , ipsecpolicyname , name , noNullPass , noNullPass )
15401540
15411541}
1542+
1543+ func TestAccIBMISVPNGatewayConnection_CIDRUpdates (t * testing.T ) {
1544+ var VPNGatewayConnection string
1545+ vpcname := fmt .Sprintf ("tfvpngc-vpc-%d" , acctest .RandIntRange (100 , 200 ))
1546+ subnetname1 := fmt .Sprintf ("tfvpngc-subnet-%d" , acctest .RandIntRange (100 , 200 ))
1547+ subnetname2 := fmt .Sprintf ("tfvpngc-subnet-%d" , acctest .RandIntRange (100 , 200 ))
1548+ vpnname := fmt .Sprintf ("tfvpngc-vpn-%d" , acctest .RandIntRange (100 , 200 ))
1549+ name := fmt .Sprintf ("tfvpngc-conn-%d" , acctest .RandIntRange (100 , 200 ))
1550+
1551+ resource .Test (t , resource.TestCase {
1552+ PreCheck : func () { acc .TestAccPreCheck (t ) },
1553+ Providers : acc .TestAccProviders ,
1554+ CheckDestroy : testAccCheckIBMISVPNGatewayConnectionDestroy ,
1555+ Steps : []resource.TestStep {
1556+ // Initial configuration
1557+ {
1558+ Config : testAccCheckIBMISVPNGatewayConnectionCIDRConfig (vpcname , subnetname1 , subnetname2 , vpnname , name , false ),
1559+ Check : resource .ComposeTestCheckFunc (
1560+ testAccCheckIBMISVPNGatewayConnectionExists ("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , VPNGatewayConnection ),
1561+ resource .TestCheckResourceAttr (
1562+ "ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , "name" , name ),
1563+ resource .TestCheckResourceAttr (
1564+ "ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , "peer.0.cidrs.#" , "1" ),
1565+ resource .TestCheckResourceAttr (
1566+ "ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , "local.0.cidrs.#" , "1" ),
1567+ ),
1568+ },
1569+ // Add additional CIDRs
1570+ {
1571+ Config : testAccCheckIBMISVPNGatewayConnectionCIDRConfig (vpcname , subnetname1 , subnetname2 , vpnname , name , true ),
1572+ Check : resource .ComposeTestCheckFunc (
1573+ testAccCheckIBMISVPNGatewayConnectionExists ("ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , VPNGatewayConnection ),
1574+ resource .TestCheckResourceAttr (
1575+ "ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , "peer.0.cidrs.#" , "2" ),
1576+ resource .TestCheckResourceAttr (
1577+ "ibm_is_vpn_gateway_connection.testacc_VPNGatewayConnection" , "local.0.cidrs.#" , "2" ),
1578+ ),
1579+ },
1580+ },
1581+ })
1582+ }
1583+
1584+ func testAccCheckIBMISVPNGatewayConnectionCIDRConfig (vpc , subnet1 , subnet2 , vpnname , name string , additionalCIDRs bool ) string {
1585+ base := fmt .Sprintf (`
1586+ resource "ibm_is_vpc" "testacc_vpc" {
1587+ name = "%s"
1588+ }
1589+
1590+ resource "ibm_is_subnet" "testacc_subnet1" {
1591+ name = "%s"
1592+ vpc = ibm_is_vpc.testacc_vpc.id
1593+ zone = "%s"
1594+ total_ipv4_address_count = 64
1595+ }
1596+
1597+ resource "ibm_is_subnet" "testacc_subnet2" {
1598+ name = "%s"
1599+ vpc = ibm_is_vpc.testacc_vpc.id
1600+ zone = "%s"
1601+ total_ipv4_address_count = 64
1602+ }
1603+
1604+ resource "ibm_is_vpn_gateway" "testacc_VPNGateway" {
1605+ name = "%s"
1606+ subnet = ibm_is_subnet.testacc_subnet1.id
1607+ mode = "policy"
1608+ }
1609+ ` , vpc , subnet1 , acc .ISZoneName , subnet2 , acc .ISZoneName , vpnname )
1610+
1611+ if ! additionalCIDRs {
1612+ return base + fmt .Sprintf (`
1613+ resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection" {
1614+ name = "%s"
1615+ vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway.id
1616+ peer {
1617+ cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
1618+ address = cidrhost(ibm_is_subnet.testacc_subnet1.ipv4_cidr_block, 14)
1619+ }
1620+ local {
1621+ cidrs = [ibm_is_subnet.testacc_subnet1.ipv4_cidr_block]
1622+ }
1623+ preshared_key = "VPNDemoPassword"
1624+ }
1625+ ` , name )
1626+ }
1627+
1628+ return base + fmt .Sprintf (`
1629+ resource "ibm_is_vpn_gateway_connection" "testacc_VPNGatewayConnection" {
1630+ name = "%s"
1631+ vpn_gateway = ibm_is_vpn_gateway.testacc_VPNGateway.id
1632+ peer {
1633+ cidrs = [
1634+ ibm_is_subnet.testacc_subnet1.ipv4_cidr_block,
1635+ ibm_is_subnet.testacc_subnet2.ipv4_cidr_block
1636+ ]
1637+ address = cidrhost(ibm_is_subnet.testacc_subnet1.ipv4_cidr_block, 14)
1638+ }
1639+ local {
1640+ cidrs = [
1641+ ibm_is_subnet.testacc_subnet1.ipv4_cidr_block,
1642+ ibm_is_subnet.testacc_subnet2.ipv4_cidr_block
1643+ ]
1644+ }
1645+ preshared_key = "VPNDemoPassword"
1646+ }
1647+ ` , name )
1648+ }
0 commit comments