Skip to content

Commit 531f49e

Browse files
authored
refactor(image): move image data sources to Plugin Framework (#1448)
Related to #752
1 parent 83c0bfd commit 531f49e

16 files changed

Lines changed: 727 additions & 404 deletions

File tree

docs/data-sources/image.md

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
---
2-
page_title: "Hetzner Cloud: hcloud_image"
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "hcloud_image Data Source - hcloud"
4+
subcategory: ""
35
description: |-
4-
Provides details about a specific Hetzner Cloud Image.
6+
Provides details about a Hetzner Cloud Image.
7+
It is recommended to always provide the image architecture (using ''with_architecture'').
8+
See the Image API documentation https://docs.hetzner.cloud/reference/cloud#images for more details.
59
---
610

7-
# Data Source: hcloud_image
11+
# hcloud_image (Data Source)
812

913
Provides details about a Hetzner Cloud Image.
10-
This resource is useful if you want to use a non-terraform managed image.
1114

12-
When relevant, it is recommended to always provide the image architecture
13-
(`with_architecture`) when fetching images.
15+
It is recommended to always provide the image architecture (using ''with_architecture'').
16+
17+
See the [Image API documentation](https://docs.hetzner.cloud/reference/cloud#images) for more details.
1418

1519
## Example Usage
1620

1721
```terraform
1822
data "hcloud_image" "by_id" {
19-
id = "114690387"
23+
id = 114690387
2024
}
2125
2226
data "hcloud_image" "by_name_x86" {
@@ -31,33 +35,36 @@ data "hcloud_image" "by_name_arm" {
3135
3236
data "hcloud_image" "by_label" {
3337
with_selector = "key=value"
38+
most_recent = true
3439
}
3540
3641
resource "hcloud_server" "main" {
3742
image = data.hcloud_image.by_name.id
3843
}
3944
```
4045

41-
## Argument Reference
42-
43-
- `id` - (Optional, string) ID of the Image.
44-
- `name` - (Optional, string) Name of the Image.
45-
- `with_selector` - (Optional, string) [Label selector](https://docs.hetzner.cloud/reference/cloud#label-selector)
46-
- `most_recent` - (Optional, bool) If more than one result is returned, use the most recent Image.
47-
- `with_status` - (Optional, list) Select only images with the specified status, could contain `creating` or `available`.
48-
- `with_architecture` - (Optional, string) Select only images with this architecture, could be `x86` (default) or `arm`.
49-
- `include_deprecated` - (Optional, bool) Also return the image if it is marked as deprecated.
50-
51-
## Attributes Reference
52-
53-
- `id` - (int) Unique ID of the Image.
54-
- `name` - (string) Name of the Image, only present when the Image is of type `system`.
55-
- `type` - (string) Type of the Image, could be `system`, `backup` or `snapshot`.
56-
- `status` - (string) Status of the Image.
57-
- `description` - (string) Description of the Image.
58-
- `created` - (string) Date when the Image was created (in ISO-8601 format).
59-
- `os_flavor` - (string) Flavor of operating system contained in the image, could be `ubuntu`, `centos`, `debian`, `fedora` or `unknown`.
60-
- `os_version` - (string) Operating system version.
61-
- `rapid_deploy` - (bool) Indicates that rapid deploy of the image is available.
62-
- `deprecated` - (string) Point in time when the image is considered to be deprecated (in ISO-8601 format).
63-
- `architecture` - (string) Architecture of the Image.
46+
<!-- schema generated by tfplugindocs -->
47+
## Schema
48+
49+
### Optional
50+
51+
- `id` (Number) ID of the Image.
52+
- `include_deprecated` (Boolean) Include deprecated images.
53+
- `most_recent` (Boolean) Sort results by created date, and return the most recent result.
54+
- `name` (String) Name of the Image, only present when the type is `system`.
55+
- `selector` (String, Deprecated) Filter results using a [Label Selector](https://docs.hetzner.cloud/reference/cloud#label-selector).
56+
- `with_architecture` (String) Filter results by architecture, for example `x86` (default) or `arm`.
57+
- `with_selector` (String) Filter results using a [Label Selector](https://docs.hetzner.cloud/reference/hetzner#label-selector).
58+
- `with_status` (Set of String) Filter results by statuses, for example `creating` or `available`.
59+
60+
### Read-Only
61+
62+
- `architecture` (String) CPU architecture compatible with the Image.
63+
- `created` (String) Point in time when the Image was created (in RFC3339 format).
64+
- `deprecated` (String) Point in time when the Image was marked as deprecated (in RFC3339 format).
65+
- `description` (String) Description of the Image.
66+
- `labels` (Map of String) User-defined [labels](https://docs.hetzner.cloud/reference/cloud#labels) (key-value pairs) for the resource.
67+
- `os_flavor` (String) Flavor of the operating system contained in the Image.
68+
- `os_version` (String) Version of the operating system contained in the Image.
69+
- `rapid_deploy` (Boolean) Whether the Image is optimized for a rapid deployment.
70+
- `type` (String) Type of the Image, for example `system`, `backup` or `snapshot`.

docs/data-sources/images.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
---
2-
page_title: "Hetzner Cloud: hcloud_images"
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "hcloud_images Data Source - hcloud"
4+
subcategory: ""
35
description: |-
4-
Provides details about multiple Hetzner Cloud Images.
6+
Provides a list of Hetzner Storage Images.
7+
It is recommended to always provide the image architecture (using ''with_architecture'').
8+
See the Image API documentation https://docs.hetzner.cloud/reference/cloud#images for more details.
59
---
610

7-
# Data Source: hcloud_images
11+
# hcloud_images (Data Source)
812

9-
Provides details about multiple Hetzner Cloud Images.
13+
Provides a list of Hetzner Storage Images.
1014

11-
When relevant, it is recommended to always provide the image architecture
12-
(`with_architecture`) when fetching images.
15+
It is recommended to always provide the image architecture (using ''with_architecture'').
16+
17+
See the [Image API documentation](https://docs.hetzner.cloud/reference/cloud#images) for more details.
1318

1419
## Example Usage
1520

@@ -23,14 +28,35 @@ data "hcloud_images" "by_label" {
2328
}
2429
```
2530

26-
## Argument Reference
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
33+
34+
### Optional
35+
36+
- `include_deprecated` (Boolean) Include deprecated images.
37+
- `most_recent` (Boolean) Sort results by created date.
38+
- `with_architecture` (Set of String) Filter results by architecture, for example `x86` or `arm`.
39+
- `with_selector` (String) Filter results using a [Label Selector](https://docs.hetzner.cloud/reference/hetzner#label-selector).
40+
- `with_status` (Set of String) Filter results by statuses, for example `creating` or `available`.
41+
42+
### Read-Only
43+
44+
- `id` (String) The ID of this resource.
45+
- `images` (Attributes List) (see [below for nested schema](#nestedatt--images))
2746

28-
- `with_selector` - (Optional, string) [Label selector](https://docs.hetzner.cloud/reference/cloud#label-selector)
29-
- `most_recent` - (Optional, bool) Sorts list by date.
30-
- `with_status` - (Optional, list) List only images with the specified status, could contain `creating` or `available`.
31-
- `with_architecture` - (Optional, list) List only images with this architecture, could contain `x86` or `arm`.
32-
- `include_deprecated` - (Optional, bool) Also list images that are marked as deprecated.
47+
<a id="nestedatt--images"></a>
48+
### Nested Schema for `images`
3349

34-
## Attributes Reference
50+
Read-Only:
3551

36-
- `images` - (list) List of all matching images. See `data.hcloud_image` for schema.
52+
- `architecture` (String) CPU architecture compatible with the Image.
53+
- `created` (String) Point in time when the Image was created (in RFC3339 format).
54+
- `deprecated` (String) Point in time when the Image was marked as deprecated (in RFC3339 format).
55+
- `description` (String) Description of the Image.
56+
- `id` (Number) ID of the Image.
57+
- `labels` (Map of String) User-defined [labels](https://docs.hetzner.cloud/reference/cloud#labels) (key-value pairs) for the resource.
58+
- `name` (String) Name of the Image, only present when the type is `system`.
59+
- `os_flavor` (String) Flavor of the operating system contained in the Image.
60+
- `os_version` (String) Version of the operating system contained in the Image.
61+
- `rapid_deploy` (Boolean) Whether the Image is optimized for a rapid deployment.
62+
- `type` (String) Type of the Image, for example `system`, `backup` or `snapshot`.

examples/data-sources/hcloud_image/data-source.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data "hcloud_image" "by_id" {
2-
id = "114690387"
2+
id = 114690387
33
}
44

55
data "hcloud_image" "by_name_x86" {
@@ -14,6 +14,7 @@ data "hcloud_image" "by_name_arm" {
1414

1515
data "hcloud_image" "by_label" {
1616
with_selector = "key=value"
17+
most_recent = true
1718
}
1819

1920
resource "hcloud_server" "main" {

hcloud/plugin_provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/hetznercloud/hcloud-go/v2/hcloud"
2323
"github.com/hetznercloud/terraform-provider-hcloud/internal/datacenter"
24+
"github.com/hetznercloud/terraform-provider-hcloud/internal/image"
2425
"github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer"
2526
"github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancertype"
2627
"github.com/hetznercloud/terraform-provider-hcloud/internal/location"
@@ -209,6 +210,8 @@ func (p *PluginProvider) DataSources(_ context.Context) []func() datasource.Data
209210
return []func() datasource.DataSource{
210211
datacenter.NewDataSource,
211212
datacenter.NewDataSourceList,
213+
image.NewDataSource,
214+
image.NewDataSourceList,
212215
loadbalancertype.NewDataSource,
213216
loadbalancertype.NewDataSourceList,
214217
location.NewDataSource,

hcloud/provider.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/hetznercloud/terraform-provider-hcloud/internal/certificate"
1616
"github.com/hetznercloud/terraform-provider-hcloud/internal/firewall"
1717
"github.com/hetznercloud/terraform-provider-hcloud/internal/floatingip"
18-
"github.com/hetznercloud/terraform-provider-hcloud/internal/image"
1918
"github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer"
2019
"github.com/hetznercloud/terraform-provider-hcloud/internal/network"
2120
"github.com/hetznercloud/terraform-provider-hcloud/internal/placementgroup"
@@ -102,8 +101,6 @@ func Provider() *schema.Provider {
102101
firewall.DataSourceListType: firewall.DataSourceList(),
103102
floatingip.DataSourceType: floatingip.DataSource(),
104103
floatingip.DataSourceListType: floatingip.DataSourceList(),
105-
image.DataSourceType: image.DataSource(),
106-
image.DataSourceListType: image.DataSourceList(),
107104
loadbalancer.DataSourceType: loadbalancer.DataSource(),
108105
loadbalancer.DataSourceListType: loadbalancer.DataSourceList(),
109106
network.DataSourceType: network.DataSource(),

hcloud/provider_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/hetznercloud/terraform-provider-hcloud/internal/certificate"
99
"github.com/hetznercloud/terraform-provider-hcloud/internal/firewall"
1010
"github.com/hetznercloud/terraform-provider-hcloud/internal/floatingip"
11-
"github.com/hetznercloud/terraform-provider-hcloud/internal/image"
1211
"github.com/hetznercloud/terraform-provider-hcloud/internal/loadbalancer"
1312
"github.com/hetznercloud/terraform-provider-hcloud/internal/network"
1413
"github.com/hetznercloud/terraform-provider-hcloud/internal/placementgroup"
@@ -63,8 +62,6 @@ func TestProvider_DataSources(t *testing.T) {
6362
firewall.DataSourceListType,
6463
floatingip.DataSourceType,
6564
floatingip.DataSourceListType,
66-
image.DataSourceType,
67-
image.DataSourceListType,
6865
loadbalancer.DataSourceType,
6966
loadbalancer.DataSourceListType,
7067
network.DataSourceType,

0 commit comments

Comments
 (0)