-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(marketplace): add image beta data source (#362)
- Loading branch information
1 parent
601efeb
commit a0f39fd
Showing
11 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters