Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ibm_is_share): 404 error fix on datasource #5770

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 2 additions & 9 deletions ibm/service/vpc/data_source_ibm_is_source_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,8 @@ func dataSourceIbmIsSourceShareRead(context context.Context, d *schema.ResourceD

share, response, err := vpcClient.GetShareSourceWithContext(context, getShareSourceOptions)
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(fmt.Errorf("[DEBUG] GetShareWithContext failed %s\n", err))
log.Printf("[DEBUG] GetShareSourceWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("[ERROR] GetShareSourceWithContext failed %s\n%s", err, response))
}

d.SetId(*share.ID)
Expand Down
23 changes: 23 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_source_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 @@ -54,3 +55,25 @@ func testAccCheckIbmIsSourceShareDataSourceConfigBasic(vpcname, vpcname1, shareN
}
`)
}
func TestAccIbmIsSourceShareDataSource404(t *testing.T) {
srId := "8843-5fr454ft-f6-4565-9555-5f889f5f3f7777"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIbmIsSourceShareDataSourceConfig404(srId),
ExpectError: regexp.MustCompile("GetShareSourceWithContext failed"),
},
},
})
}

func testAccCheckIbmIsSourceShareDataSourceConfig404(srId string) string {
return fmt.Sprintf(`

data "ibm_is_source_share" "test" {
share_replica = "%s"
}
`, srId)
}
Loading