Skip to content
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

Allow filtering of VPC instance images via data source #5617

Open
greyhoundforty opened this issue Sep 5, 2024 · 1 comment
Open

Allow filtering of VPC instance images via data source #5617

greyhoundforty opened this issue Sep 5, 2024 · 1 comment
Labels
service/VPC Infrastructure Issues related to the VPC Infrastructure

Comments

@greyhoundforty
Copy link
Contributor

@deepaksibm - sorry for the delay, somehow I missed the original notification

I don't see a filter option listed for https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_images. Can you confirm this was implemented? I see a new user_data section but nothing related to the ability to filter by OS family

provider "ibm" {
  region = "us-south"
}

data "ibm_is_images" "images" {
  visibility = "public"
  status     = "available"
  filter {
    key    = "vendor"
    values = ["Canonical"]
  }
}

output "images" { 
   value = data.ibm_is_images.images
}

Attempt to validate

% tfv 
Initializing the backend...

Initializing provider plugins...
- Finding ibm-cloud/ibm versions matching "1.68.1"...
- Using previously-installed ibm-cloud/ibm v1.68.1

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
╷
│ Error: Unsupported block type
│
│   on main.tf line 9, in data "ibm_is_images" "images":
│    9:   filter {
│
│ Blocks of type "filter" are not expected here.
╵

I was able to get around this with using locals:

locals {
  filtered_images = [
    for image in data.ibm_is_images.images.images :
     image if contains([for os in image.operating_system : os.vendor], "Canonical")
  ]
}


data "ibm_is_images" "images" {
  visibility = "public"
  status     = "available"
  user_data_format = ["cloud_init"]
}

Originally posted by @greyhoundforty in #4930 (comment)

@github-actions github-actions bot added the service/VPC Infrastructure Issues related to the VPC Infrastructure label Sep 5, 2024
@deepaksibm
Copy link
Contributor

@greyhoundforty Terraform can only support what is supported by the API. Anything outside of what API supports should be handled in the client side terraform script like you have done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service/VPC Infrastructure Issues related to the VPC Infrastructure
Projects
None yet
Development

No branches or pull requests

3 participants
@greyhoundforty @deepaksibm and others