Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue with VirtualMachine and VirtualDisk attachment at creation and Use as secondary disk during same apply. #2303

Open
4 tasks done
asteriskie opened this issue Nov 25, 2024 · 1 comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage

Comments

@asteriskie
Copy link

asteriskie commented Nov 25, 2024

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

1.7.1

Terraform Provider

hashicorp/vsphere

VMware vSphere

8.0.3.00400

Description

Not sure if my tf version has anything to do with this but can try if it truly is related.
It would seem that the following is true:
I can create a vsphere_virtual_machine resource fine
I can create the vsphere_virtual_disk resource fine

What I cannot do is create them, then attach them in the same terraform apply.

For example, I am creating the vsphere_virtual_machine with a single boot disk and a secondary disk that is created separately from the vm....hence the vsphere_virtual_disk
Scenario 1: When I try to include that secondary disk as an attachment to the vm, when the virtual machine is initially created, it will not attach as it keeps asking about the datastore_id even though I am explicitly setting it.

Scenario 2: When I try to create the vsphere_virtual_disk and the vsphere_virtual_machine independently but do not attach the first time through, it creates all resources. From there I can re-enable the code to attach the volume in which the vm then allows the volume to be attached to the vm as intended.

Hopefully these 2 scenarios make sense. As you can imagine I would quite like for scenario 1 to work.

These are not being created presently on a clustered datastore.

I'm sorry I cannot provide full code but I followed the documentation and that code really is enough just need to attach the volume.

Affected Resources or Data Sources

resource/vsphere_virtual_disk
resource /vshpere_virtual_machine

Terraform Configuration

resource "vsphere_virtual_machine" "vm1" {
  ------------------------
  #ifI comment this out, do a terraform apply, then re-enable this code it attaches to the vm.
  disk{
    attach = true
    label = "disk1"
    path = vsphere_virtual_disk.data.vmdk_path
    datastore_id = data.vsphere_datastore.datastore.id
    disk_mode = "persistent"
    unit_number = 1
  }
  --------
}

resource "vsphere_virtual_disk" "data" {
  size               = var.persistentDisk.size
  type               = "thin"
  vmdk_path          = "/datadisks/${var.vm.vm_hostname}-${var.persistentDisk.name}.vmdk" 
  create_directories = true
  datacenter         = data.vsphere_datacenter.datacenter.name
  datastore          = data.vsphere_datastore.datastore.name
}

Debug Output

would rather not post what was requested:

│ Error: disk.1: datastore_id for disk "disk1" is required when attach is set
│ 
│   with module.vsphere-vms["hostA"].vsphere_virtual_machine.vm,
│   on .terraform/modules/vsphere-vms/vm.tf line 1, in resource "vsphere_virtual_machine" "vm":
│    1: resource "vsphere_virtual_machine" "vm" {
│ 

Panic Output

No response

Expected Behavior

Allow both the vm and the disk to be created with the disk attached on first runthrough.

Actual Behavior

Receive error about missing a datastore_id even though it's been provided.

Steps to Reproduce

Use document sample code to create a vm and disk but DO include a secondary disk as an attached disk. Do not run without as it will create a vm and disk separately fine.

Environment Details

No response

Screenshots

No response

References

No response

@asteriskie asteriskie added bug Type: Bug needs-triage Status: Issue Needs Triage labels Nov 25, 2024
Copy link

Hello, asteriskie! 🖐

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.

@asteriskie asteriskie changed the title REPLACE WITH A SHORT DESCRIPTION Issue with VirtualMachine and VirtualDisk attachment at creation and Use as secondary disk during same apply. Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Bug needs-triage Status: Issue Needs Triage
Projects
None yet
Development

No branches or pull requests

1 participant