Skip to content

Commit

Permalink
404 error fix on ibm_is_share datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm committed Nov 6, 2024
1 parent cf63419 commit ceeb756
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 2 additions & 9 deletions ibm/service/vpc/data_source_ibm_is_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,8 @@ func dataSourceIbmIsShareRead(context context.Context, d *schema.ResourceData, m

shareItem, response, err := vpcClient.GetShareWithContext(context, getShareOptions)
if err != nil {
if response != nil {
if response.StatusCode == 404 {
d.SetId("")
}
log.Printf("[DEBUG] GetShareWithContext failed %s\n%s", err, response)
return nil
}
log.Printf("[DEBUG] GetShareWithContext failed %s\n", err)
return diag.FromErr(err)
log.Printf("[DEBUG] GetShareWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("[ERROR] GetShareWithContext failed %s\n%s", err, response))
}
share = shareItem
} else if shareName != "" {
Expand Down
21 changes: 21 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vpc_test

import (
"fmt"
"regexp"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
Expand Down Expand Up @@ -39,6 +40,19 @@ func TestAccIbmIsShareDataSourceBasic(t *testing.T) {
},
})
}
func TestAccIbmIsShareDataSource404(t *testing.T) {
shareId := "8843-5fr454ft-f6-4565-9555-5f889f5f3f7777"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIbmIsShareDataSourceConfig404(shareId),
ExpectError: regexp.MustCompile("GetShareWithContext failed"),
},
},
})
}

func TestAccIbmIsShareDataSourceAllArgs(t *testing.T) {
shareName := fmt.Sprintf("tf-fs-name-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -93,6 +107,13 @@ func testAccCheckIbmIsShareDataSourceConfigBasic(name string) string {
}
`, name, acc.ShareProfileName)
}
func testAccCheckIbmIsShareDataSourceConfig404(id string) string {
return fmt.Sprintf(`
data "ibm_is_share" "is_share" {
share = %s
}
`, id)
}

func testAccCheckIbmIsShareDataSourceConfig(vpcName, shareName string, shareSize int, shareTargetName string) string {
return fmt.Sprintf(`
Expand Down

0 comments on commit ceeb756

Please sign in to comment.