@@ -569,101 +569,140 @@ func TestAccIBMISVirtualEndpointGateway_ServiceEndpoints(t *testing.T) {
569569func TestAccIBMISVirtualEndpointGateway_DnsResolutionBindingMode (t * testing.T ) {
570570 var endpointGateway string
571571 vpcName := fmt .Sprintf ("tf-vpe-vpc-%d" , acctest .RandIntRange (10 , 100 ))
572- enableHub := false
573- gatewayName := fmt .Sprintf ("tf-vpe-gateway-%d" , acctest .RandIntRange (10 , 100 ))
574- resourceName := "ibm_is_virtual_endpoint_gateway.vpe_gateway"
572+ gatewayName1 := fmt .Sprintf ("tf-vpe-gateway-1-%d" , acctest .RandIntRange (10 , 100 ))
573+ gatewayName2 := fmt .Sprintf ("tf-vpe-gateway-2-%d" , acctest .RandIntRange (10 , 100 ))
574+ gatewayName3 := fmt .Sprintf ("tf-vpe-gateway-3-%d" , acctest .RandIntRange (10 , 100 ))
575+ gatewayName4 := fmt .Sprintf ("tf-vpe-gateway-4-%d" , acctest .RandIntRange (10 , 100 ))
576+ gatewayName5 := fmt .Sprintf ("tf-vpe-gateway-5-%d" , acctest .RandIntRange (10 , 100 ))
575577
576578 resource .Test (t , resource.TestCase {
577579 PreCheck : func () { acc .TestAccPreCheck (t ) },
578580 Providers : acc .TestAccProviders ,
579581 Steps : []resource.TestStep {
582+ // Step 1: Create VPC only
580583 {
581- Config : testAccCheckIBMISVirtualEndpointGatewayConfigDnsResolutionBindingMode (vpcName , gatewayName , enableHub , "primary" ),
584+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
582585 Check : resource .ComposeTestCheckFunc (
583- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
584- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
585- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode" , "primary" ),
586- // Verify deprecated field behavior when dns_resolution_binding_mode is "primary"
587- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding" , "true" ),
586+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
588587 ),
589588 },
589+ // Step 2: Add VPE Gateway 1 - Deprecated field with allow_dns_resolution_binding = true
590590 {
591- Config : testAccCheckIBMISVirtualEndpointGatewayConfigDnsResolutionBindingMode (vpcName , gatewayName , enableHub , "disabled " ),
591+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName1 , "vpe_gateway_1" , "deprecated" , "true" , " " ),
592592 Check : resource .ComposeTestCheckFunc (
593- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
594- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
595- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode " , "disabled " ),
596- // Verify deprecated field behavior when dns_resolution_binding_mode is "disabled"
597- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding " , "false " ),
593+ testAccCheckisVirtualEndpointGatewayExists ("ibm_is_virtual_endpoint_gateway.vpe_gateway_1" , & endpointGateway ),
594+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_1" , "name" , gatewayName1 ),
595+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_1" , "allow_dns_resolution_binding " , "true " ),
596+ // Verify new field gets computed correctly (true maps to "primary")
597+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_1" , "dns_resolution_binding_mode " , "primary " ),
598598 ),
599599 },
600+ // Step 3: Remove VPE Gateway 1 - VPC only
600601 {
601- Config : testAccCheckIBMISVirtualEndpointGatewayConfigDnsResolutionBindingMode (vpcName , gatewayName , enableHub , "per_resource_binding" ),
602+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
602603 Check : resource .ComposeTestCheckFunc (
603- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
604- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
605- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode" , "per_resource_binding" ),
606- // Verify deprecated field behavior when dns_resolution_binding_mode is "per_resource_binding"
607- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding" , "true" ),
604+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
608605 ),
609606 },
610- // Test backward compatibility with deprecated field
607+ // Step 4: Add VPE Gateway 2 - Deprecated field with allow_dns_resolution_binding = false
611608 {
612- Config : testAccCheckIBMISVirtualEndpointGatewayConfigBackwardCompatibility (vpcName , gatewayName , enableHub , true ),
609+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName2 , "vpe_gateway_2" , "deprecated" , "false" , "" ),
613610 Check : resource .ComposeTestCheckFunc (
614- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
615- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
616- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding" , "true " ),
617- // When allow_dns_resolution_binding is true, dns_resolution_binding_mode should be "primary"
618- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode" , "primary " ),
611+ testAccCheckisVirtualEndpointGatewayExists ("ibm_is_virtual_endpoint_gateway.vpe_gateway_2" , & endpointGateway ),
612+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_2" , "name" , gatewayName2 ),
613+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_2" , "allow_dns_resolution_binding" , "false " ),
614+ // Verify new field gets computed correctly (false maps to "disabled")
615+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_2" , "dns_resolution_binding_mode" , "disabled " ),
619616 ),
620617 },
618+ // Step 5: Remove VPE Gateway 2 - VPC only
621619 {
622- Config : testAccCheckIBMISVirtualEndpointGatewayConfigBackwardCompatibility (vpcName , gatewayName , enableHub , false ),
620+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
623621 Check : resource .ComposeTestCheckFunc (
624- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
625- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
626- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding" , "false" ),
627- // When allow_dns_resolution_binding is false, dns_resolution_binding_mode should be "disabled"
628- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode" , "disabled" ),
622+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
623+ ),
624+ },
625+ // Step 6: Add VPE Gateway 3 - New field with dns_resolution_binding_mode = "primary"
626+ {
627+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName3 , "vpe_gateway_3" , "new" , "" , "primary" ),
628+ Check : resource .ComposeTestCheckFunc (
629+ testAccCheckisVirtualEndpointGatewayExists ("ibm_is_virtual_endpoint_gateway.vpe_gateway_3" , & endpointGateway ),
630+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_3" , "name" , gatewayName3 ),
631+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_3" , "dns_resolution_binding_mode" , "primary" ),
632+ // Verify deprecated field shows correct computed value
633+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_3" , "allow_dns_resolution_binding" , "true" ),
634+ ),
635+ },
636+ // Step 7: Remove VPE Gateway 3 - VPC only
637+ {
638+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
639+ Check : resource .ComposeTestCheckFunc (
640+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
641+ ),
642+ },
643+ // Step 8: Add VPE Gateway 4 - New field with dns_resolution_binding_mode = "disabled"
644+ {
645+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName4 , "vpe_gateway_4" , "new" , "" , "disabled" ),
646+ Check : resource .ComposeTestCheckFunc (
647+ testAccCheckisVirtualEndpointGatewayExists ("ibm_is_virtual_endpoint_gateway.vpe_gateway_4" , & endpointGateway ),
648+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_4" , "name" , gatewayName4 ),
649+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_4" , "dns_resolution_binding_mode" , "disabled" ),
650+ // Verify deprecated field shows correct computed value
651+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_4" , "allow_dns_resolution_binding" , "false" ),
652+ ),
653+ },
654+ // Step 9: Remove VPE Gateway 4 - VPC only
655+ {
656+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
657+ Check : resource .ComposeTestCheckFunc (
658+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
659+ ),
660+ },
661+ // Step 10: Add VPE Gateway 5 - New field with dns_resolution_binding_mode = "per_resource_binding"
662+ {
663+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName5 , "vpe_gateway_5" , "new" , "" , "per_resource_binding" ),
664+ Check : resource .ComposeTestCheckFunc (
665+ testAccCheckisVirtualEndpointGatewayExists ("ibm_is_virtual_endpoint_gateway.vpe_gateway_5" , & endpointGateway ),
666+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_5" , "name" , gatewayName5 ),
667+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_5" , "dns_resolution_binding_mode" , "per_resource_binding" ),
668+ // Verify deprecated field shows correct computed value
669+ resource .TestCheckResourceAttr ("ibm_is_virtual_endpoint_gateway.vpe_gateway_5" , "allow_dns_resolution_binding" , "true" ),
670+ ),
671+ },
672+ // Step 11: Final cleanup - Remove VPE Gateway 5, VPC remains (will be cleaned up by test framework)
673+ {
674+ Config : testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName ),
675+ Check : resource .ComposeTestCheckFunc (
676+ resource .TestCheckResourceAttr ("ibm_is_vpc.testacc_vpc" , "name" , vpcName ),
629677 ),
630678 },
631679 },
632680 })
633681}
634682
635- func testAccCheckIBMISVirtualEndpointGatewayConfigDnsResolutionBindingMode (vpcName , gatewayName string , enableHub bool , dnsResolutionBindingMode string ) string {
683+ // Helper function for VPC only config
684+ func testAccCheckIBMISVirtualEndpointGatewayComprehensiveVPCOnly (vpcName string ) string {
636685 return fmt .Sprintf (`
637686 resource "ibm_is_vpc" "testacc_vpc" {
638687 name = "%s"
639- dns {
640- enable_hub = %t
641- }
642688 }
643-
644- resource "ibm_is_virtual_endpoint_gateway" "vpe_gateway" {
645- name = "%s"
646- vpc = ibm_is_vpc.testacc_vpc.id
647-
648- target {
649- name = "ibm-ntp-server"
650- resource_type = "provider_infrastructure_service"
651- }
652-
653- dns_resolution_binding_mode = "%s"
654- }` , vpcName , enableHub , gatewayName , dnsResolutionBindingMode )
689+ ` , vpcName )
655690}
656691
657- func testAccCheckIBMISVirtualEndpointGatewayConfigBackwardCompatibility (vpcName , gatewayName string , enableHub , allowDnsResolutionBinding bool ) string {
658- return fmt .Sprintf (`
692+ // Helper function for VPC + VPE Gateway config
693+ func testAccCheckIBMISVirtualEndpointGatewayComprehensiveConfig (vpcName , gatewayName , resourceName , fieldType , deprecatedValue , newValue string ) string {
694+ baseConfig := fmt .Sprintf (`
659695 resource "ibm_is_vpc" "testacc_vpc" {
660696 name = "%s"
661- dns {
662- enable_hub = %t
663- }
664697 }
665-
666- resource "ibm_is_virtual_endpoint_gateway" "vpe_gateway" {
698+ ` , vpcName )
699+
700+ var gatewayConfig string
701+
702+ if fieldType == "deprecated" {
703+ // Using deprecated field
704+ gatewayConfig = fmt .Sprintf (`
705+ resource "ibm_is_virtual_endpoint_gateway" "%s" {
667706 name = "%s"
668707 vpc = ibm_is_vpc.testacc_vpc.id
669708
@@ -672,49 +711,23 @@ func testAccCheckIBMISVirtualEndpointGatewayConfigBackwardCompatibility(vpcName,
672711 resource_type = "provider_infrastructure_service"
673712 }
674713
675- allow_dns_resolution_binding = %t
676- }` , vpcName , enableHub , gatewayName , allowDnsResolutionBinding )
677- }
678-
679- // Test for the specific configuration
680- func TestAccIBMISVirtualEndpointGateway_BasicConfig (t * testing.T ) {
681- var endpointGateway string
682- vpcName := fmt .Sprintf ("tf-vpe-vpc-%d" , acctest .RandIntRange (10 , 100 ))
683- gatewayName := fmt .Sprintf ("tf-vpe-ntp-%d" , acctest .RandIntRange (10 , 100 ))
684- resourceName := "ibm_is_virtual_endpoint_gateway.vpe_ntp"
685-
686- resource .Test (t , resource.TestCase {
687- PreCheck : func () { acc .TestAccPreCheck (t ) },
688- Providers : acc .TestAccProviders ,
689- Steps : []resource.TestStep {
690- {
691- Config : testAccCheckIBMISVirtualEndpointGatewayBasicConfig (vpcName , gatewayName ),
692- Check : resource .ComposeTestCheckFunc (
693- testAccCheckisVirtualEndpointGatewayExists (resourceName , & endpointGateway ),
694- resource .TestCheckResourceAttr (resourceName , "name" , gatewayName ),
695- resource .TestCheckResourceAttr (resourceName , "dns_resolution_binding_mode" , "disabled" ),
696- resource .TestCheckResourceAttr (resourceName , "allow_dns_resolution_binding" , "false" ),
697- ),
698- },
699- },
700- })
701- }
702-
703- func testAccCheckIBMISVirtualEndpointGatewayBasicConfig (vpcName , gatewayName string ) string {
704- return fmt .Sprintf (`
705- resource "ibm_is_vpc" "testacc_vpc" {
706- name = "%s"
707- }
708-
709- resource "ibm_is_virtual_endpoint_gateway" "vpe_ntp" {
714+ allow_dns_resolution_binding = %s
715+ }` , resourceName , gatewayName , deprecatedValue )
716+ } else {
717+ // Using new field
718+ gatewayConfig = fmt .Sprintf (`
719+ resource "ibm_is_virtual_endpoint_gateway" "%s" {
710720 name = "%s"
711721 vpc = ibm_is_vpc.testacc_vpc.id
712722
713723 target {
714- resource_type = "provider_infrastructure_service"
715724 name = "ibm-ntp-server"
725+ resource_type = "provider_infrastructure_service"
716726 }
717727
718- dns_resolution_binding_mode = "disabled"
719- }` , vpcName , gatewayName )
728+ dns_resolution_binding_mode = "%s"
729+ }` , resourceName , gatewayName , newValue )
730+ }
731+
732+ return baseConfig + gatewayConfig
720733}
0 commit comments