terraform-provider-vsphere
terraform-provider-vsphere copied to clipboard
Allow datastore_cluster for content library clones with `vm_templates`
Community Guidelines
- [X] I have read and agree to the HashiCorp Community Guidelines .
- [X] Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
- [X] Do not leave "+1" or other comments that do not add relevant information or questions.
- [X] If you are interested in working on this issue or have submitted a pull request, please leave a comment.
Terraform
OpenTofu v1.8.2
Terraform Provider
v2.9.2
VMware vSphere
ESXI 7.0 U2
Description
Referencing from this https://knowledge.broadcom.com/external/article/312205/vm-template-cannot-be-deployed-to-datast.html and PR that seemed to fix this issue
I see this was tested with ovf template i am using VM templates
Affected Resources or Data Sources
resource/vsphere_virtual_machine
Terraform Configuration
resource "vsphere_virtual_machine"
resource "vsphere_virtual_machine" "vm" {
name = length(var.ip-addresses) > 1 ? "${var.name}-${count.index + 1}" : var.name
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id
host_system_id = data.vsphere_host.host.id
sata_controller_count = 1
scsi_controller_count = 1
count = length(var.ip-addresses) > 0 ? length(var.ip-addresses) : 1
# only if you DO NOT want to wait for an IP address
wait_for_guest_net_routable = false
num_cpus = var.num_cpus
memory = var.memory
guest_id = "ubuntu64Guest"
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "disk0"
size = var.disk_size
unit_number = 0
thin_provisioned = false
}
clone {
template_uuid = data.vsphere_content_library_item.item.id
customize {
linux_options {
host_name = "${count.index}" > 1 ? "${var.name}-${count.index}" : var.name
domain = "${count.index}" > 1 ? "${var.name}-${count.index}" : var.name
}
network_interface {
ipv4_address = length(var.ip-addresses) > 0 ? element(var.ip-addresses, count.index) : var.ip-address
ipv4_netmask = 24
}
ipv4_gateway = "10.10.10.1"
}
}
}
Data file
data "vsphere_datacenter" "dc" {
name = var.datacenter_name
}
data "vsphere_datastore_cluster" "datastore_cluster" {
name = var.datastore_cluster
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_content_library" "library" {
name = "HQ-UAT"
}
data "vsphere_content_library_item" "item" {
name = "ubuntu-20-v1-dev-2024-09-25"
type = "vm-template"
library_id = data.vsphere_content_library.library.id
}
Debug Output
None
Panic Output
No response
Expected Behavior
Creating vm with datastore cluster
Actual Behavior
I got this error
╷
│ Error: 400 Bad Request: {"type":"com.vmware.vapi.std.errors.invalid_argument","value":{"error_type":"INVALID_ARGUMENT","messages":[{"args":["group-p105:2e683356-6528-4429-b53e-78ab46e2136b"],"default_message":"The provided datastore ID group-p105:2e683356-6528-4429-b53e-78ab46e2136b is invalid.","id":"com.vmware.vdcs.vmtx-main.invalid_datastore_id_format"}]}}
│
│ with module.virtual_machine.vsphere_virtual_machine.vm[1],
│ on modules/virtual-machine/vm_machine.tf line 2, in resource "vsphere_virtual_machine" "vm":
│ 2: resource "vsphere_virtual_machine" "vm" {
╵
Steps to Reproduce
Storing vm template to content library from using packer and with this configuration which getting the datastore cluster data has been validated but while creating the vm i am getting this error.
Environment Details
No response
Screenshots
No response
References
https://github.com/hashicorp/terraform-provider-vsphere/pull/2061