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

Import fails on vsphere when template/-s exist #364

Open
fatspiderlinux opened this issue Mar 24, 2023 · 4 comments
Open

Import fails on vsphere when template/-s exist #364

fatspiderlinux opened this issue Mar 24, 2023 · 4 comments
Labels
Type: Bug Something isn't working

Comments

@fatspiderlinux
Copy link

General information:
Terracognita goes fine through all the resources but when it comes to vsphere_virtual_machine and a template is found it exits with an error.

  • Operating System: Rocky Linux release 9.1 (Blue Onyx)
  • Terracognita version / tag: 0.8.3
  • Did you build Terracognita from sources or did you use the Docker image:
    I used this instruction:
curl -L https://github.com/cycloidio/terracognita/releases/latest/download/terracognita-linux-amd64.tar.gz -o terracognita-linux-amd64.tar.gz
tar -xf terracognita-linux-amd64.tar.gz
chmod u+x terracognita-linux-amd64
sudo mv terracognita-linux-amd64 /usr/local/bin/terracognita

Describe the bug:

I am trying to map existing vsphere infra and when I run terracognita specifying all the resources but vsphere_virtual_machine it works perfectly fine.
When I try to discover virtual machines as well it exits with an error.

Log message

All good:

# terracognita vsphere --insecure --password "xxx" --username "xxx" --vsphereserver "xxx" --tfstate resources.tfstate --hcl resources.hcl --soap-url https://xxx/sdk -i vsphere_compute_cluster,vsphere_resource_pool,vsphere_datacenter,vsphere_folder,vsphere_datastore_cluster
Starting Terracognita with version v0.8.3
Importing with filters:
        Tags:    [],
        Include: [vsphere_compute_cluster vsphere_resource_pool vsphere_datacenter vsphere_folder vsphere_datastore_cluster],
        Exclude: [],
        Targets: [],
Importing vsphere_compute_cluster [1/1] Done!
Importing vsphere_resource_pool [1/1] Done!
Importing vsphere_datacenter [1/1] Done!
Importing vsphere_folder [8/8] Done!
Writing HCL Done!
Writing TFState Done!

Borked:

ts=2023-03-24T17:54:18.706597953Z caller=import.go:105 func=provider.Import resource=vsphere_virtual_machine id=/VxRail-Datacenter/vm/template.rocky.9 total=26 current=3 msg="reading from TF"
Error: could not import from vsphere: could not import resource vsphere_virtual_machine with id /VxRail-Datacenter/vm/template.rocky.9: VM "/VxRail-Datacenter/vm/template.rocky.9" is a template and cannot be imported
@fatspiderlinux fatspiderlinux added the Type: Bug Something isn't working label Mar 24, 2023
@fatspiderlinux
Copy link
Author

The above error exists for vsphere version 7.0.3, I just tried to import from older vsphere 6.0.0 and got the same issue:

ts=2023-03-24T18:15:59.200093938Z caller=import.go:105 func=provider.Import resource=vsphere_virtual_machine id=/Europe/vm/Templates/template-x-dbmxx_1 total=173 current=111 msg="reading from TF"
Error: could not import from vsphere: could not import resource vsphere_virtual_machine with id /Europe/vm/Templates/template-slvr-dbmxx_1: VM "/Europe/vm/Templates/template-x-dbmxx_1" is a template and cannot be imported

@fatspiderlinux
Copy link
Author

@xescugc
Copy link
Member

xescugc commented Mar 30, 2023

Hi @fatspiderlinux

If the errors is directly from the Provider it means they intended this type to not be imported when that condition happens, at the end TerraCognita tries to use the provider defined import so there is not much we can do around that.

I've checked a bit deeper and there is no specific reason on the PR/Commit in which this was introduced.

@alireza-nasseri-azihub
Copy link

it would be great if we had something to filter in Terracognita, maybe by using regex, we could only import vms which has not any "template" key on it's name, normally vsphere includes templates in the list of VM, by checking this API "/api/vcenter/vm" you can see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants