Skip to content

Commit 7ccc5c9

Browse files
committed
feat: implement advanced search options for images
1 parent 5e5404b commit 7ccc5c9

File tree

9 files changed

+775
-69
lines changed

9 files changed

+775
-69
lines changed

docs/data-sources/image.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,52 @@ Image datasource schema. Must have a `region` specified in the provider configur
1313
## Example Usage
1414

1515
```terraform
16-
data "stackit_image" "example" {
16+
data "stackit_image" "default" {
1717
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1818
image_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
1919
}
20+
21+
data "stackit_image" "name_match" {
22+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
23+
name = "Ubuntu 22.04"
24+
}
25+
26+
data "stackit_image" "name_regex_latest" {
27+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
28+
name_regex = "^Ubuntu .*"
29+
sort_descending = true
30+
}
31+
32+
data "stackit_image" "name_regex_oldest" {
33+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
34+
name_regex = "^Ubuntu .*"
35+
sort_descending = false
36+
}
37+
38+
data "stackit_image" "filter_distro_version" {
39+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
40+
filter = {
41+
distro = "debian"
42+
version = "11"
43+
}
44+
}
2045
```
2146

2247
<!-- schema generated by tfplugindocs -->
2348
## Schema
2449

2550
### Required
2651

27-
- `image_id` (String) The image ID.
2852
- `project_id` (String) STACKIT project ID to which the image is associated.
2953

