terraform-provider-ibm
terraform-provider-ibm copied to clipboard
create a power vs data element to reference stock catalog image by name
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 other comments that do not add relevant new information or questions, 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
Description
It is possible to use the ibmcloud cli to list the stock catalog images for powerVS:
vpc-transit/power_tf % ic pi image list-catalog
Listing images under account Powell Quiring's Account as user [email protected]...
ID Name Address
a857bbbd-6fee-4bf7-816d-04fb4cdbf65e 7100-05-09 /pcloud/v1/images/a857bbbd-6fee-4bf7-816d-04fb4cdbf65e
0f9818b7-1646-407a-80a1-b2cbf1154549 7200-05-03 /pcloud/v1/images/0f9818b7-1646-407a-80a1-b2cbf1154549
ccbaef35-c26e-40d3-8cc1-10dc34624b65 7200-05-05 /pcloud/v1/images/ccbaef35-c26e-40d3-8cc1-10dc34624b65
4cfe9575-ade0-4c69-92f9-45364b732759 7200-05-06 /pcloud/v1/images/4cfe9575-ade0-4c69-92f9-45364b732759
24083f6f-6ab7-4b59-bbd1-3ccb9e24a8db 7300-00-01 /pcloud/v1/images/24083f6f-6ab7-4b59-bbd1-3ccb9e24a8db
142d55ca-d24c-4114-a2f9-4174e96ed96e 7300-01-01 /pcloud/v1/images/142d55ca-d24c-4114-a2f9-4174e96ed96e
7d16f6ff-6137-4343-834a-0090182b18fc 7300-01-02 /pcloud/v1/images/7d16f6ff-6137-4343-834a-0090182b18fc
ecb9553c-9b7d-4a53-bf0c-0ab2c748bbc7 CentOS-Stream-8 /pcloud/v1/images/ecb9553c-9b7d-4a53-bf0c-0ab2c748bbc7
69866375-0cec-4db9-93e9-a55c63c13d6e IBMi-71-11-2924-8 /pcloud/v1/images/69866375-0cec-4db9-93e9-a55c63c13d6e
27e98290-a4f9-4a15-907c-4312b0cac9cd IBMi-71-11-2984-8 /pcloud/v1/images/27e98290-a4f9-4a15-907c-4312b0cac9cd
4adda2e3-1603-430d-9502-907b4a2d0ba7 SLES15-SP5 /pcloud/v1/images/4adda2e3-1603-430d-9502-907b4a2d0ba7
When one of these are used they need to be referenced by their id. For example:
resource "ibm_pi_image" "testacc_image" {
pi_image_name = "SLES15-SP5"
pi_cloud_instance_id = var.power.guid
#pi_image_id = "e00178e1-f763-41b7-adb0-b5da0edde4c9"
pi_image_id = "4adda2e3-1603-430d-9502-907b4a2d0ba7"
}
It would be helpful to have a data element that allowed a reference by name. Something like:
data "ibm_pi_catalog_image" "sles" {
name = "SLES15-SP5"
}
Then in the image resource:
resource "ibm_pi_image" "testacc_image" {
pi_image_name = "SLES15-SP5"
pi_cloud_instance_id = var.power.guid
pi_image_id = data.ibm_pi_catalog_image.sles.id
}
This same pattern is used in VPC images:
data "ibm_is_image" "ubuntu" {
name = "ibm-ubuntu-22-04-1-minimal-amd64-3"
}
# then the id can be referenced:
resource "foo"... {
image_id = data.ibm_is_image.ubuntu.id
}
This has a few advantages. First the names are self documenting. Also the images have different ids in each region.
### New or Affected Resource(s)
<!--- Please list the new or affected resources and data sources. --->
* ibm_pi_image
* #0000
Another workaround could be implemented using filter. First try:
data "ibm_pi_catalog_images" "image" {
filter = "name==SLES15-SP5"
pi_cloud_instance_id = var.power.guid
}
Result:
│ Error: Unsupported argument
│
│ on power_test_instances_tf/power_test_instances.tf line 9, in data "ibm_pi_catalog_images" "image":
│ 9: filter = "name==SLES15-SP5"
│
│ An argument named "filter" is not expected here.
Using filter is more complicated. All of the catalog images should have unique names. It should be straightforward for the user to pick an image by name.
The following is a work around:
data "ibm_pi_catalog_images" "my_images" {
pi_cloud_instance_id = var.power.guid
}
locals {
matching_images = [for image in data.ibm_pi_catalog_images.my_images.images : image if image.name == "SLES15-SP5"]
image_id = local.matching_images[0].image_id
}
An alternative to implementing the suggested feature is to document this in https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/pi_catalog_images
Explain that catalog image IDs are different in each region (or is it each data center). Provide an example like the one aboce. I use terraform frequently but rarely require this technique.