Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func setTPMs(d *schema.ResourceData, domainDef *libvirtxml.Domain) {
prefix := "tpm.0"
if _, ok := d.GetOk(prefix); ok {
tpm := libvirtxml.DomainTPM{}
if model, ok := d.GetOk(".model"); ok {
if model, ok := d.GetOk(prefix + ".model"); ok {
tpm.Model = model.(string)
}

Expand Down
26 changes: 26 additions & 0 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,32 @@ func resourceLibvirtDomainRead(ctx context.Context, d *schema.ResourceData, meta
d.Set("kernel", domainDef.OS.Kernel)
d.Set("initrd", domainDef.OS.Initrd)

var (
tpms []map[string]interface{}
tpm map[string]interface{}
)
for _, tpmDef := range domainDef.Devices.TPMs {
tpm = map[string]interface{}{}
log.Printf(tpmDef.Model)
tpm["model"] = tpmDef.Model
if tpmDef.Backend.Emulator != nil {
tpm["backend_type"] = "emulator"
tpm["backend_version"] = tpmDef.Backend.Emulator.Version
} else if tpmDef.Backend.Passthrough != nil {
tpm["backend_type"] = "passthrough"
if tpmDef.Backend.Passthrough.Device != nil {
tpm["backend_device_path"] = tpmDef.Backend.Passthrough.Device.Path
}
} else {
log.Printf("TPM backend type from VM not implemented yet.")
}

tpms = append(tpms, tpm)
}
if len(tpms) > 0 {
d.Set("tpm", tpms)
}

caps, err := getHostCapabilities(virConn)
if err != nil {
return diag.FromErr(err)
Expand Down
35 changes: 35 additions & 0 deletions libvirt/resource_libvirt_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,41 @@ func TestAccLibvirtDomain_Cpu(t *testing.T) {
})
}

func TestAccLibvirtDomain_Tpm(t *testing.T) {
var domain libvirt.Domain
randomDomainName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)

config := fmt.Sprintf(`
resource "libvirt_domain" "%s" {
name = "%s"
tpm {
model = "tpm-crb"
backend_type = "emulator"
backend_version = "2.0"
}
}`, randomDomainName, randomDomainName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLibvirtDomainDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckLibvirtDomainExists("libvirt_domain."+randomDomainName, &domain),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "tpm.0.model", "tpm-crb"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "tpm.0.backend_type", "emulator"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "tpm.0.backend_version", "2.0"),
),
},
},
})
}

func TestAccLibvirtDomain_Video(t *testing.T) {
var domain libvirt.Domain
randomDomainName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
Expand Down