Cloud-Temple / terraform-provider-cloudtemple

Cloud Temple CSP Terraform Provider
https://cloud-temple.com
Mozilla Public License 2.0
8 stars 1 forks source link

Issue with terraform import for controller ressources #97

Closed JoshDelPaso closed 10 months ago

JoshDelPaso commented 11 months ago

Hello,

When I import a controller, I have an issue at the next "terraform apply" I will explain each step of my deployment to reproduce this issue.

resource "cloudtemple_compute_virtual_machine" "VM-TEST2" { name = "VM-TEST2"

memory = 4 1024 1024 * 1024 cpu = 4 num_cores_per_socket = 2 cpu_hot_add_enabled = false cpu_hot_remove_enabled = false memory_hot_add_enabled = false

datacenter_id = data.cloudtemple_compute_virtual_datacenter.DC-PAR7S.id host_cluster_id = data.cloudtemple_compute_host_cluster.clu001-prod1.id host_id = data.cloudtemple_compute_host.esx001.id datastore_id = data.cloudtemple_compute_datastore.live_prod_04.id

boot_options { efi_secure_boot_enabled = true firmware = "efi" } os_disk { capacity = 70 1024 1024 * 1024 } os_network_adapter { network_id = data.cloudtemple_compute_network.vlan-ADMIN-PA7S.id }

content_library_id = data.cloudtemple_compute_content_library.pa7s.id content_library_item_id = data.cloudtemple_compute_content_library_item.w2016cloudinit.id

power_state = "off"

tags = local.common_tags

backup_sla_policies = [ data.cloudtemple_backup_sla_policy.nobackup.id, ]

lifecycle { prevent_destroy = false

ignore_changes = [ power_state ]

} }

####### My controllers & Disks

resource "cloudtemple_compute_virtual_controller" "VM-TEST2-SCSI1" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id type = "SCSI" sub_type = "ParaVirtual" }

resource "cloudtemple_compute_virtual_controller" "VM-TEST2-SCSI2" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id type = "SCSI" sub_type = "ParaVirtual" }

resource "cloudtemple_compute_virtual_controller" "VM-TEST2-SCSI3" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id type = "SCSI" sub_type = "ParaVirtual" }

resource "cloudtemple_compute_virtual_disk" "VM-TEST2-dd3-live" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id provisioning_type = "staticImmediate" disk_mode = "persistent" capacity = 4 1024 1024 * 1024 datastore_id = data.cloudtemple_compute_datastore.live_prod_04.id controller_id = cloudtemple_compute_virtual_controller.VM-TEST2-SCSI1.id

backup_sla_policies = [ data.cloudtemple_backup_sla_policy.nobackup.id, ] depends_on = [ cloudtemple_compute_virtual_controller.VM-TEST2-SCSI1 ] }

resource "cloudtemple_compute_virtual_disk" "VM-TEST2-dd4-live" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id provisioning_type = "staticImmediate" disk_mode = "persistent" capacity = 5 1024 1024 * 1024 datastore_id = data.cloudtemple_compute_datastore.live_prod_04.id controller_id = cloudtemple_compute_virtual_controller.VM-TEST2-SCSI2.id

backup_sla_policies = [ data.cloudtemple_backup_sla_policy.nobackup.id, ] depends_on = [ cloudtemple_compute_virtual_controller.VM-TEST2-SCSI2 ] }

####### DATA to get my ressource id

data "cloudtemple_compute_virtual_controllers" "allmycontrollers" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id }

data "cloudtemple_compute_virtual_disks" "allmydisks" { virtual_machine_id = cloudtemple_compute_virtual_machine.VM-TEST2.id }


I applied this deployment with success.
<img width="313" alt="Screenshot 2023-11-09 081951" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/a93b675d-9f71-4c2f-82be-ddf72ca1ed44">

- After, I added a controller on Shiva GUI

<img width="309" alt="Screenshot 2023-11-09 082122" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/cf6508e3-6b28-43e9-8c80-ac7e1cbdf6bb">

This new controller was the third one : 
<img width="525" alt="Screenshot 2023-11-09 082134" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/b9c138b2-f97d-4fab-b079-52f2e8de977d">

- Next, I did a new terraform apply to get my id for my new controller.
<img width="611" alt="Screenshot 2023-11-09 082245" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/60d3d8e1-dda8-48ac-9b78-f43c31070d98">

Nothing changed, but i could get my id  : 

`terraform state show data.cloudtemple_compute_virtual_controllers.allmycontrollers`
The id was : 911ae854-db56-4416-9126-411d4ff3ac2c

<img width="358" alt="Screenshot 2023-11-09 082341" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/9575fce3-69b2-4023-83f4-f2b1f7245112">

- Then, I wanted to import my new controller for that :
I added in my TF file :
<img width="343" alt="Screenshot 2023-11-09 082527" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/5dfd09c3-04fd-462a-8c48-d063f663dd98">

And I typed the command : 
`terraform import cloudtemple_compute_virtual_controller.VM-TEST2-SCSI3 911ae854-db56-4416-9126-411d4ff3ac2c`

The import was a success:
<img width="586" alt="Screenshot 2023-11-09 082644" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/4a03f0d8-f1c6-43ba-a270-8fdf6e52532d">

- Finally, here came the issue, my next apply wanted to destroy and recreate the controller as you can see below :
<img width="710" alt="Screenshot 2023-11-09 082740" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/091e1aac-3604-416e-9353-d24ce58a34ac">

I didn't apply the change, and i rechecked the state, it was exactly the same id.

I tried to apply the change. 
<img width="719" alt="Screenshot 2023-11-09 083014" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/473a15cd-6e58-4c5e-bdd4-6e3a742c2f1d">
The effect was the ID stayed the same:
<img width="442" alt="Screenshot 2023-11-09 083034" src="https://github.com/Cloud-Temple/terraform-provider-cloudtemple/assets/54177066/939156f9-8e2d-43b2-b2bd-224b106d7107">

But if a disk is attached to this controller, the disk is destroyed&recreated too.

Thanks,

Cheers,
pbesret commented 10 months ago

Hello, thank you for such a good issue. I'm working on it at this moment and will let you know as soon as this is fixed.

Best regards,