Skip to content

Importing existing VM produces non-matching plan #335

@Morpheus0x

Description

@Morpheus0x

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.".

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions