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

Content Library support? #50

Open
brtduvally opened this issue Oct 21, 2020 · 7 comments
Open

Content Library support? #50

brtduvally opened this issue Oct 21, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@brtduvally
Copy link

Hi All,

I've been using this for a while and it's great, and now we're looking to move our templates into a content library. Does this support content libraries? I couldn't find any reference to it in the code.

@Arman-Keyoumarsi Arman-Keyoumarsi added the enhancement New feature or request label Oct 26, 2020
@Arman-Keyoumarsi
Copy link
Member

No It doesn't, I am looking to add it in feature release

@Arman-Keyoumarsi
Copy link
Member

Please do a PR with Content library. we will review and approve it. It is a welcome feature.

Thanks 👍

@rdbartram
Copy link

FYI i've added this in #73

@willdafoe
Copy link

FYI i've added this in #73

I'm testing a new build using the content library support, however, I'm getting the following error when running terraform plan:

terraform plan ╷ │ Error: Attempt to index null value │ │ on .terraform/modules/vm/main.tf line 161, in resource "vsphere_virtual_machine" "vm": │ 161: size = var.disk_size_gb[template_disks.key] │ ├──────────────── │ │ template_disks.key is 0 │ │ var.disk_size_gb is null │ │ This value is null, so it does not have any indices.

Is there an updated example that shows the correct usage of the content_library option?

@Zwordi
Copy link

Zwordi commented Feb 21, 2022

Hi @ralphbrynard ,

Just hit the same issue than you did.
Got it around with the following modification within the modules but it’s working on my side/case maybe not on yours:

diff --git a/main.tf b/main.tf
index e813f78..f060e65 100644
--- a/main.tf
+++ b/main.tf
@@ -158,7 +158,8 @@ resource "vsphere_virtual_machine" "vm" {
     iterator = template_disks
     content {
       label             = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
-      size              = var.disk_size_gb[template_disks.key]
+      #size              = var.disk_size_gb[template_disks.key]
+      size              = var.disk_size_gb
       unit_number       = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
       // thin_provisioned  = data.vsphere_virtual_machine.template[0].disks[template_disks.key].thin_provisioned
       // eagerly_scrub     = data.vsphere_virtual_machine.template[0].disks[template_disks.key].eagerly_scrub
 variable "disk_size_gb" {
   description = "List of disk sizes to override template disk size."
-  type        = list(any)
-  default     = null
+  #type        = list(any)
+  type = string
+  default     = ""
 }

And i added the variables within my module block definition as:

disk_size_gb = 81

I got the VM created after that.

Hope it will help.

#workaround

@willdafoe
Copy link

willdafoe commented Feb 23, 2022

Hi @ralphbrynard ,

Just hit the same issue than you did. Got it around with the following modification within the modules but it’s working on my side/case maybe not on yours:

diff --git a/main.tf b/main.tf
index e813f78..f060e65 100644
--- a/main.tf
+++ b/main.tf
@@ -158,7 +158,8 @@ resource "vsphere_virtual_machine" "vm" {
     iterator = template_disks
     content {
       label             = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
-      size              = var.disk_size_gb[template_disks.key]
+      #size              = var.disk_size_gb[template_disks.key]
+      size              = var.disk_size_gb
       unit_number       = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
       // thin_provisioned  = data.vsphere_virtual_machine.template[0].disks[template_disks.key].thin_provisioned
       // eagerly_scrub     = data.vsphere_virtual_machine.template[0].disks[template_disks.key].eagerly_scrub
 variable "disk_size_gb" {
   description = "List of disk sizes to override template disk size."
-  type        = list(any)
-  default     = null
+  #type        = list(any)
+  type = string
+  default     = ""
 }

And i added the variables within my module block definition as:

disk_size_gb = 81

I got the VM created after that.

Hope it will help.

#workaround

Hi @Zwordi,

Tested this myself and this works. I'd suggest submitting a PR with this change as it's fairly minor. I'm also happy to submit and can include examples as well if needed.

@rachid2222
Copy link

rachid2222 commented Oct 17, 2023

Hello,

ultimately, I didn't need any changes to create a VM from a content library

an example:

module "vm" {
for_each = local.vms
vmname = each.key
...
content_library = "NameOfYourContentLibrary"
vmtemp = "TemplateName"
disk_size_gb = try(each.value.disk_size_gb, [24])
...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants