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

Add google_compute_images datasource #11515

Open
xabinapal opened this issue Apr 15, 2022 · 2 comments
Open

Add google_compute_images datasource #11515

xabinapal opened this issue Apr 15, 2022 · 2 comments

Comments

@xabinapal
Copy link

xabinapal commented Apr 15, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment. If the issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If the issue is assigned to a user, that user is claiming responsibility for the issue. If the issue is assigned to "hashibot", a community member has claimed the issue already.

Description

Currently, the only way to retrieve existing Compute Images is with the google_compute_image datasource: https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_image

This is quite limited, as it only supports returning exactly one image, and when used with the filter argument, this filter must be crafted so that it returns a single result.My current limitation is that I'm uploading custom images to Google Compute Engine, and they are labeled with their operating system and build date. We are also developing an internal module that should allow our developers to specify what image to use with two variables, OS name and build date (nullable). We architected it this way so that devs have some flexibility: if they know the exact image they want to use, they would specify it's build date but, if they don't mind using a specific "version", they would keep that variable as null and the latest built image should be used.

As the google_compute_image datasource requires a single image to be returned, I find impossible to develop the module so it allows this second execution mode. A datasource that allows to return more than one image would solve this, as we could select our desired image sorting it in Terraform logic.

This should not be too hard to implement, as it's logic is the same as the existing datasource, but returning an images list attribute with each element an object with the same structure as the google_compute_image datasource. I could even try to submit a PR if there is interest in this feature.

New or Affected Resource(s)

  • data.google_compute_image

Potential Terraform Configuration

data "google_compute_images" "example" {
  filter = "filter returning more than one image"
}

locals {
  # Image selection could be as complex as required
  selected_image = data.google_compute_images.example.images[0]
}

resource "google_compute_instance" "example" {
  boot_disk {
    initialize_params {
      # Each image in the images attribute 100% follows the
      # specification of the google_compute_image datasource
      image = local.selected_image.self_link
    }
  }
}

Another execution possibility would be returning all images by family, instead of the latest one:

data "google_compute_images" "example" {
  family = "debian"
}

And even a deprecated parameter could be added so it adds up to the filter or family paremeters.

b/356688105

@rileykarson
Copy link
Collaborator

Dependent on general plural datasource support: #8255

@rileykarson rileykarson added this to the Goals milestone Apr 18, 2022
@github-actions github-actions bot added service/compute-pd forward/review In review; remove label to forward labels Oct 5, 2023
@roaks3
Copy link
Collaborator

roaks3 commented Jul 31, 2024

See #8255 for light guidelines for plural datasource implementation.

@roaks3 roaks3 removed the forward/review In review; remove label to forward label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants