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

Importing existing VM produces non-matching plan #335

Open
Morpheus0x opened this issue Jul 21, 2024 · 0 comments
Open

Importing existing VM produces non-matching plan #335

Morpheus0x opened this issue Jul 21, 2024 · 0 comments

Comments

@Morpheus0x
Copy link

Morpheus0x commented Jul 21, 2024

Using the terraform import command to get an existing VM from Xen Orchestra works. However, when showing the resource with terraform state show and copying the resulting output to the test-vm-01.tf file, adding the required template value and removing the dynamic values from the state shows inconsistencies when running terraform plan, making it basically impossible to import an existing infrastructure.

echo -e 'resource "xenorchestra_vm" "test-vm-01" {
  # Will be imported
}' > ./test-vm-01.tf
terraform import xenorchestra_vm.test-vm-01 12d0b1ed-5a63-d3b4-3ed8-a8f165f2c36b
# command successfully completes "Import successful!"
terraform state show xenorchestra_vm.test-vm-01

Output of state show command: test-vm-01_state_show.txt
Converted to the following .tf file: test-vm-01.tf.txt
Produces the following terraform plan state difference which requires the vm to be recreated: terraform_plan.txt

This is also the case when using the experimental -generate-config-out flag for terraform plan (reset state, not containing test-vm-01).

echo -e 'import {
  to = xenorchestra_vm.test-vm-01
  id = "12d0b1ed-5a63-d3b4-3ed8-a8f165f2c36b"
}' > import.tf
terraform plan -generate-config-out=generated.tf
cat generated.tf

The generate command seems to work, except for it not adding the correct template value. Output: terraform_plan_generate.txt
Adding the template vauluet manually, the generated.tf file looks as follows: generated.tf.txt
Then running terraform plan shows basically the same error: terraform_plan_generated.txt

The only other option I found was the terraformer tool which has a community supported xenorchestra plugin. But it unfortunately doesn't support importing VMs.

Edit: Forgot to mention, using the same .tf file copied from the state to create a new VM works without any issues and produces a matching state so that terraform plan reports "No changes.".

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

No branches or pull requests

1 participant