Open xabinapal opened 2 years ago
Dependent on general plural datasource support: https://github.com/hashicorp/terraform-provider-google/issues/8255
See https://github.com/hashicorp/terraform-provider-google/issues/8255 for light guidelines for plural datasource implementation.
Community Note
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_imageThis 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 thegoogle_compute_image
datasource. I could even try to submit a PR if there is interest in this feature.New or Affected Resource(s)
Potential Terraform Configuration
Another execution possibility would be returning all images by
family
, instead of the latest one:And even a
deprecated
parameter could be added so it adds up to thefilter
orfamily
paremeters.b/356688105