hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
623 stars 453 forks source link

Changes in `vsphere_file destination_file` does not work as expected #1810

Open pavel-khritonenko opened 1 year ago

pavel-khritonenko commented 1 year ago

Community Guidelines

Terraform

v1.3.3

Terraform Provider

v2.1.1

VMware vSphere

v7.0.3

Description

I generate a value of argument vsphere_file.destination_file based on the content of file I'm going to upload (md5-hash, actually), so when the content of the file has changed the new filename generated. And in that case subsequent terraform apply fails with "file not found".

According to the code, id of that resource calculated only once on file upload, based on destination_file argument and not going to be changed despite destination_file changed.

Would recommend to change that id (not sure if it's possible and for me it ever sounds weird), or force new resource if that field has changed.

Affected Resources or Data Sources

resource/vsphere_file

Terraform Configuration


resource "null_resource" "nocloud_seed" {
  triggers = {
    always = timestamp()
  }

  provisioner "local-exec" {
    command     = "genisoimage -output seed.iso -volid cidata -joliet -rock meta-data user-data network-config"
    working_dir = "${path.module}/machine"
  }
}

data "local_file" "nocloud_seed" {
  depends_on = [
    null_resource.nocloud_seed
  ]

  filename = "${path.module}/machine/seed.iso"
}

resource "vsphere_file" "nocloud_seed" {
  datastore        = "dev"
  datacenter       = "dc"
  destination_file = "cloud-init/seed-${md5(data.local_file.nocloud_seed.content_base64)}.iso"
  source_file      = data.local_file.nocloud_seed.filename
}

Debug Output

Not sure if it'd help

Panic Output

No response

Expected Behavior

Would expect file name and content changed in the remote datastore

Actual Behavior

On a subsequent apply, when file's hash changed:

ā”‚ Error: Unable to access file [dev] cloud-init/seed-2f72c51eac9227a09900745a16545c23.iso
ā”‚ 
ā”‚   with vsphere_file.nocloud_seed,
ā”‚   on main.tf line 126, in resource "vsphere_file" "nocloud_seed":
ā”‚  126: resource "vsphere_file" "nocloud_seed" {

Steps to Reproduce

Apply terraform configuration, change the content of the file, apply terraform configuration

Environment Details

No response

Screenshots

No response

References

No response

github-actions[bot] commented 1 year ago

Hello, pavel-khritonenko! šŸ–

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

pavel-khritonenko commented 1 year ago

Just few cents - in my case I found an workaround - I saved a file locally with hash in name too so it forced resource been destroyed and created.