diff options
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index f7d7a074..d1c6b61e 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -158,6 +158,11 @@ func resourceLibvirtDomain() *schema.Resource { Type: schema.TypeString, Optional: true, }, + "readonly": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }, }, }, @@ -706,27 +711,35 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error { return err } disk = map[string]interface{}{ - "url": url.String(), + "url": url.String(), + "readonly": diskDef.ReadOnly, } disks = append(disks, disk) } else if diskDef.Device == "cdrom" { disk = map[string]interface{}{ - "file": diskDef.Source.File, + "file": diskDef.Source.File, + "readonly": diskDef.ReadOnly, } } else { - virVol, err := virConn.LookupStorageVolByPath(diskDef.Source.File) - if err != nil { - return fmt.Errorf("Error retrieving volume for disk: %s", err) - } - defer virVol.Free() + if diskDef.ReadOnly == nil { + virVol, err := virConn.LookupStorageVolByPath(diskDef.Source.File) + if err != nil { + return fmt.Errorf("Error retrieving volume for disk: %s", err) + } + defer virVol.Free() - virVolKey, err := virVol.GetKey() - if err != nil { - return fmt.Errorf("Error retrieving volume for disk: %s", err) - } + virVolKey, err := virVol.GetKey() + if err != nil { + return fmt.Errorf("Error retrieving volume for disk: %s", err) + } - disk = map[string]interface{}{ - "volume_id": virVolKey, + disk = map[string]interface{}{ + "volume_id": virVolKey, + } + } else { + disk = map[string]interface{}{ + "readonly": diskDef.ReadOnly, + } } } disks = append(disks, disk) @@ -1097,6 +1110,12 @@ func setDisks(d *schema.ResourceData, domainDef *libvirtxml.Domain, virConn *lib } } + if d.Get(prefix + ".readonly").(bool) { + disk.ReadOnly = &libvirtxml.DomainDiskReadOnly{} + } else { + disk.ReadOnly = nil + } + if volumeKey, ok := d.GetOk(prefix + ".volume_id"); ok { diskVolume, err := virConn.LookupStorageVolByKey(volumeKey.(string)) if err != nil { |