54+
### Optional
55+
56+
- `filter` (Attributes) Additional filtering options based on image properties. Can be used independently or in conjunction with `name` or `name_regex`. (see [below for nested schema](#nestedatt--filter))
57+
- `image_id` (String) Image ID to fetch directly
58+
- `name` (String) Exact image name to match. Optionally applies a `filter` block to further refine results in case multiple images share the same name. The first match is returned, optionally sorted by name in descending order. Cannot be used together with `name_regex`.
59+
- `name_regex` (String) Regular expression to match against image names. Optionally applies a `filter` block to narrow down results when multiple image names match the regex. The first match is returned, optionally sorted by name in descending order. Cannot be used together with `name`.
60+
- `sort_descending` (Boolean) If set to `true`, images are sorted in descending lexicographical order by image name before selecting the first match. Defaults to `false` (ascending).
61+
3062
### Read-Only
3163

3264
- `checksum` (Attributes) Representation of an image checksum. (see [below for nested schema](#nestedatt--checksum))
@@ -36,10 +68,21 @@ data "stackit_image" "example" {
3668
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
3769
- `min_disk_size` (Number) The minimum disk size of the image in GB.
3870
- `min_ram` (Number) The minimum RAM of the image in MB.
39-
- `name` (String) The name of the image.
4071
- `protected` (Boolean) Whether the image is protected.
4172
- `scope` (String) The scope of the image.
4273

74+
<a id="nestedatt--filter"></a>
75+
### Nested Schema for `filter`
76+
77+
Optional:
78+
79+
- `distro` (String) Filter images by operating system distribution. For example: `ubuntu`, `ubuntu-arm64`, `debian`, `rhel`, etc.
80+
- `os` (String) Filter images by operating system type, such as `linux` or `windows`.
81+
- `secure_boot` (Boolean) Filter images with Secure Boot support. Set to `true` to match images that support Secure Boot.
82+
- `uefi` (Boolean) Filter images based on UEFI support. Set to `true` to match images that support UEFI.
83+
- `version` (String) Filter images by OS distribution version, such as `22.04`, `11`, or `9.1`.
84+
85+
4386
<a id="nestedatt--checksum"></a>
4487
### Nested Schema for `checksum`
4588

docs/resources/server.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ description: |-
77
Example Usage
88
With key pair
99
10+
data "stackit_image" "image" {
11+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
12+
name = "Ubuntu 22.04"
13+
}
14+
1015
resource "stackit_key_pair" "keypair" {
1116
name = "example-key-pair"
1217
public_key = chomp(file("path/to/id_rsa.pub"))
@@ -17,7 +22,7 @@ description: |-
1722
boot_volume = {
1823
size = 64
1924
source_type = "image"
20-
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
25+
source_id = data.stackit_image.image.id
2126
}
2227
name = "example-server"
2328
machine_type = "g1.1"
@@ -28,13 +33,18 @@ description: |-
2833
2934
Boot from volume
3035
36+
data "stackit_image" "image" {
37+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
38+
name = "Ubuntu 22.04"
39+
}
40+
3141
resource "stackit_server" "boot-from-volume" {
3242
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3343
name = "example-server"
3444
boot_volume = {
3545
size = 64
3646
source_type = "image"
37-
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
47+
source_id = data.stackit_image.image.id
3848
}
3949
availability_zone = "eu01-1"
4050
machine_type = "g1.1"
@@ -44,12 +54,17 @@ description: |-
4454
4555
Boot from existing volume
4656
57+
data "stackit_image" "image" {
58+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
59+
name = "Ubuntu 22.04"
60+
}
61+
4762
resource "stackit_volume" "example-volume" {
4863
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
4964
size = 12
5065
source = {
5166
type = "image"
52-
id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
67+
id = data.stackit_image.image.id
5368
}
5469
name = "example-volume"
5570
availability_zone = "eu01-1"
@@ -188,6 +203,11 @@ Server resource schema. Must have a region specified in the provider configurati
188203

189204
### With key pair
190205
```terraform
206+
data "stackit_image" "image" {
207+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
208+
name = "Ubuntu 22.04"
209+
}
210+
191211
resource "stackit_key_pair" "keypair" {
192212
name = "example-key-pair"
193213
public_key = chomp(file("path/to/id_rsa.pub"))
@@ -198,7 +218,7 @@ resource "stackit_server" "user-data-from-file" {
198218
boot_volume = {
199219
size = 64
200220
source_type = "image"
201-
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
221+
source_id = data.stackit_image.image.id
202222
}
203223
name = "example-server"
204224
machine_type = "g1.1"
@@ -210,13 +230,18 @@ resource "stackit_server" "user-data-from-file" {
210230

211231
### Boot from volume
212232
```terraform
233+
data "stackit_image" "image" {
234+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
235+
name = "Ubuntu 22.04"
236+
}
237+
213238
resource "stackit_server" "boot-from-volume" {
214239
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
215240
name = "example-server"
216241
boot_volume = {
217242
size = 64
218243
source_type = "image"
219-
source_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
244+
source_id = data.stackit_image.image.id
220245
}
221246
availability_zone = "eu01-1"
222247
machine_type = "g1.1"
@@ -227,12 +252,17 @@ resource "stackit_server" "boot-from-volume" {
227252

228253
### Boot from existing volume
229254
```terraform
255+
data "stackit_image" "image" {
256+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
257+
name = "Ubuntu 22.04"
258+
}
259+
230260
resource "stackit_volume" "example-volume" {
231261
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
232262
size = 12
233263
source = {
234264
type = "image"
235-
id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
265+
id = data.stackit_image.image.id
236266
}
237267
name = "example-volume"
238268
availability_zone = "eu01-1"
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
data "stackit_image" "example" {
1+
data "stackit_image" "default" {
22
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
33
image_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
44
}
5+
6+
data "stackit_image" "name_match" {
7+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
8+
name = "Ubuntu 22.04"
9+
}
10+
11+
data "stackit_image" "name_regex_latest" {
12+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
13+
name_regex = "^Ubuntu .*"
14+
sort_descending = true
15+
}
16+
17+
data "stackit_image" "name_regex_oldest" {
18+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
19+
name_regex = "^Ubuntu .*"
20+
sort_descending = false
21+
}
22+
23+
data "stackit_image" "filter_distro_version" {
24+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
25+
filter = {
26+
distro = "debian"
27+
version = "11"
28+
}
29+
}

0 commit comments

Comments
 (0)