-
Notifications
You must be signed in to change notification settings - Fork 454
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
VM Folder Placement Module - Path for type VM not valid #2030
Comments
Hello, penguinpages! 🖐 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. |
Update Posting Create new folder data "vsphere_folder" "rancher" {
path = "datacenter/vm/test_folder"
}
So this is NOT a bug with the concept of the provider but ... that it can't handle sub folders data "vsphere_folder" "rancher" {
path = "datacenter/vm/test_folder/subfolder"
} Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
module.rke-prod-sc-03.vsphere_virtual_machine.ovf_deploy: Creating...
module.rke-prod-sc-01.vsphere_virtual_machine.ovf_deploy: Creating...
module.rke-prod-sc-02.vsphere_virtual_machine.ovf_deploy: Creating...
╷
│ Error: folder '/datacenter/vm/datacenter/vm/test_folder/subfolder' not found
│
│ with module.rke-prod-sc-02.vsphere_virtual_machine.ovf_deploy,
│ on modules/ovf_deploy/main.tf line 10, in resource "vsphere_virtual_machine" "ovf_deploy":
│ 10: resource "vsphere_virtual_machine" "ovf_deploy" {` |
Here's an example of mine that shows how to do this. |
I did a review of your above code and your code data "vsphere_folder" "folder" {
path = "/${data.vsphere_datacenter.datacenter.name}/vm/${var.vsphere_folder}"
}
data "vsphere_virtual_machine" "template" {
name = var.vsphere_template
datacenter_id = data.vsphere_datacenter.datacenter.id
}
resource "vsphere_virtual_machine" "vm" {
name = var.vm_name
folder = trimprefix(data.vsphere_folder.folder.path, "/${data.vsphere_datacenter.datacenter.name}/vm")
num_cpus = var.vm_cpus Would still place VMs within default folder under datacenter. Vs many cusotmers expect VMs to be deployed within folders with subfolders to organize and create controls of permissions for developers. Ex:
etc... this is a very typical logic of how to organize and control VMs and so module needs to deploy with subdirectory logic. |
Just as a remark, the problem remains with v2.6.1 and v2.7.0 |
As a unrelated remark, would using a data exported vsphere_folder id inside the vsphere_virtual_machine be useful ? |
THe ability to place virtual machines in a nested folder can certainly be achieved in the provider by taking the base inventory path into consideration. Extending my prior example, below is an example you could run in your own environment that deploys two basic Ubuntu 24.04 LTS cloud image into seperate nested folders. terraform {
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = ">= 2.8.1"
}
}
required_version = ">= 1.8.5"
}
provider "vsphere" {
vsphere_server = "m01-vc01.rainpole.io"
user = "[email protected]"
password = "VMware1!"
allow_unverified_ssl = true
}
data "vsphere_datacenter" "datacenter" {
name = "m01-dc01"
}
data "vsphere_datastore" "datastore" {
name = "local-ssd-01"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_compute_cluster" "cluster" {
name = "m01-cl01"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_resource_pool" "pool" {
name = format("%s%s", data.vsphere_compute_cluster.cluster.name, "/Resources")
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_host" "host" {
name = "m01-esx01.rainpole.io"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_network" "network" {
name = "DHCP"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_folder" "folder-1" {
path = "/${data.vsphere_datacenter.datacenter.name}/vm/foo/bar/baz/"
}
data "vsphere_folder" "folder-2" {
path = "/${data.vsphere_datacenter.datacenter.name}/vm/hello/world/"
}
data "vsphere_ovf_vm_template" "ovf" {
name = "ubuntu-24.04-server-cloudimg-amd64"
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
remote_ovf_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
ovf_network_map = {
"VM Network" : data.vsphere_network.network.id
}
}
resource "vsphere_virtual_machine" "ubuntu-cloud-image-01" {
name = "ubuntu-01"
folder = trimprefix(data.vsphere_folder.folder-1.path, "/${data.vsphere_datacenter.datacenter.name}/vm")
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.datacenter.id
host_system_id = data.vsphere_host.host.id
num_cpus = data.vsphere_ovf_vm_template.ovf.num_cpus
num_cores_per_socket = data.vsphere_ovf_vm_template.ovf.num_cores_per_socket
memory = data.vsphere_ovf_vm_template.ovf.memory
guest_id = data.vsphere_ovf_vm_template.ovf.guest_id
dynamic "network_interface" {
for_each = data.vsphere_ovf_vm_template.ovf.ovf_network_map
content {
network_id = network_interface.value
}
}
wait_for_guest_net_timeout = 0
wait_for_guest_ip_timeout = 0
ovf_deploy {
allow_unverified_ssl_cert = true
remote_ovf_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
disk_provisioning = "thin"
ovf_network_map = data.vsphere_ovf_vm_template.ovf.ovf_network_map
}
cdrom {
client_device = true
}
vapp {
properties = {
"hostname" = "ubuntu-01"
"instance-id" = "ubuntu-01"
"password" = "VMware1!"
}
}
lifecycle {
ignore_changes = [
vapp[0].properties,
]
}
}
resource "vsphere_virtual_machine" "ubuntu-cloud-image-02" {
name = "ubuntu-02"
folder = trimprefix(data.vsphere_folder.folder-2.path, "/${data.vsphere_datacenter.datacenter.name}/vm")
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.datacenter.id
host_system_id = data.vsphere_host.host.id
num_cpus = data.vsphere_ovf_vm_template.ovf.num_cpus
num_cores_per_socket = data.vsphere_ovf_vm_template.ovf.num_cores_per_socket
memory = data.vsphere_ovf_vm_template.ovf.memory
guest_id = data.vsphere_ovf_vm_template.ovf.guest_id
dynamic "network_interface" {
for_each = data.vsphere_ovf_vm_template.ovf.ovf_network_map
content {
network_id = network_interface.value
}
}
wait_for_guest_net_timeout = 0
wait_for_guest_ip_timeout = 0
ovf_deploy {
allow_unverified_ssl_cert = true
remote_ovf_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
disk_provisioning = "thin"
ovf_network_map = data.vsphere_ovf_vm_template.ovf.ovf_network_map
}
cdrom {
client_device = true
}
vapp {
properties = {
"hostname" = "ubuntu-02"
"instance-id" = "ubuntu-02"
"password" = "VMware1!"
}
}
lifecycle {
ignore_changes = [
vapp[0].properties,
]
}
} The run: ➜ terraform apply -auto-approve
data.vsphere_datacenter.datacenter: Reading...
data.vsphere_datacenter.datacenter: Read complete after 0s [id=datacenter-3]
data.vsphere_folder.folder-1: Reading...
data.vsphere_network.network: Reading...
data.vsphere_folder.folder-2: Reading...
data.vsphere_compute_cluster.cluster: Reading...
data.vsphere_host.host: Reading...
data.vsphere_datastore.datastore: Reading...
data.vsphere_folder.folder-2: Read complete after 0s [id=group-v35005]
data.vsphere_network.network: Read complete after 0s [id=network-18085]
data.vsphere_folder.folder-1: Read complete after 0s [id=group-v35008]
data.vsphere_compute_cluster.cluster: Read complete after 0s [id=domain-c18070]
data.vsphere_datastore.datastore: Read complete after 0s [id=datastore-18076]
data.vsphere_resource_pool.pool: Reading...
data.vsphere_host.host: Read complete after 0s [id=host-18072]
data.vsphere_resource_pool.pool: Read complete after 0s [id=resgroup-18071]
data.vsphere_ovf_vm_template.ovf: Reading...
data.vsphere_ovf_vm_template.ovf: Read complete after 1s [id=ubuntu-24.04-server-cloudimg-amd64]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# vsphere_virtual_machine.ubuntu-cloud-image-01 will be created
+ resource "vsphere_virtual_machine" "ubuntu-cloud-image-01" {
+ annotation = (known after apply)
+ boot_retry_delay = 10000
+ change_version = (known after apply)
+ cpu_limit = -1
+ cpu_share_count = (known after apply)
+ cpu_share_level = "normal"
+ datacenter_id = "datacenter-3"
+ datastore_id = "datastore-18076"
+ default_ip_address = (known after apply)
+ ept_rvi_mode = "automatic"
+ extra_config_reboot_required = true
+ firmware = "bios"
+ folder = "foo/bar/baz"
+ force_power_off = true
+ guest_id = "ubuntu64Guest"
+ guest_ip_addresses = (known after apply)
+ hardware_version = (known after apply)
+ host_system_id = "host-18072"
+ hv_mode = "hvAuto"
+ id = (known after apply)
+ ide_controller_count = 2
+ imported = (known after apply)
+ latency_sensitivity = "normal"
+ memory = 1024
+ memory_limit = -1
+ memory_share_count = (known after apply)
+ memory_share_level = "normal"
+ migrate_wait_timeout = 30
+ moid = (known after apply)
+ name = "ubuntu-01"
+ num_cores_per_socket = 0
+ num_cpus = 2
+ power_state = (known after apply)
+ poweron_timeout = 300
+ reboot_required = (known after apply)
+ resource_pool_id = "resgroup-18071"
+ run_tools_scripts_after_power_on = true
+ run_tools_scripts_after_resume = true
+ run_tools_scripts_before_guest_shutdown = true
+ run_tools_scripts_before_guest_standby = true
+ sata_controller_count = 0
+ scsi_bus_sharing = "noSharing"
+ scsi_controller_count = 1
+ scsi_type = "pvscsi"
+ shutdown_wait_timeout = 3
+ storage_policy_id = (known after apply)
+ swap_placement_policy = "inherit"
+ sync_time_with_host = true
+ tools_upgrade_policy = "manual"
+ uuid = (known after apply)
+ vapp_transport = (known after apply)
+ vmware_tools_status = (known after apply)
+ vmx_path = (known after apply)
+ wait_for_guest_ip_timeout = 0
+ wait_for_guest_net_routable = true
+ wait_for_guest_net_timeout = 0
+ cdrom {
+ client_device = true
+ device_address = (known after apply)
+ key = (known after apply)
}
+ network_interface {
+ adapter_type = "vmxnet3"
+ bandwidth_limit = -1
+ bandwidth_reservation = 0
+ bandwidth_share_count = (known after apply)
+ bandwidth_share_level = "normal"
+ device_address = (known after apply)
+ key = (known after apply)
+ mac_address = (known after apply)
+ network_id = "network-18085"
}
+ ovf_deploy {
+ allow_unverified_ssl_cert = true
+ disk_provisioning = "thin"
+ enable_hidden_properties = false
+ ovf_network_map = {
+ "VM Network" = "network-18085"
}
+ remote_ovf_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
}
+ vapp {
+ properties = {
+ "hostname" = "ubuntu-01"
+ "instance-id" = "ubuntu-01"
+ "password" = "VMware1!"
}
}
}
# vsphere_virtual_machine.ubuntu-cloud-image-02 will be created
+ resource "vsphere_virtual_machine" "ubuntu-cloud-image-02" {
+ annotation = (known after apply)
+ boot_retry_delay = 10000
+ change_version = (known after apply)
+ cpu_limit = -1
+ cpu_share_count = (known after apply)
+ cpu_share_level = "normal"
+ datacenter_id = "datacenter-3"
+ datastore_id = "datastore-18076"
+ default_ip_address = (known after apply)
+ ept_rvi_mode = "automatic"
+ extra_config_reboot_required = true
+ firmware = "bios"
+ folder = "hello/world"
+ force_power_off = true
+ guest_id = "ubuntu64Guest"
+ guest_ip_addresses = (known after apply)
+ hardware_version = (known after apply)
+ host_system_id = "host-18072"
+ hv_mode = "hvAuto"
+ id = (known after apply)
+ ide_controller_count = 2
+ imported = (known after apply)
+ latency_sensitivity = "normal"
+ memory = 1024
+ memory_limit = -1
+ memory_share_count = (known after apply)
+ memory_share_level = "normal"
+ migrate_wait_timeout = 30
+ moid = (known after apply)
+ name = "ubuntu-02"
+ num_cores_per_socket = 0
+ num_cpus = 2
+ power_state = (known after apply)
+ poweron_timeout = 300
+ reboot_required = (known after apply)
+ resource_pool_id = "resgroup-18071"
+ run_tools_scripts_after_power_on = true
+ run_tools_scripts_after_resume = true
+ run_tools_scripts_before_guest_shutdown = true
+ run_tools_scripts_before_guest_standby = true
+ sata_controller_count = 0
+ scsi_bus_sharing = "noSharing"
+ scsi_controller_count = 1
+ scsi_type = "pvscsi"
+ shutdown_wait_timeout = 3
+ storage_policy_id = (known after apply)
+ swap_placement_policy = "inherit"
+ sync_time_with_host = true
+ tools_upgrade_policy = "manual"
+ uuid = (known after apply)
+ vapp_transport = (known after apply)
+ vmware_tools_status = (known after apply)
+ vmx_path = (known after apply)
+ wait_for_guest_ip_timeout = 0
+ wait_for_guest_net_routable = true
+ wait_for_guest_net_timeout = 0
+ cdrom {
+ client_device = true
+ device_address = (known after apply)
+ key = (known after apply)
}
+ network_interface {
+ adapter_type = "vmxnet3"
+ bandwidth_limit = -1
+ bandwidth_reservation = 0
+ bandwidth_share_count = (known after apply)
+ bandwidth_share_level = "normal"
+ device_address = (known after apply)
+ key = (known after apply)
+ mac_address = (known after apply)
+ network_id = "network-18085"
}
+ ovf_deploy {
+ allow_unverified_ssl_cert = true
+ disk_provisioning = "thin"
+ enable_hidden_properties = false
+ ovf_network_map = {
+ "VM Network" = "network-18085"
}
+ remote_ovf_url = "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.ova"
}
+ vapp {
+ properties = {
+ "hostname" = "ubuntu-02"
+ "instance-id" = "ubuntu-02"
+ "password" = "VMware1!"
}
}
}
Plan: 2 to add, 0 to change, 0 to destroy.
vsphere_virtual_machine.ubuntu-cloud-image-02: Creating...
vsphere_virtual_machine.ubuntu-cloud-image-01: Creating...
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [40s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [40s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [50s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [50s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m0s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m0s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m40s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m40s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [1m50s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [1m50s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m0s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [2m0s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [2m10s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [2m20s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Still creating... [2m30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m30s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-02: Creation complete after 2m38s [id=421e6109-bfeb-fb11-d5a0-0ee854f7b91d]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m40s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Still creating... [2m50s elapsed]
vsphere_virtual_machine.ubuntu-cloud-image-01: Creation complete after 2m58s [id=421ec242-1f61-c343-6826-5aa6244e4393]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed. The results: {
"mode": "data",
"type": "vsphere_folder",
"name": "folder-1",
"provider": "provider[\"registry.terraform.io/hashicorp/vsphere\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "group-v35008",
"path": "/m01-dc01/vm/foo/bar/baz/"
},
"sensitive_attributes": []
}
]
},
{
"mode": "data",
"type": "vsphere_folder",
"name": "folder-2",
"provider": "provider[\"registry.terraform.io/hashicorp/vsphere\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "group-v35005",
"path": "/m01-dc01/vm/hello/world/"
},
"sensitive_attributes": []
}
]
}, |
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. |
Community Guidelines
Terraform
1.5.7
Terraform Provider
2.0.2
VMware vSphere
8.0
Description
main.tf
Defined Use of Folder Type VM path:
Call for vm deploy
Per instructions the PATH for folder should be
datacenter/<vm>
ordatacenter etc..>/folder/subfolder
.Affected Resources or Data Sources
Deploy of VMs within folder path. This is important to customer who will not authorize deployment service accounts that have VM create at top level in vcenter. Workaround is to allow all datacenter but this is a stop deploy for them to move to production
Terraform Configuration
Debug Output
Panic Output
Expected Behavior
Deploy vm in vcenter folder
<datacenter>/vm/demos/suse/rancher
.Actual Behavior
Error not able to find path.
Steps to Reproduce
I can get vm deploy to complete if I remark out folder module and vm placement TF call.
Environment Details
I also tried with removal of
datacenter/vm
and it gave different result.I can post as followup.
Screenshots
No response
References
No response
The text was updated successfully, but these errors were encountered: