Skip to content

Commit 75094fe

Browse files
authored
Merge pull request #909 from ovh/dev/aamstutz/add-cloud-images
feat: Add cloud images datasources
2 parents 35378a9 + ce84e1d commit 75094fe

13 files changed

+1952
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
subcategory : "Cloud Project"
3+
---
4+
5+
# ovh_cloud_project_image (Data Source)
6+
7+
Get information about an image in the given public cloud project.
8+
9+
## Example Usage
10+
11+
```terraform
12+
data "ovh_cloud_project_image" "image" {
13+
service_name = "<public cloud project ID>"
14+
image_id = "<image ID>"
15+
}
16+
```
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `image_id` (String) Image ID
24+
- `service_name` (String) Public cloud project ID
25+
26+
### Read-Only
27+
28+
- `creation_date` (String) Image creation date
29+
- `flavor_type` (String) Image usable only for this type of flavor if not null
30+
- `id` (String) Image ID
31+
- `min_disk` (Number) Minimum disks required to use image
32+
- `min_ram` (Number) Minimum RAM required to use image
33+
- `name` (String) Image name
34+
- `plan_code` (String) Order plan code
35+
- `region` (String) Image region
36+
- `size` (Number) Image size (in GiB)
37+
- `status` (String) Image status
38+
- `tags` (List of String) Tags about the image
39+
- `type` (String) Image type
40+
- `user` (String) User to connect with
41+
- `visibility` (String) Image visibility
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
subcategory : "Cloud Project"
3+
---
4+
5+
# ovh_cloud_project_images (Data Source)
6+
7+
Get available images in the given public cloud project.
8+
9+
## Example Usage
10+
11+
```terraform
12+
data "ovh_cloud_project_images" "images" {
13+
service_name = "<public cloud project ID>"
14+
region = "WAW1"
15+
os_type = "linux"
16+
}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Required
23+
24+
- `service_name` (String) Public cloud project ID
25+
26+
### Optional
27+
28+
- `flavor_type` (String) Get compatible images with flavor type
29+
- `os_type` (String) Image OS (Allowed values: baremetal-linux ┃ bsd ┃ linux ┃ windows)
30+
- `region` (String) Image region
31+
32+
### Read-Only
33+
34+
- `images` (Attributes Set) (see [below for nested schema](#nestedatt--images))
35+
36+
<a id="nestedatt--images"></a>
37+
### Nested Schema for `images`
38+
39+
Read-Only:
40+
41+
- `creation_date` (String) Image creation date
42+
- `flavor_type` (String) Image usable only for this type of flavor if not null
43+
- `id` (String) Image ID
44+
- `min_disk` (Number) Minimum disks required to use image
45+
- `min_ram` (Number) Minimum RAM required to use image
46+
- `name` (String) Image name
47+
- `plan_code` (String) Order plan code
48+
- `region` (String) Image region
49+
- `size` (Number) Image size (in GiB)
50+
- `status` (String) Image status
51+
- `tags` (List of String) Tags about the image
52+
- `type` (String) Image type
53+
- `user` (String) User to connect with
54+
- `visibility` (String) Image visibility
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "ovh_cloud_project_image" "image" {
2+
service_name = "<public cloud project ID>"
3+
image_id = "<image ID>"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data "ovh_cloud_project_images" "images" {
2+
service_name = "<public cloud project ID>"
3+
region = "WAW1"
4+
os_type = "linux"
5+
}

ovh/data_cloud_project_image.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package ovh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/url"
7+
8+
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
)
10+
11+
var _ datasource.DataSourceWithConfigure = (*cloudProjectImageDataSource)(nil)
12+
13+
func NewCloudProjectImageDataSource() datasource.DataSource {
14+
return &cloudProjectImageDataSource{}
15+
}
16+
17+
type cloudProjectImageDataSource struct {
18+
config *Config
19+
}
20+
21+
func (d *cloudProjectImageDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
22+
resp.TypeName = req.ProviderTypeName + "_cloud_project_image"
23+
}
24+
25+
func (d *cloudProjectImageDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
26+
if req.ProviderData == nil {
27+
return
28+
}
29+
30+
config, ok := req.ProviderData.(*Config)
31+
if !ok {
32+
resp.Diagnostics.AddError(
33+
"Unexpected Data Source Configure Type",
34+
fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
35+
)
36+
return
37+
}
38+
39+
d.config = config
40+
}
41+
42+
func (d *cloudProjectImageDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
43+
resp.Schema = CloudProjectImageDataSourceSchema(ctx)
44+
}
45+
46+
func (d *cloudProjectImageDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
47+
var data CloudProjectImageModel
48+
49+
// Read Terraform configuration data into the model
50+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
51+
52+
if resp.Diagnostics.HasError() {
53+
return
54+
}
55+
56+
// Read API call logic
57+
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/image/" + url.PathEscape(data.ImageId.ValueString())
58+
if err := d.config.OVHClient.Get(endpoint, &data); err != nil {
59+
resp.Diagnostics.AddError(
60+
fmt.Sprintf("Error calling Get %s", endpoint),
61+
err.Error(),
62+
)
63+
return
64+
}
65+
66+
// Save data into Terraform state
67+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
68+
}

ovh/data_cloud_project_image_gen.go

+203
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)