@@ -82,6 +82,8 @@ We have to expect several matches here and need some heuristic to find the
8282right image, preferrably the one matching the old naming convention.
8383
8484Full code that does this is available in [ find_img.py] ( find_img.py ) .
85+ The script assume that you have set your ` OS_CLOUD ` environment variable
86+ and have configured working ` clouds.yaml ` and ` secure.yaml ` .
8587Feel free to copy, I deliberately put this under MIT license.
8688
8789## Identifying the image with OpenStack CLI
@@ -108,6 +110,39 @@ somewhat similar (but not identical) to the python code.
108110
109111Full code that does this is available in [ find_img.sh] ( find_img.sh ) .
110112
111- ## Terraform / opentofu
113+ ## opentofu / terraform
114+
115+ With opentofu (or Hashicorp's terraform is you still use it), identifying
116+ the image in an HCL recipe looks like this:
117+
118+ ``` hcl
119+ # Find the image
120+ data "openstack_images_image_v2" "my_image" {
121+ most_recent = true
122+
123+ properties = {
124+ os_distro = "ubuntu"
125+ os_version = "24.04"
126+ os_purpose = "generic"
127+ }
128+ # sort_key = "name"
129+ # sort_direction = "desc"
130+ }
131+
132+ # Use the selected image
133+ resource "openstack_compute_instance_v2" "instance" {
134+ image_id = data.openstack_images_image_v2.my_image.id
135+ ...
136+ }
137+ ```
138+
139+ This will find the most recent image wtih the ` os_ ` variables set to ` ubuntu ` , ` 24.04 ` , ` generic ` .
140+ Note that unlike the python and shell examples, we can not easily sort for name and creation
141+ date at the same time; the name sorting is thus commented out here. To use name sorting you can
142+ enable it — using it and then selecting the latest if the name is identical requires some
143+ HCL magic using ` locals ` and ` reverse(sort(...)) ` calls or calling an external program.
144+
145+ An example can be found in [ find_img.tf] ( find_img.tf ) . Call it with ` tofu apply -auto-approve `
146+ (after you ran ` tofu init ` in this directory once).
112147
113- TBW
148+ The fallback to name matching is harder.
0 commit comments