Skip to content

Commit 867439b

Browse files
committed
add important note to datasource
1 parent 39a8de6 commit 867439b

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

docs/data-sources/image.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,47 @@
33
page_title: "stackit_image Data Source - stackit"
44
subcategory: ""
55
description: |-
6-
Image datasource schema. Must have a region specified in the provider configuration.
6+
Provides access to operating system images for use with resources such as servers. The provider configuration must specify a region.
7+
~> Important: When using the name, name_regex, or filter attributes to select images dynamically, be aware that image IDs may change frequently. Each OS patch or update results in a new unique image ID. If this data source is used to populate fields like boot_volume.source_id in a server resource, it may cause Terraform to detect changes and recreate the associated resource.
8+
To avoid unintended updates or resource replacements:
9+
Prefer using a static image_id to pin a specific image version.If you accept automatic image updates but wish to suppress resource changes, use a lifecycle block to ignore relevant changes. For example:
10+
11+
resource "stackit_server" "example" {
12+
boot_volume = {
13+
size = 64
14+
source_type = "image"
15+
source_id = data.stackit_image.latest.id
16+
}
17+
18+
lifecycle {
19+
ignore_changes = [boot_volume[0].source_id]
20+
}
21+
}
722
---
823

924
# stackit_image (Data Source)
1025

11-
Image datasource schema. Must have a `region` specified in the provider configuration.
26+
Provides access to operating system images for use with resources such as servers. The provider configuration must specify a region.
27+
28+
~> Important: When using the `name`, `name_regex`, or `filter` attributes to select images dynamically, be aware that image IDs may change frequently. Each OS patch or update results in a new unique image ID. If this data source is used to populate fields like `boot_volume.source_id` in a server resource, it may cause Terraform to detect changes and recreate the associated resource.
29+
30+
To avoid unintended updates or resource replacements:
31+
- Prefer using a static `image_id` to pin a specific image version.
32+
- If you accept automatic image updates but wish to suppress resource changes, use a `lifecycle` block to ignore relevant changes. For example:
33+
34+
```hcl
35+
resource "stackit_server" "example" {
36+
boot_volume = {
37+
size = 64
38+
source_type = "image"
39+
source_id = data.stackit_image.latest.id
40+
}
41+
42+
lifecycle {
43+
ignore_changes = [boot_volume[0].source_id]
44+
}
45+
}
46+
```
1247

1348
## Example Usage
1449

stackit/internal/services/iaas/image/datasource.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,27 @@ func (d *imageDataSource) ConfigValidators(_ context.Context) []datasource.Confi
107107

108108
// Schema defines the schema for the datasource.
109109
func (d *imageDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
110-
description := "Image datasource schema. Must have a `region` specified in the provider configuration."
110+
description := fmt.Sprintf(
111+
"%s\n\n~> %s",
112+
"Provides access to operating system images for use with resources such as servers. The provider configuration must specify a region.",
113+
"Important: When using the `name`, `name_regex`, or `filter` attributes to select images dynamically, be aware that image IDs may change frequently. Each OS patch or update results in a new unique image ID. If this data source is used to populate fields like `boot_volume.source_id` in a server resource, it may cause Terraform to detect changes and recreate the associated resource.\n\n"+
114+
"To avoid unintended updates or resource replacements:\n"+
115+
" - Prefer using a static `image_id` to pin a specific image version.\n"+
116+
" - If you accept automatic image updates but wish to suppress resource changes, use a `lifecycle` block to ignore relevant changes. For example:\n\n"+
117+
"```hcl\n"+
118+
"resource \"stackit_server\" \"example\" {\n"+
119+
" boot_volume = {\n"+
120+
" size = 64\n"+
121+
" source_type = \"image\"\n"+
122+
" source_id = data.stackit_image.latest.id\n"+
123+
" }\n"+
124+
"\n"+
125+
" lifecycle {\n"+
126+
" ignore_changes = [boot_volume[0].source_id]\n"+
127+
" }\n"+
128+
"}\n"+
129+
"```",
130+
)
111131
resp.Schema = schema.Schema{
112132
MarkdownDescription: description,
113133
Description: description,

0 commit comments

Comments
 (0)