Skip to content

Commit

Permalink
404 error fix on ibm_is_virtual_network_interface_floating_ip datasource
Browse files Browse the repository at this point in the history
ujjwal-ibm authored and hkantare committed Nov 6, 2024
1 parent c5551eb commit cf63419
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ var (
SourceShareCRN string
ShareEncryptionKey string
VNIId string
FloatingIpID string
VolumeProfileName string
VSIUnattachedBootVolumeID string
VSIDataVolumeID string
@@ -991,6 +992,11 @@ func init() {
VNIId = "c93dc4c6-e85a-4da2-9ea6-f24576256122"
fmt.Println("[INFO] Set the environment variable IS_VIRTUAL_NETWORK_INTERFACE for testing ibm_is_virtual_network_interface else it is set to default value 'c93dc4c6-e85a-4da2-9ea6-f24576256122'")
}
FloatingIpID = os.Getenv("IS_FLOATING_IP")
if FloatingIpID == "" {
FloatingIpID = "r006-9fc3948f-1b01-406c-baa5-e86b185e559f"
fmt.Println("[INFO] Set the environment variable IS_FLOATING_IP for testing ibm_is_virtual_network_interface else it is set to default value 'r006-9fc3948f-1b01-406c-baa5-e86b185e559f'")
}

VSIUnattachedBootVolumeID = os.Getenv("IS_VSI_UNATTACHED_BOOT_VOLUME_ID")
if VSIUnattachedBootVolumeID == "" {
Original file line number Diff line number Diff line change
@@ -82,10 +82,6 @@ func dataSourceIBMIsVirtualNetworkInterfaceFloatingIPRead(context context.Contex

floatingIP, response, err := sess.GetNetworkInterfaceFloatingIPWithContext(context, getNetworkInterfaceFloatingIPOptions)
if err != nil {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
log.Printf("[DEBUG] GetVirtualNetworkInterfaceFloatingIPWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetVirtualNetworkInterfaceFloatingIPWithContext failed %s\n%s", err, response))
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ package vpc_test

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -37,6 +38,22 @@ func TestAccIBMIsVirtualNetworkInterfaceFloatingIPDataSourceBasic(t *testing.T)
},
})
}
func TestAccIBMIsVirtualNetworkInterfaceFloatingIPDataSource404(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigVNI404(),
ExpectError: regexp.MustCompile("GetVirtualNetworkInterfaceFloatingIPWithContext failed"),
},
{
Config: testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigFIP404(),
ExpectError: regexp.MustCompile("GetVirtualNetworkInterfaceFloatingIPWithContext failed"),
},
},
})
}

func testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigBasic(vpcname, subnetname, vniname, floatingipname string) string {
return testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPConfigBasic(vpcname, subnetname, vniname, floatingipname) + fmt.Sprintf(`
@@ -46,3 +63,19 @@ func testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigBasic(vpc
}
`)
}
func testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigVNI404() string {
return fmt.Sprintf(`
data "ibm_is_virtual_network_interface_floating_ip" "is_floating_ip" {
virtual_network_interface = "%s"
floating_ip = "%s"
}
`, acc.VNIId, acc.VNIId)
}
func testAccCheckIBMIsVirtualNetworkInterfaceFloatingIPDataSourceConfigFIP404() string {
return fmt.Sprintf(`
data "ibm_is_virtual_network_interface_floating_ip" "is_floating_ip" {
virtual_network_interface = "%s"
floating_ip = "%s"
}
`, acc.FloatingIpID, acc.FloatingIpID)
}

0 comments on commit cf63419

Please sign in to comment.