Skip to content

Commit

Permalink
fix(ibm_is_image): 404 error fix on datasource (#5769)
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm authored Nov 21, 2024
1 parent f492e62 commit 2a51ec1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 1 addition & 4 deletions ibm/service/vpc/data_source_ibm_is_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ func imageGetById(d *schema.ResourceData, meta interface{}, identifier string) e

image, response, err := sess.GetImage(getImageOptions)
if err != nil {
if response.StatusCode == 404 {
return fmt.Errorf("[ERROR] No image found with id %s", identifier)
}
return fmt.Errorf("[ERROR] Error Fetching Images %s\n%s", err, response)
return fmt.Errorf("[ERROR] Error fetching image with id(%s) %s\n%s", identifier, err, response)
}

d.SetId(*image.ID)
Expand Down
22 changes: 22 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_image_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 @@ -34,6 +35,20 @@ func TestAccIBMISImageDataSource_basic(t *testing.T) {
},
})
}
func TestAccIBMISImageDataSource_id404(t *testing.T) {
imageId := "8843-5fr454ft-f6-4565-9555-5f889f5f3f7777"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISImageDataSource404Config(imageId),
ExpectError: regexp.MustCompile("Error fetching image with id"),
},
},
})
}
func TestAccIBMISImageDataSource_All(t *testing.T) {
resName := "data.ibm_is_image.test1"
imageName := fmt.Sprintf("tfimage-name-%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -171,6 +186,13 @@ func testAccCheckIBMISImageDataSourceConfig(imageName string) string {
}`, acc.Image_cos_url, imageName, acc.Image_operating_system)
}

func testAccCheckIBMISImageDataSource404Config(imageId string) string {
return fmt.Sprintf(`
data "ibm_is_image" "test1" {
identifier = "%s"
}`, imageId)
}

func testAccCheckIBMISImageDataSourceAllConfig(imageName string) string {
return fmt.Sprintf(`
data "ibm_is_images" "test1" {
Expand Down

0 comments on commit 2a51ec1

Please sign in to comment.