Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

r/vsphere_file causes crash with incorrect configuration #1779

Closed
4 tasks done
springer268 opened this issue Oct 25, 2022 · 6 comments · Fixed by #1866
Closed
4 tasks done

r/vsphere_file causes crash with incorrect configuration #1779

springer268 opened this issue Oct 25, 2022 · 6 comments · Fixed by #1866
Labels
area/storage Area: Storage bug Type: Bug enhancement Type: Enhancement
Milestone

Comments

@springer268
Copy link

springer268 commented Oct 25, 2022

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

v1.3.3

Terraform Provider

v2.2.0

VMware vSphere

7.0.2.00500

Description

I am trying to use vsphere_file to upload a file to a datastore. This causes a crash in the plugin

Affected Resources or Data Sources

r/vsphere_file

Terraform Configuration

provider "vsphere" {
  allow_unverified_ssl = true
  vsphere_server       = var.server
  user                 = var.user
  password             = var.password
}

resource "vsphere_file" "ubuntu_vmdk_upload2" {
  datacenter         = "dc"
  datastore          = "ds1"
  source_file        = "/Users/springern/Documents/hi.txt"
  destination_file   = "hi.txt"
  create_directories = true
}

Debug Output

https://gist.github.com/springer268/3ac854675994b18aa2922c042791c8dc

Panic Output

https://gist.github.com/springer268/3ac854675994b18aa2922c042791c8dc

(i dont see a crash.log)

Expected Behavior

The file to upload to the specified datastore

Actual Behavior

the file is not uploaded to the datastore and crashes the program

Steps to Reproduce

  1. Have vsphere, terraform, and provider with matching versions
  2. Attempt to upload file to datastore with configuration as shown before
  3. See output

Environment Details

This error also occurs on a different vCenter.

The datastore is VMFS

Screenshots

No response

References

No response

@springer268 springer268 added bug Type: Bug needs-triage Status: Issue Needs Triage labels Oct 25, 2022
@github-actions github-actions bot removed the bug Type: Bug label Oct 25, 2022
@github-actions
Copy link

Hello, springer268! 🖐

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.

@tenthirtyam tenthirtyam added bug Type: Bug crash Impact: Crash labels Oct 26, 2022
@tenthirtyam tenthirtyam changed the title vsphere_file causes plugin crash r/vsphere_file causes plugin crash Oct 26, 2022
@tenthirtyam
Copy link
Collaborator

tenthirtyam commented Oct 26, 2022

At first glance the example seems incorrect as it's set to create directories, but none are required as no directory path is provided.

resource "vsphere_file" "ubuntu_vmdk_upload2" {
  datacenter         = "dc"
  datastore          = "ds1"
  source_file        = "/Users/springern/Documents/hi.txt"
  destination_file   = "hi.txt"
  create_directories = true
}

Try:

resource "vsphere_file" "ubuntu_vmdk_upload2" {
  datacenter         = "dc"
  datastore          = "ds1"
  source_file        = "/Users/springern/Documents/hi.txt"
  destination_file   = "path/to/file/hi.txt"
  create_directories = true
}

or if in the datastore root:

resource "vsphere_file" "ubuntu_vmdk_upload2" {
  datacenter         = "dc"
  datastore          = "ds1"
  source_file        = "/Users/springern/Documents/hi.txt"
  destination_file   = "hi.txt"
  create_directories = false
}

@springer268
Copy link
Author

Yes, this worked. I guess an error message should be added when this occurs, instead of a crash. Thanks.

@tenthirtyam tenthirtyam added enhancement Type: Enhancement and removed bug Type: Bug crash Impact: Crash needs-triage Status: Issue Needs Triage labels Oct 26, 2022
@tenthirtyam tenthirtyam changed the title r/vsphere_file causes plugin crash r/vsphere_file causes crash if Oct 26, 2022
@tenthirtyam tenthirtyam changed the title r/vsphere_file causes crash if r/vsphere_file causes crash with incorrect configuration Oct 26, 2022
@tenthirtyam tenthirtyam added the bug Type: Bug label Oct 26, 2022
@tenthirtyam
Copy link
Collaborator

tenthirtyam commented Oct 26, 2022

I've updated the issue to track this item for an enhancement to misconfiguration error handling.

@tenthirtyam tenthirtyam added this to the Backlog milestone Oct 26, 2022
@tenthirtyam tenthirtyam added the area/storage Area: Storage label Nov 13, 2022
stoyan-hristov added a commit to stoyan-hristov/terraform-provider-vsphere that referenced this issue Mar 24, 2023
…rp#1779

Update resource_vsphere_file.createDirectory method to check whether the provided file path has any parent folder(s). If there are no folders to be created we return early without invoking FileManager.MakeDirectory. This fixes the “slice bounds out of range” runtime error which was crashing the provider.

Fix the resource_vsphere_file_test acceptance tests as they were failing due to incorrect test vmdk files. Also, adding new TestAccResourceVSphereFile_uploadWithCreateDirectories test to cover the r/vsphere_file.create_directories configuration field.
appilon pushed a commit that referenced this issue Apr 21, 2023
Update resource_vsphere_file.createDirectory method to check whether the provided file path has any parent folder(s). If there are no folders to be created we return early without invoking FileManager.MakeDirectory. This fixes the “slice bounds out of range” runtime error which was crashing the provider.

Fix the resource_vsphere_file_test acceptance tests as they were failing due to incorrect test vmdk files. Also, adding new TestAccResourceVSphereFile_uploadWithCreateDirectories test to cover the r/vsphere_file.create_directories configuration field.
@tenthirtyam tenthirtyam modified the milestones: Backlog, v2.4.0 May 4, 2023
@github-actions
Copy link

github-actions bot commented May 5, 2023

This functionality has been released in v2.4.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area/storage Area: Storage bug Type: Bug enhancement Type: Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants