IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
339 stars 663 forks source link

regression: Unable to create power instance using catalog image #4679

Closed clnperez closed 1 year ago

clnperez commented 1 year ago

Community Note

Terraform CLI and Terraform IBM Provider Version

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.


locals {
  centos_img_storaget_lon04 = tolist([for obj in data.ibm_pi_catalog_images.catalog_lon04.images: obj.storage_type if strcontains("CentOS-Stream-8", obj.name)])[0] 
  centos_img_id_lon04 = tolist([for obj in data.ibm_pi_catalog_images.catalog_lon04.images: obj.image_id if strcontains("CentOS-Stream-8", obj.name)])[0]
}

resource "ibm_pi_instance" "centos_instances_lon04" {
  provider             = ibm.powervslon04
  count                = 1
  pi_memory            = "8" 
  pi_processors        = "0.5"
  pi_instance_name     = "rdr-cln-centos-lon04"
  pi_proc_type         = "shared"
  pi_image_id          = local.centos_img_id_lon04
  pi_storage_type      = local.centos_img_storaget_lon04
  pi_network           { network_id = ibm_pi_dhcp.dhcp_lon04.id}
  pi_key_pair_name     = data.ibm_pi_key.key_lon04.id
  pi_sys_type          = "s922"
  pi_cloud_instance_id = var.cloud_inst_id_lon04
  pi_health_status     = "WARNING"
}

Debug Output

https://gist.github.com/clnperez/5ef202b04ad45a79d220c716c95e74c8

Panic Output

n/a

Expected Behavior

the instance should have created successfully. i have been able to use the catalog images with terraform in the past

Actual Behavior

it seems to be only looking for images in the service instance to verify, and fails because it can't find it there

Steps to Reproduce

  1. terraform apply

Important Factoids

References

michaelkad commented 1 year ago

Hi @clnperez,

the instance should have created successfully. i have been able to use the catalog images with terraform in the past

One more step you need to include is to add that stock image into your account first, and then run your terraform. Since the stock images is not under your account.

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pi_image

clnperez commented 1 year ago

i don't see how i would add the stock image to my account using that pi_image resource. they're not in buckets. i did look at that but it doesn't seem to be possible with terraform.

the UI, it seems, copies the stock image over under the covers when provisioning from a stock image.

clnperez commented 1 year ago

actually -- it looks like i'd use the first example?

resource "ibm_pi_image" "testacc_image  "{
  pi_image_name       = "7200-03-02"
  pi_image_id         = <"image id obtained from the datasource">
  pi_cloud_instance_id = "<value of the cloud_instance_id>"
}
clnperez commented 1 year ago

If so -- can we update the TF doc to make this obvious since the UI behaves differently?

clnperez commented 1 year ago

Oh man. I'm now hitting another annoying error that I know is related to a "working as designed" issue, but partly needs to be made better. I deleted the boot image that the UI made, which was called the same thing as the name in the catalog (CentOS-Stream-8). IIRC, the name locally will just be the name of what it was in the catalog, and you can't change it. So now, since you can't re-create an image with the same name as an old one without waiting some amount of time, I can't test the new TF:

