terraform-provider-vsphere: Unable to upload the vmdk file when the destination folder doesnt exist

Community Guidelines

  • I have read and agree to the HashiCorp Community Guidelines .
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave “+1” or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Terraform

0.13.3

Terraform Provider

v2.0.2

VMware ESXi

v7.0.2

Description

I have used the source code of version v2.0.2 terraform vmware provider and built a plugin and used that plugin to perform instantiation . I have not done any modification . I found that I am unable to upload the vmdk when the destination directory is not present . But I am able to upload the iso .

Affected Resources

resource/vsphere_file

Terraform Configuration

resource "vsphere_file" "upload" {

  datacenter = data.vsphere_datacenter.datacenter.id
  datastore  = var.vsphere_datastore_name

  source_file        = "/home/kishan/file.vmdk"
  destination_file   = "source_files/file.vmdk"
}

Debug Output

vsphere_file.upload["vmdk1"]: Still creating... [10s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [20s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [30s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [40s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [50s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m0s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m10s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m20s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m30s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m40s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [1m50s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m0s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m10s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m20s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m30s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m40s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [2m50s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [3m0s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [3m10s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [3m20s elapsed]
vsphere_file.upload["vmdk1"]: Still creating... [3m30s elapsed]
vsphere_file.upload["vmdk1"]: Creation complete after 3m36s [id=[datastore1] ha-datacenter/source_files/file.vmdk]

vsphere_file.upload["vmdk1"]: Still creating... [4m40s elapsed]

Error: error File /vmfs/volumes/5ff5a927-3c8bedec-1ea5-e4434b298064/tfm-temp-457776264/file.vmdk was not found

Panic Output

Expected Behavior

File should be uploaded properly

Actual Behavior

Throws error

Steps to Reproduce

No response

Environment Details

No response

Screenshots

No response

References

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 50

Most upvoted comments

Enhancement issue https://github.com/hashicorp/terraform-provider-vsphere/issues/1623 has been submitted for community reactions.

I can confirm that I can recreate the issue when using a direct ESXi host connection - this was an important detail left out of the issue description.

I can also confirm that when using a direct ESXi host connection that the datacenter id is required since the name would not be resolvable if Terraform nor the host are connected to a vCenter Server instance.

I’ll take a look at the proposed fix but will need to determine if this is something the provider team wishes to address.

Ryan Johnson Staff II Solutions Architect | VMware, Inc.

I’m attaching a demo video with v2.1.1 using your example configuration with slight modification.

Here are the plan files: gh-1587_plan.zip

And here is a demo that shows the use of the same plan.

https://user-images.githubusercontent.com/7771363/158466475-fae0e2fd-b393-4463-8eb6-44ba02e177d4.mp4

  • Notice that at the time the first terraform apply is run it creates the directories (source_files) if needed and it is successful.
  • The terraform destroy removes the files but leaves the source_files directory, as expected.
  • So, on the next terraform apply, the .vmdks are uploaded to the existing directory without issue nor an error stating that folder already exists, even with create_directories flagged as true.

Notice that I am using datacenter = data.vsphere_datacenter.datacenter.name in the resource to target the name of the datacenter.

Ryan

Hi , we doesnt want to use the create_directories option , since create_directories option will throw the error if the destination directory is already existing