Skip to content

Commit

Permalink
fix InternalValidate error on cpu.mode block
Browse files Browse the repository at this point in the history
Fixes error:

* resource libvirt_domain: cpu: TypeMap with Elem *Resource not supported,use
  TypeList/TypeSet with Elem *Resource or TypeMap with Elem *Schema
  • Loading branch information
dmacvicar committed Sep 12, 2021
1 parent 0286102 commit 7074fe3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ func resourceLibvirtDomain() *schema.Resource {
},
},
"cpu": {
Type: schema.TypeMap,
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -449,7 +450,7 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
domainDef.Name = name.(string)
}

if cpuMode, ok := d.GetOk("cpu.mode"); ok {
if cpuMode, ok := d.GetOk("cpu.0.mode"); ok {
domainDef.CPU = &libvirtxml.DomainCPU{
Mode: cpuMode.(string),
}
Expand Down
4 changes: 2 additions & 2 deletions libvirt/resource_libvirt_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ func TestAccLibvirtDomain_Cpu(t *testing.T) {
var config = fmt.Sprintf(`
resource "libvirt_domain" "%s" {
name = "%s"
cpu = {
cpu {
mode = "custom"
}
}`, randomDomainName, randomDomainName)
Expand All @@ -884,7 +884,7 @@ func TestAccLibvirtDomain_Cpu(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckLibvirtDomainExists("libvirt_domain."+randomDomainName, &domain),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "cpu.mode", "custom"),
"libvirt_domain."+randomDomainName, "cpu.0.mode", "custom"),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ The optional `cpu` block allows to configure CPU mode. Example:
```hcl
resource "libvirt_domain" "my_machine" {
...
cpu = {
cpu {
mode = "host-passthrough"
}
}
Expand Down

0 comments on commit 7074fe3

Please sign in to comment.