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 3 times, most recently from d0e15f9 to 686d03a Compare June 12, 2025 14:08
@h3adex h3adex requested a review from rubenhoenle June 12, 2025 19:23
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jun 20, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Jun 23, 2025
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from 686d03a to d4e5c28 Compare June 23, 2025 12:17
@h3adex
Copy link
Contributor Author

h3adex commented Jun 23, 2025

Also requested by: #887

Copy link

github-actions bot commented Jul 1, 2025

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jul 1, 2025
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from d4e5c28 to 9e8aded Compare July 2, 2025 07:38
@github-actions github-actions bot removed the Stale PR is marked as stale due to inactivity. label Jul 3, 2025
@h3adex
Copy link
Contributor Author

h3adex commented Jul 4, 2025

Remove stale comment

Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jul 12, 2025
@h3adex
Copy link
Contributor Author

h3adex commented Jul 15, 2025

Bump remove stale

@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from 9e8aded to b18548a Compare July 15, 2025 12:11
@h3adex h3adex requested a review from a team as a code owner July 15, 2025 12:11
@github-actions github-actions bot removed the Stale PR is marked as stale due to inactivity. label Jul 16, 2025
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from b18548a to a82e816 Compare July 18, 2025 08:19
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jul 26, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Jul 29, 2025
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from a82e816 to 7c9a9ae Compare July 31, 2025 12:21
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