2023-07-12T16:40:46.223-0700 [ERROR] provider.terraform-provider-ibm_v1.49.0: Response contains error diagnostic: diagnostic_severity=ERROR tf_proto_version=5.3 @caller=github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_detail= diagnostic_summary="failed to perform Create Image Operation for cloud instance b4a9a365-9545-4c95-bf5c-d2f2132d4f87 with error  [POST /pcloud/v1/cloud-instances/{cloud_instance_id}/images][400] pcloudCloudinstancesImagesPostBadRequest  &{Code:0 Description:for cloud instance fbd37fc3a30c494c88f9258ff5571cc5, an image with the name CentOS-Stream-8 already exists or may have been recently deleted.  Please wait or reattempt with a unique name Error:bad request Message:}" tf_provider_addr=provider tf_req_id=c26c9a0d-a87c-6e7b-0b09-0ad82225d432 tf_resource_type=ibm_pi_image tf_rpc=ApplyResourceChange @module=sdk.proto timestamp=2023-07-12T16:40:46.223-0700
2023-07-12T16:40:46.244-0700 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2023-07-12T16:40:46.244-0700 [ERROR] vertex "ibm_pi_image.image_centos8stream_lon06" error: failed to perform Create Image Operation for cloud instance b4a9a365-9545-4c95-bf5c-d2f2132d4f87 with error  [POST /pcloud/v1/cloud-instances/{cloud_instance_id}/images][400] pcloudCloudinstancesImagesPostBadRequest  &{Code:0 Description:for cloud instance fbd37fc3a30c494c88f9258ff5571cc5, an image with the name CentOS-Stream-8 already exists or may have been recently deleted.  Please wait or reattempt with a unique name Error:bad request Message:}
β•·
β”‚ Error: failed to perform Create Image Operation for cloud instance b4a9a365-9545-4c95-bf5c-d2f2132d4f87 with error  [POST /pcloud/v1/cloud-instances/{cloud_instance_id}/images][400] pcloudCloudinstancesImagesPostBadRequest  &{Code:0 Description:for cloud instance fbd37fc3a30c494c88f9258ff5571cc5, an image with the name CentOS-Stream-8 already exists or may have been recently deleted.  Please wait or reattempt with a unique name Error:bad request Message:}
β”‚ 
β”‚   with ibm_pi_image.image_centos8stream_lon06,
β”‚   on main.tf line 38, in resource "ibm_pi_image" "image_centos8stream_lon06":
β”‚   38: resource "ibm_pi_image" "image_centos8stream_lon06" {
β”‚ 
β•΅
β•·
β”‚ Error: failed to provision: failed to Create PVM Instance :[POST /pcloud/v1/cloud-instances/{cloud_instance_id}/pvm-instances][400] pcloudPvminstancesPostBadRequest  &{Code:0 Description:error getting deployment image information: unable to get image f1626ad4-288a-4fc2-ade2-404c387a4fe7/a25cf2e3-6d80-485d-9f8c-2f788caa4c73: Resource not found f1626ad4-288a-4fc2-ade2-404c387a4fe7/a25cf2e3-6d80-485d-9f8c-2f788caa4c73 Error:bad request Message:}
β”‚ 
β”‚   with ibm_pi_instance.centos_instances_lon04[0],
β”‚   on main.tf line 100, in resource "ibm_pi_instance" "centos_instances_lon04":
β”‚  100: resource "ibm_pi_instance" "centos_instances_lon04" {

I tried renaming it:

resource "ibm_pi_image" "image_centos8stream_lon04" {
  provider             = ibm.powervslon04
  pi_image_name        = "CentOS-Stream"
  pi_image_id          = local.centos_img_id_lon04
  pi_cloud_instance_id = var.cloud_inst_id_lon04
}

but that name seems to be ignored. It's still trying to name it "CentOS-Stream-8", and I keep getting that error.

The only real "bug" here I think is that the name shouldn't be a required parameter since it's ignored in the stock image case.

michaelkad commented 1 year ago

i don't see how i would add the stock image to my account using that pi_image resource. they're not in buckets. i did look at that but it doesn't seem to be possible with terraform.

the UI, it seems, copies the stock image over under the covers when provisioning from a stock image.

Yes, the UI does the copy under cover for stock images.

actually -- it looks like i'd use the first example?

resource "ibm_pi_image" "testacc_image "{ pi_image_name = "7200-03-02" pi_image_id = <"image id obtained from the datasource"> pi_cloud_instance_id = "" }

Yes, this how would copy a stock image. Or you can use the cli ibmcloud pi image-create <stock-image-id>

If so -- can we update the TF doc to make this obvious since the UI behaves differently?

I will have the doc update in the todo list

but that name seems to be ignored. It's still trying to name it "CentOS-Stream-8", and I keep getting that error. The only real "bug" here I think is that the name shouldn't be a required parameter since it's ignored in the stock image case.

ibm_pi_image does two thing: stock image copy or COS image import, hence the name is a required value but stock image name can’t be changed. I know it is working as design. I will update the documentation to make it clearer.

prb112 commented 1 year ago

Just hit this one too... thanks for the issue - I've upvoted