Skip to content

Conversation

h3adex
Copy link
Contributor

@h3adex h3adex commented Aug 26, 2025

Description

This PR improves the stackit_image_v2 data source by enabling image selection via name, regex, or detailed filters (OS, distro, version, UEFI, and secure_boot). When multiple results match (e.g., Ubuntu 18.04, 20.04...), they are sorted descending by name, selecting the newest. Similar to Azure’s behavior.

The design aligns with syntax and behavior from other providers like Azure, Google, and OpenStack.

Unlike Google/OpenStack, we avoid relying on most_recent or timestamps (created_at, updated_at) since these refer to upload/update events—not actual image creation by the vendor. Instead, we sort by name/system version to reliably select the latest version.

Code to test it:

variable "project_id" {}

data "stackit_image_v2" "name_match_ubuntu_22_04" {
  project_id = var.project_id
  name       = "Ubuntu 22.04"
}

data "stackit_image_v2" "ubuntu_by_image_id" {
  project_id = var.project_id
  image_id   = data.stackit_image.name_match_ubuntu_22_04.image_id
}

data "stackit_image_v2" "regex_match_ubuntu_22_04" {
  project_id = var.project_id
  name_regex = "(?i)^ubuntu 22.04$"
}

data "stackit_image_v2" "filter_debian_11" {
  project_id = var.project_id
  filter = {
    distro  = "debian"
    version = "11"
  }
}

data "stackit_image_v2" "filter_uefi_ubuntu" {
  project_id = var.project_id
  filter = {
    distro = "ubuntu"
    uefi = true
  }
}

data "stackit_image_v2" "name_regex_and_filter_rhel_9_1" {
  project_id = var.project_id
  name_regex = "^Red Hat Enterprise Linux 9.1$"
  filter = {
    distro = "rhel"
    version = "9.1"
    uefi = true
  }
}

data "stackit_image_v2" "name_windows_2022_standard" {
  project_id = var.project_id
  name       = "Windows Server 2022 Standard"
}

data "stackit_image_v2" "ubuntu_arm64_latest" {
  project_id = var.project_id
  filter = {
    distro = "ubuntu-arm64"
  }
}

data "stackit_image_v2" "ubuntu_arm64_oldest" {
  project_id = var.project_id
  filter = {
    distro = "ubuntu-arm64"
  }
  sort_ascending = true
}

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@h3adex h3adex requested a review from a team as a code owner August 26, 2025 08:12
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch 6 times, most recently from 0390758 to 152f190 Compare August 28, 2025 09:27
@h3adex
Copy link
Contributor Author

h3adex commented Aug 28, 2025

E2E Tests

Screenshot 2025-08-28 at 11 34 33

@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch 2 times, most recently from 6bcb992 to 5b2b782 Compare August 28, 2025 09:37
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from 5b2b782 to 63f65f4 Compare August 28, 2025 14:48
Copy link
Contributor

@Fyusel Fyusel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 😃 Only one nitpick

h3adex and others added 2 commits September 1, 2025 13:45
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
Signed-off-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from aa420f8 to f466a37 Compare September 1, 2025 11:45
@h3adex h3adex requested a review from Fyusel September 1, 2025 11:46
@Fyusel Fyusel merged commit 9ac92b7 into stackitcloud:main Sep 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants