Skip to content

Commit

Permalink
Add hypervisor type argument to libvirt_domain resource (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
thequailman authored Nov 5, 2023
1 parent 49ba899 commit 8d7c58f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 0 additions & 6 deletions libvirt/domain_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ func newDomainDef() libvirtxml.Domain {
},
}

if v := os.Getenv("TERRAFORM_LIBVIRT_TEST_DOMAIN_TYPE"); v != "" {
domainDef.Type = v
} else {
domainDef.Type = "kvm"
}

// FIXME: We should allow setting this from configuration as well.
rngDev := os.Getenv("TF_LIBVIRT_RNG_DEV")
if rngDev == "" {
Expand Down
13 changes: 13 additions & 0 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net"
"net/url"
"os"
"strings"
"time"

Expand Down Expand Up @@ -74,6 +75,12 @@ func resourceLibvirtDomain() *schema.Resource {
Optional: true,
ForceNew: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "kvm",
},
"nvram": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -508,6 +515,12 @@ func resourceLibvirtDomainCreate(ctx context.Context, d *schema.ResourceData, me
domainDef.OS.Type.Machine = d.Get("machine").(string)
domainDef.Devices.Emulator = d.Get("emulator").(string)

if v := os.Getenv("TERRAFORM_LIBVIRT_TEST_DOMAIN_TYPE"); v != "" {
domainDef.Type = v
} else {
domainDef.Type = d.Get("type").(string)
}

arch, err := getHostArchitecture(virConn)
if err != nil {
return diag.Errorf("error retrieving host architecture: %s", err)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following arguments are supported:
* `emulator` - (Optional) The path of the emulator to use
* `qemu_agent` (Optional) By default is disabled, set to true for enabling it. More info [qemu-agent](https://wiki.libvirt.org/page/Qemu_guest_agent).
* `tpm` (Optional) TPM device to attach to the domain. The `tpm` object structure is documented [below](#tpm-device).
* `type` (Optional) The type of hypervisor to use for the domain. Defaults to `kvm`, other values can be found [here](https://libvirt.org/formatdomain.html#id1)
### Kernel and boot arguments

* `kernel` - (Optional) The path of the kernel to boot
Expand Down

0 comments on commit 8d7c58f

Please sign in to comment.