Skip to content

feat: implement advanced search options for images #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

h3adex
Copy link
Contributor

@h3adex h3adex commented Jun 10, 2025

Description

This PR improves the stackit_image 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" "name_match_ubuntu_22_04" {
  project_id = var.project_id
  name       = "Ubuntu 22.04"
}

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

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

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

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

data "stackit_image" "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" "name_windows_2022_standard" {
  project_id = var.project_id
  name       = "Windows Server 2022 Standard"
}

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

data "stackit_image" "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)

@rubenhoenle
Copy link
Member

Are there any other datasources in which we might want to re-use this? This could be re-structured to be a general approach. I wouldn't want to duplicate this code in the future.

@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch 3 times, most recently from 2f22ea0 to 39a8de6 Compare June 10, 2025 12:43
@h3adex
Copy link
Contributor Author

h3adex commented Jun 10, 2025

Are there any other datasources in which we might want to re-use this? This could be re-structured to be a general approach. I wouldn't want to duplicate this code in the future.

I don't see any other usecase - This seems like a edgecase for a datasource. I also did not reinvent the wheel. I checked the implementation of gcp and azure.

@h3adex h3adex changed the title Draft: feat: implement advanced search options for images feat: implement advanced search options for images Jun 10, 2025
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch 2 times, most recently from 867439b to d0e15f9 Compare June 12, 2025 10:05
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from d0e15f9 to 686d03a Compare June 12, 2025 14:08
@h3adex h3adex requested a review from rubenhoenle June 12, 2025 19:23
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.

2 participants