diff options
author | Christopher Baines <mail@cbaines.net> | 2018-03-15 08:30:33 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-04-08 14:50:50 +0100 |
commit | fdfc6683c657aff1d37823301db768310d6722cc (patch) | |
tree | db9063aca8eebaba13640176ee247bbc278f34a3 /libvirt | |
parent | d37e941778af77694f63306d4cae3250885abd87 (diff) | |
download | terraform-provider-libvirt-fdfc6683c657aff1d37823301db768310d6722cc.tar terraform-provider-libvirt-fdfc6683c657aff1d37823301db768310d6722cc.tar.gz |
Add support for readonly disks
Diffstat (limited to 'libvirt')
-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 { |