diff options
-rw-r--r-- | docs/providers/libvirt/r/domain.html.markdown | 11 | ||||
-rw-r--r-- | libvirt/domain_def.go | 3 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 14 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain_test.go | 28 |
4 files changed, 56 insertions, 0 deletions
diff --git a/docs/providers/libvirt/r/domain.html.markdown b/docs/providers/libvirt/r/domain.html.markdown index a779a69b..3305973b 100644 --- a/docs/providers/libvirt/r/domain.html.markdown +++ b/docs/providers/libvirt/r/domain.html.markdown @@ -40,6 +40,7 @@ The following arguments are supported: the domain. This is going to be attached as a CDROM ISO. Changing the cloud-init won't cause the domain to be recreated, however the change will have effect on the next reboot. +* `cpu` - (Optional) Configures CPU mode. There is an optional `coreos_ignition` parameter: * `coreos_ignition` (Optional) The `libvirt_ignition` resource that is to be used by @@ -285,6 +286,16 @@ that you can repeat `disk` blocks (see above) See [libvirt Domain XML Console element](https://libvirt.org/formatdomain.html#elementsConsole) for more information. +The optional `cpu` block allows to configure CPU mode. Example: +``` +resource "libvirt_domain" "my_machine" { + ... + cpu { + mode = "host-passthrough" + } +} +``` + ## Attributes Reference * `id` - a unique identifier for the resource diff --git a/libvirt/domain_def.go b/libvirt/domain_def.go index 3ac2bedb..407183b5 100644 --- a/libvirt/domain_def.go +++ b/libvirt/domain_def.go @@ -50,6 +50,9 @@ type defDomain struct { XMLName xml.Name `xml:"qemu:commandline"` Cmd []defCmd `xml:"qemu:arg"` } + Cpu struct { + Mode string `xml:"mode,attr,omitempty"` + } `xml:"cpu,omitempty"` } type defGraphics struct { diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 106f5fed..56b99ba8 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -125,6 +125,12 @@ func resourceLibvirtDomain() *schema.Resource { Schema: consoleSchema(), }, }, + "cpu": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + Required: false, + ForceNew: true, + }, }, } } @@ -194,6 +200,13 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error } } + if cpu, ok := d.GetOk("cpu"); ok { + cpu_map := cpu.(map[string]interface{}) + if cpu_mode, ok := cpu_map["mode"]; ok { + domainDef.Cpu.Mode = cpu_mode.(string) + } + } + if firmware, ok := d.GetOk("firmware"); ok { firmwareFile := firmware.(string) if _, err := os.Stat(firmwareFile); os.IsNotExist(err) { @@ -646,6 +659,7 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error { d.Set("memory", domainDef.Memory) d.Set("firmware", domainDef.Os.Loader) d.Set("nvram", domainDef.Os.NvRam) + d.Set("cpu", domainDef.Cpu) running, err := isDomainRunning(domain) if err != nil { diff --git a/libvirt/resource_libvirt_domain_test.go b/libvirt/resource_libvirt_domain_test.go index 4e584c5a..942770d8 100644 --- a/libvirt/resource_libvirt_domain_test.go +++ b/libvirt/resource_libvirt_domain_test.go @@ -323,6 +323,34 @@ func TestAccLibvirtDomain_IgnitionObject(t *testing.T) { }) } +func TestAccLibvirtDomain_Cpu(t *testing.T) { + var domain libvirt.VirDomain + + var config = fmt.Sprintf(` + resource "libvirt_domain" "acceptance-test-domain" { + name = "terraform-test" + cpu { + mode = "host-passthrough" + } + }`) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLibvirtDomainDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccCheckLibvirtDomainExists("libvirt_domain.acceptance-test-domain", &domain), + resource.TestCheckResourceAttr( + "libvirt_domain.acceptance-test-domain", "cpu.mode", "host-passthrough"), + ), + }, + }, + }) +} + func testAccCheckLibvirtDomainDestroy(s *terraform.State) error { virtConn := testAccProvider.Meta().(*Client).libvirt |