diff --git a/scaleway/data_source_marketplace_image_beta.go b/scaleway/data_source_marketplace_image_beta.go new file mode 100644 index 000000000..668a893fa --- /dev/null +++ b/scaleway/data_source_marketplace_image_beta.go @@ -0,0 +1,53 @@ +package scaleway + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/scaleway/scaleway-sdk-go/api/marketplace/v1" +) + +func dataSourceScalewayMarketplaceImageBeta() *schema.Resource { + return &schema.Resource{ + Read: dataSourceScalewayMarketplaceImageReadBeta, + + Schema: map[string]*schema.Schema{ + "label": { + Type: schema.TypeString, + Required: true, + Description: "Exact label of the desired image", + }, + "instance_type": { + Type: schema.TypeString, + Optional: true, + Default: "DEV1-S", + Description: "The instance commercial type of the desired image", + }, + "zone": zoneSchema(), + }, + } +} + +func dataSourceScalewayMarketplaceImageReadBeta(d *schema.ResourceData, m interface{}) error { + meta := m.(*Meta) + marketplaceAPI := marketplace.NewAPI(meta.scwClient) + zone, err := getZone(d, meta) + if err != nil { + return err + } + + imageID, err := marketplaceAPI.GetLocalImageIDByLabel(&marketplace.GetLocalImageIDByLabelRequest{ + ImageLabel: d.Get("label").(string), + CommercialType: d.Get("instance_type").(string), + Zone: zone, + }) + if err != nil { + return err + } + + zonedID := datasourceNewZonedID(imageID, zone) + d.SetId(zonedID) + d.Set("zone", zone) + d.Set("label", d.Get("label")) + d.Set("instance_type", d.Get("type")) + + return nil +} diff --git a/scaleway/data_source_marketplace_image_beta_test.go b/scaleway/data_source_marketplace_image_beta_test.go new file mode 100644 index 000000000..6ca77b3db --- /dev/null +++ b/scaleway/data_source_marketplace_image_beta_test.go @@ -0,0 +1,27 @@ +package scaleway + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccScalewayDataSourceMarketplaceImageBeta_Basic(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: ` +data "scaleway_marketplace_image_beta" "test1" { + label = "ubuntu-bionic" +} +`, + Check: resource.ComposeTestCheckFunc( + testAccCheckScalewayInstanceImageExists("data.scaleway_marketplace_image_beta.test1"), + resource.TestCheckResourceAttr("data.scaleway_marketplace_image_beta.test1", "id", "fr-par-1/f974feac-abae-4365-b988-8ec7d1cec10d"), + ), + }, + }, + }) +} diff --git a/scaleway/provider.go b/scaleway/provider.go index f089cabb5..93deec592 100644 --- a/scaleway/provider.go +++ b/scaleway/provider.go @@ -226,6 +226,7 @@ func Provider() terraform.ResourceProvider { "scaleway_instance_image": dataSourceScalewayInstanceImage(), "scaleway_instance_volume": dataSourceScalewayInstanceVolume(), "scaleway_baremetal_offer_beta": dataSourceScalewayBaremetalOfferBeta(), + "scaleway_marketplace_image_beta": dataSourceScalewayMarketplaceImageBeta(), }, } diff --git a/website/docs/d/image.html.markdown b/website/docs/d/image.html.markdown index ffe87a807..e314ee8b0 100644 --- a/website/docs/d/image.html.markdown +++ b/website/docs/d/image.html.markdown @@ -8,7 +8,7 @@ description: |- # scaleway_image **DEPRECATED**: This resource is deprecated and will be removed in `v2.0+`. -Please use `scaleway_instance_image` instead. +Please use `scaleway_instance_image` instead or `scaleway_marketplace_image_beta` depending on your usage. Use this data source to get the ID of a registered Image for use with the `scaleway_server` resource. diff --git a/website/docs/d/instance_image.html.markdown b/website/docs/d/instance_image.html.markdown index cd5a3af75..639fdfde9 100644 --- a/website/docs/d/instance_image.html.markdown +++ b/website/docs/d/instance_image.html.markdown @@ -14,7 +14,7 @@ Gets information about an instance image. ```hcl // Get info by image name data "scaleway_instance_image" "my_image" { - name = "ubuntu bionic" + name = "my-image-name" } // Get info by image id @@ -33,7 +33,7 @@ data "scaleway_instance_image" "my_image" { - `latest` - (Optional, default `true`) Use the latest image ID. -- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the image should be created. +- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the image exists. ## Attributes Reference diff --git a/website/docs/d/instance_security_group.html.markdown b/website/docs/d/instance_security_group.html.markdown index 606335c16..698ed1440 100644 --- a/website/docs/d/instance_security_group.html.markdown +++ b/website/docs/d/instance_security_group.html.markdown @@ -29,7 +29,7 @@ data "scaleway_instance_security_group" "my_key" { - `security_group_id` - (Optional) The security group id. Only one of `name` and `security_group_id` should be specified. -- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the security group should be created. +- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the security group exists. ## Attributes Reference diff --git a/website/docs/d/instance_server.html.markdown b/website/docs/d/instance_server.html.markdown index 9b64dcb07..d79633479 100644 --- a/website/docs/d/instance_server.html.markdown +++ b/website/docs/d/instance_server.html.markdown @@ -29,7 +29,7 @@ data "scaleway_instance_server" "my_key" { - `server_id` - (Optional) The server id. Only one of `name` and `server_id` should be specified. -- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the server should be created. +- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the server exists. ## Attributes Reference @@ -37,6 +37,11 @@ In addition to all above arguments, the following attributes are exported: - `id` - The ID of the server. +- `type` - The commercial type of the server. +You find all the available types on the [pricing page](https://www.scaleway.com/en/pricing/). + +- `image` - The UUID and the label of the base image used by the server. + - `organization_id` - The ID of the organization the server is associated with. - `tags` - The tags associated with the server. @@ -58,7 +63,7 @@ attached to the server. - `state` - The state of the server. Possible values are: `started`, `stopped` or `standby`. -- `cloud_init` - The cloud init script associated with this server. Updates to this field will trigger a stop/start of the server. +- `cloud_init` - The cloud init script associated with this server. - `user_data` - The user data associated with the server. diff --git a/website/docs/d/instance_volume.html.markdown b/website/docs/d/instance_volume.html.markdown index 5f0e24637..cefdba464 100644 --- a/website/docs/d/instance_volume.html.markdown +++ b/website/docs/d/instance_volume.html.markdown @@ -31,7 +31,7 @@ data "scaleway_instance_volume" "my_volume" { - `volume_id` - (Optional) The volume id. Only one of `name` and `volume_id` should be specified. -- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the server should be created. +- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the volume exists. - `organization_id` - (Defaults to [provider](../index.html#organization_id) `organization_id`) The ID of the organization the server is associated with. diff --git a/website/docs/d/marketplace_image_beta.html.markdown b/website/docs/d/marketplace_image_beta.html.markdown new file mode 100644 index 000000000..ce2206062 --- /dev/null +++ b/website/docs/d/marketplace_image_beta.html.markdown @@ -0,0 +1,34 @@ +--- +layout: "scaleway" +page_title: "Scaleway: scaleway_marketplace_image_beta" +description: |- + Gets local image ID of an image from its label name. +--- + +# scaleway_marketplace_image_beta + +Gets local image ID of an image from its label name. + +## Example Usage + +```hcl +data "scaleway_marketplace_image_beta" "my_image" { + labal = "ubuntu-bionic" +} +``` + +## Argument Reference + +- `label` - (Required) Exact label of the desired image. You can use [this endpoint](https://api-marketplace.scaleway.com/images?page=1&per_page=100) +to find the right `label`. + +- `instance_type` - (Optional, default `DEV1-S`) The instance type the image is compatible with. +You find all the available types on the [pricing page](https://www.scaleway.com/en/pricing/). + +- `zone` - (Defaults to [provider](../index.html#zone) `zone`) The [zone](../guides/regions_and_zones.html#zones) in which the image exists. + +## Attributes Reference + +In addition to all above arguments, the following attributes are exported: + +- `id` - The ID of the image. diff --git a/website/docs/r/instance_server.html.markdown b/website/docs/r/instance_server.html.markdown index 4dfd345a9..04f5b7870 100644 --- a/website/docs/r/instance_server.html.markdown +++ b/website/docs/r/instance_server.html.markdown @@ -116,7 +116,7 @@ Updates to this field will recreate a new resource. [//]: # (TODO: Improve me) - `image` - (Required) The UUID or the label of the base image used by the server. You can use [this endpoint](https://api-marketplace.scaleway.com/images?page=1&per_page=100) -to find either the right `label` or the right local image `ID` for a given `commercial_type`. +to find either the right `label` or the right local image `ID` for a given `type`. [//]: # (TODO: Improve me) diff --git a/website/scaleway.erb b/website/scaleway.erb index 073022f5f..f15634fe5 100644 --- a/website/scaleway.erb +++ b/website/scaleway.erb @@ -145,6 +145,15 @@ +