Skip to content

Commit

Permalink
oVirt: remove tmp template VM on bootstrap phase
Browse files Browse the repository at this point in the history
This patch breaks the dependency between terraform resources:
releaseimage_template  and tmp_import_vm

allowing us to remove the tmp vm during the bootstrap phase

Signed-off-by: Gal-Zaidman <gzaidman@redhat.com>
  • Loading branch information
Gal-Zaidman committed Jul 26, 2020
1 parent 8c87898 commit 3c59625
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions data/data/ovirt/template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,23 @@ resource "ovirt_vm" "tmp_import_vm" {
depends_on = [ovirt_image_transfer.releaseimage]
}

data "ovirt_vms" "tmp_import_vm_data" {
count = length(local.existing_id) == 0 ? 1 : 0
search = {
criteria = "name=tmpvm-for-${ovirt_image_transfer.releaseimage.0.alias}"
case_sensitive = true
}
depends_on = [ovirt_vm.tmp_import_vm]
}

resource "ovirt_template" "releaseimage_template" {
// create the template only when we don't have an existing template
count = length(local.existing_id) == 0 ? 1 : 0
// name the template after the openshift cluster id
name = var.openstack_base_image_name
cluster_id = ovirt_vm.tmp_import_vm.0.cluster_id
cluster_id = data.ovirt_vms.tmp_import_vm_data.0.vms.0.cluster_id
// create from vm
vm_id = ovirt_vm.tmp_import_vm.0.id
depends_on = [ovirt_vm.tmp_import_vm]
vm_id = data.ovirt_vms.tmp_import_vm_data.0.vms.0.id
}

// finally get the template by name(should be unique), fail if it doesn't exist
Expand Down
3 changes: 3 additions & 0 deletions pkg/destroy/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/openshift/installer/pkg/types/gcp"
"github.com/openshift/installer/pkg/types/libvirt"
"github.com/openshift/installer/pkg/types/openstack"
"github.com/openshift/installer/pkg/types/ovirt"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -79,6 +80,8 @@ func Destroy(dir string) (err error) {
if err != nil {
return errors.Wrapf(err, "Failed to delete glance image %s", imageName)
}
case ovirt.Name:
extraArgs = append(extraArgs, "-target=module.template.ovirt_vm.tmp_import_vm")
}

extraArgs = append(extraArgs, "-target=module.bootstrap")
Expand Down

0 comments on commit 3c59625

Please sign in to comment.