Skip to content

feat: implement advanced search options for images#874

Closed
h3adex wants to merge 5 commits into
stackitcloud:mainfrom
h3adex:feat/implement-advanced-image-search-options
Closed

feat: implement advanced search options for images#874
h3adex wants to merge 5 commits into
stackitcloud:mainfrom
h3adex:feat/implement-advanced-image-search-options

Conversation

@h3adex

@h3adex h3adex commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

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)

Comment thread stackit/internal/services/iaas/image/datasource.go
Comment thread stackit/internal/services/iaas/image/datasource.go Outdated
@rubenhoenle

Copy link
Copy Markdown
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.

Comment thread stackit/internal/services/iaas/image/datasource.go
Comment thread stackit/internal/services/iaas/image/datasource.go Outdated
@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

h3adex commented Jun 10, 2025

Copy link
Copy Markdown
Contributor Author

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
@github-actions

Copy link
Copy Markdown

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

h3adex commented Jun 23, 2025

Copy link
Copy Markdown
Contributor Author

Also requested by: #887

@github-actions

github-actions Bot commented Jul 1, 2025

Copy link
Copy Markdown

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

h3adex commented Jul 4, 2025

Copy link
Copy Markdown
Contributor Author

Remove stale comment

@github-actions

Copy link
Copy Markdown

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

h3adex commented Jul 15, 2025

Copy link
Copy Markdown
Contributor Author

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
@github-actions

Copy link
Copy Markdown

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
@h3adex h3adex force-pushed the feat/implement-advanced-image-search-options branch from 7c9a9ae to d38ec0f Compare August 4, 2025 09:56
@github-actions

Copy link
Copy Markdown

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 Aug 18, 2025
@github-actions

Copy link
Copy Markdown

This PR was closed automatically because it has been stalled for 7 days with no activity. Feel free to re-open it at any time.

@github-actions github-actions Bot closed this Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale PR is marked as stale due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants