diff options
author | Christopher Baines <mail@cbaines.net> | 2018-04-08 16:42:36 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-04-08 16:42:36 +0100 |
commit | 682f8a9865fe0bec16423f63018725f5b364659b (patch) | |
tree | 99d64033e21c4c85316ff888868f8567d51b2b32 /libvirt | |
parent | ce90234bfc8aa09d5aead5992af2e07667603d07 (diff) | |
parent | fdfc6683c657aff1d37823301db768310d6722cc (diff) | |
download | terraform-provider-libvirt-for-govuk-mini-environment-admin.tar terraform-provider-libvirt-for-govuk-mini-environment-admin.tar.gz |
Merge remote-tracking branches 'origin/network_improvs' and 'cbaines-github/support-readonly-disks' into for-govuk-mini-environment-adminfor-govuk-mini-environment-admin
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 526f5a91..b198a5fb 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 { |