Skip to content

Commit 6a4fbd2

Browse files
committed
feat(marketplace_image): add image_type filter
1 parent 78093ed commit 6a4fbd2

File tree

5 files changed

+379
-48
lines changed

5 files changed

+379
-48
lines changed

docs/data-sources/marketplace_image.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ to find the right `label`.
2323
- `instance_type` - (Optional, default `DEV1-S`) The instance type the image is compatible with.
2424
You find all the available types on the [pricing page](https://www.scaleway.com/en/pricing/).
2525

26+
- `image_type` - (Optional, default `instance_local`) The local image type, `instance_local` or `instance_sbs`.
27+
2628
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the image exists.
2729

2830
## Attributes Reference

internal/services/marketplace/image_data_source.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ func DataSourceImage() *schema.Resource {
2626
Default: "DEV1-S",
2727
Description: "The instance commercial type of the desired image",
2828
},
29+
"image_type": {
30+
Type: schema.TypeString,
31+
Optional: true,
32+
Default: "instance_local", // Keep the old default as default to avoid a breaking change.
33+
Description: "The type of the desired image, instance_local or instance_sbs",
34+
},
2935
"zone": zonal.Schema(),
3036
},
3137
}
@@ -41,7 +47,7 @@ func DataSourceMarketplaceImageRead(ctx context.Context, d *schema.ResourceData,
4147
ImageLabel: d.Get("label").(string),
4248
CommercialType: d.Get("instance_type").(string),
4349
Zone: zone,
44-
Type: marketplace.LocalImageTypeInstanceLocal,
50+
Type: marketplace.LocalImageType(d.Get("image_type").(string)),
4551
}, scw.WithContext(ctx))
4652
if err != nil {
4753
return diag.FromErr(err)
@@ -52,6 +58,7 @@ func DataSourceMarketplaceImageRead(ctx context.Context, d *schema.ResourceData,
5258
_ = d.Set("zone", zone)
5359
_ = d.Set("label", d.Get("label"))
5460
_ = d.Set("instance_type", d.Get("type"))
61+
_ = d.Set("image_type", image.Type)
5562

5663
return nil
5764
}

internal/services/marketplace/image_data_source_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ func TestAccDataSourceMarketplaceImage_Basic(t *testing.T) {
2424
Check: resource.ComposeTestCheckFunc(
2525
instancechecks.DoesImageExists(tt, "data.scaleway_marketplace_image.test1"),
2626
resource.TestCheckResourceAttr("data.scaleway_marketplace_image.test1", "label", "ubuntu_focal"),
27+
resource.TestCheckResourceAttr("data.scaleway_marketplace_image.test1", "image_type", "instance_local"),
28+
),
29+
},
30+
},
31+
})
32+
}
33+
34+
func TestAccDataSourceMarketplaceImage_SBS(t *testing.T) {
35+
tt := acctest.NewTestTools(t)
36+
defer tt.Cleanup()
37+
resource.ParallelTest(t, resource.TestCase{
38+
PreCheck: func() { acctest.PreCheck(t) },
39+
ProviderFactories: tt.ProviderFactories,
40+
Steps: []resource.TestStep{
41+
{
42+
Config: `
43+
data "scaleway_marketplace_image" "test1" {
44+
label = "ubuntu_focal"
45+
image_type = "instance_sbs"
46+
}
47+
`,
48+
Check: resource.ComposeTestCheckFunc(
49+
instancechecks.DoesImageExists(tt, "data.scaleway_marketplace_image.test1"),
50+
resource.TestCheckResourceAttr("data.scaleway_marketplace_image.test1", "label", "ubuntu_focal"),
51+
resource.TestCheckResourceAttr("data.scaleway_marketplace_image.test1", "image_type", "instance_sbs"),
2752
),
2853
},
2954
},

0 commit comments

Comments
 (0)