-
Notifications
You must be signed in to change notification settings - Fork 452
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
Feature Request: Support importing vsphere_virtual_machine resources #57
Comments
I also just ran into this as I was reorganizing my modules... I've reorganized them and now Terraform wants to destroy/recreate them all. I'd love if they could be imported. |
Hi, Best regards |
Would love to have this feature as we are trying to adopt terraform in our current organizatio, We wanna use this feature to compare the existing infra as a base line and then basically rewrite IaC as we add more resource. Any timeline around the availability of this? Thanks 👍 |
Hi I tried import with newest provider version - 1.0.3 and terraform version 0.11.1:
Is there a way to specify datacenter? I tried with -var 'datacenter=mydatacenter', but it doesn't work. Best regards |
Hey all, This was added in the 1.0.0 release. For more information, please consult the section in the Thanks! |
PS @Rybue, you want to specify the full path to the VM, as per the documentation, which should include the datacenter as well. |
@vancluever thanks! |
Could one of you elaborate or provide a generic example on what you mean by "full path to the VM....which should include the datacenter as well"? I am new to Terraform and am having the same issue when trying to import an existing VM. Thank you! |
Please, anyone, tell me HOW TO SPECIFY datacenter in "terraform import"? I have to create a lot of VMs
but some of this VMs already created manually and I don want to recreate it. How to import existing VMs from DC with name "dc-name" and id "dc-id"? |
@tenchi4u and @belonesox - some help on importing: The "full path" to your object in vSphere inventory is usually composed of a few things:
So, viewing the sample path as shown in https://www.terraform.io/docs/providers/vsphere/r/virtual_machine.html#importing, this is broken down as
Now, say you have both objects in folders - maybe your datacenter is in a folder named "foo" and your VM is in a folder named "blue". The path is then, along with breakdowns:
Hope this helps! |
@vancluever, thank you very much.
and even
but still get All data - *.tf files, logs, terraform.tfstate with "big-tms-00" VM (created by TF, which I tried to import back) on https://kopy.io/M2tz9 Any ideas welcomed! |
Dear @vancluever, may be you can look at previous comment? Please! |
@belonesox can you try to locate your vm using You can get info on govc here. Thanks! |
Thank you very much! But I immediately got new puzzle!
??? |
Dear @vancluever, may be you can look at previous comment? Please! |
@belonesox it sounds like you have an existing state for the specific resource address ( |
@belonesox I ran into this when I was using the Terraform vSphere examples - it's not the clearest of documentation, but the important bit is that the part after the period is the name of the vm. For example, what you would want in your Terraform file, and in the import step, is to call those vms something like "vsphere_virtual_machine.big-tms-01" and "vsphere_virtual_machine.big-tms-02" (defined in your instance.tf file like this:
|
Hello guys, resource "vsphere_virtual_machine" "dns" {
count = "${terraform.workspace == "core" ? "${local.core_dns_count}" : 0}"
name = "${element(local.core_dns_vm_names, count.index)}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = 1
memory = 1024
folder = "${local.core_folder}"
depends_on = ["vsphere_folder.core-folder"]
guest_id = "${data.vsphere_virtual_machine.centos.guest_id}"
scsi_type = "${data.vsphere_virtual_machine.centos.scsi_type}"
resource_pool_id = "${data.vsphere_compute_cluster.lab_cluster.resource_pool_id}"
network_interface {
network_id = "${data.vsphere_network.core-nic.id}"
}
disk {
label = "disk0"
size = "${data.vsphere_virtual_machine.centos.disks.0.size}"
eagerly_scrub = "${data.vsphere_virtual_machine.centos.disks.0.eagerly_scrub}"
thin_provisioned = "${data.vsphere_virtual_machine.centos.disks.0.thin_provisioned}"
}
clone {
template_uuid = "${data.vsphere_virtual_machine.centos.id}"
customize {
timeout = "${var.timeout}"
linux_options {
host_name = "${element(local.core_dns_vm_names, count.index)}"
domain = "domain.test"
}
network_interface {
ipv4_address = "${element(local.core_dns_vm_ips, count.index)}"
ipv4_netmask = 24
}
ipv4_gateway = "${local.core_gtw}"
}
}
provisioner "remote-exec" {
script = "after-deploy/centos.sh"
connection {
password = "${var.root_password}"
}
}
} This suppose to create 2 dns servers - dns1 and dns2. Unfortunately when I run vsphere_virtual_machine.dns: Importing from ID "/BM-LAB/vm/00_Core/00_dns2"...
vsphere_virtual_machine.dns: Import complete!
Imported vsphere_virtual_machine (ID: 564da04d-5ed8-c688-20a7-32eb89257a8c)
Error: vsphere_virtual_machine.dns (import id: /BM-LAB/vm/00_Core/00_dns2): Can't import vsphere_virtual_machine.dns, would collide with an existing resource.
Please remove or rename this resource before continuing. @vancluever could you tell me how to handle this situation and push all previously created items from |
@vancluever bump, any idea please? |
@Koleon I had some trouble with this, but finally this worked:
if course, if the DC is in a folder you need to prefix the folder name. Once I figured out how to properly construct the full path it worked great. Note: I believe it's case-sensitive 😉 |
This issue was originally opened by @jaredledvina as hashicorp/terraform#9535. It was migrated here as part of the provider split. The original body of the issue is below.
Terraform Version
Terraform v0.7.7
Affected Resource(s)
Expected Behavior
The following command would successfully import the resource into the tfstate file.
Actual Behavior
The command above fails with:
The text was updated successfully, but these errors were encountered: