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

How to compute template values from content library item #1012

Closed
Satak opened this issue Mar 28, 2020 · 2 comments
Closed

How to compute template values from content library item #1012

Satak opened this issue Mar 28, 2020 · 2 comments

Comments

@Satak
Copy link

Satak commented Mar 28, 2020

Terraform Version

v0.12.24

vSphere Provider Version

v1.17.0

Affected Resource(s)

  • vsphere_virtual_machine
  • vsphere_content_library_item

Terraform Configuration Files

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

data "vsphere_datacenter" "dc" {
  name = "dc1"
}

data "vsphere_datastore" "datastore" {
  name          = "datastore1"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_resource_pool" "pool" {
  name          = "cluster1/Resources"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_network" "network" {
  name          = "public"
  datacenter_id = data.vsphere_datacenter.dc.id
}

data "vsphere_content_library" "library" {
  name = "img-library"
}

data "vsphere_content_library_item" "item" {
  name       = "windows-2019-in-content-library"
  library_id = data.vsphere_content_library.library.id
}

// can you compute template object from content library item?
data "vsphere_virtual_machine" "template" {
  name          = "windows-2019"
  datacenter_id = data.vsphere_datacenter.dc.id
}

resource "vsphere_virtual_machine" "vm" {
  name             = "terraform-test"
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id     = data.vsphere_datastore.datastore.id

  num_cpus = 2
  memory   = 8192

  // how would you get guest_id from the content library template?
// this is not possible :(
  guest_id = data.vsphere_content_library_item.item.guest_id

  network_interface {
    network_id = data.vsphere_network.network.id
  }

  clone {
    template_uuid = data.vsphere_content_library_item.item.id

    customize {
      network_interface {
        ipv4_address = "10.0.0.10"
        ipv4_netmask = 24
      }
      ipv4_gateway = "10.0.0.1"
    }
  }

}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Expecting to compute template values like guest_id from content library item/template.

Actual Behavior

It's not documented how to compute template values from content library item.
It seems that the content library item only exports it's id value and nothing else.
This is not possible:

  guest_id = data.vsphere_content_library_item.item.guest_id

How to compute template values from content library item e.g. disk size and guest_id?

Steps to Reproduce

N/A

Important Factoids

N/A

References

@bill-rich
Copy link
Contributor

Hi @Satak! Unfortunately there is not currently a way to get template values from content library. The content library API has limited information. I believe this is due to the fact that content library items do not necessarily need to be templates.

I have a PR (#1014) open to help alleviate the problem. Once that is merged and released, you can work around the lack of config attributes on content library items by first deploying a VM from content library, and then using that as your source.

Another option is to deploy the VM from content library, and leave guest_id blank. The only caveat is that you will need to ignore guest_id changes using the following:

lifecycle {
  ignore_changes: [ "guest_id" ]
}

@ghost
Copy link

ghost commented May 1, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators May 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants