diff options
author | Silvio Moioli <smoioli@suse.de> | 2016-11-01 09:50:51 +0100 |
---|---|---|
committer | Silvio Moioli <smoioli@suse.de> | 2016-11-01 14:07:19 +0100 |
commit | f79e0c835f0c49716e633ec12057804a8f15895b (patch) | |
tree | 72d268aba799c92182a3c0bc774ea16faca31d74 /libvirt | |
parent | 5a9475c31f4d0a5d4eb5396e6947490679eee956 (diff) | |
download | terraform-provider-libvirt-f79e0c835f0c49716e633ec12057804a8f15895b.tar terraform-provider-libvirt-f79e0c835f0c49716e633ec12057804a8f15895b.tar.gz |
Allow to use maps for disk definitions
This changes the disk block in the domain resource to be defined as a map,
instead of an object. There is no difference in the standard use case,
but it allows to generate disk maps via interpolations and variables
which is useful in modules.
Diffstat (limited to 'libvirt')
-rw-r--r-- | libvirt/disk_def.go | 11 | ||||
-rw-r--r-- | libvirt/resource_libvirt_domain.go | 9 |
2 files changed, 5 insertions, 15 deletions
diff --git a/libvirt/disk_def.go b/libvirt/disk_def.go index 28fc7159..b0a4a5b3 100644 --- a/libvirt/disk_def.go +++ b/libvirt/disk_def.go @@ -2,7 +2,6 @@ package libvirt import ( "encoding/xml" - "github.com/hashicorp/terraform/helper/schema" ) type defDisk struct { @@ -26,16 +25,6 @@ type defDisk struct { } `xml:"driver"` } -func diskCommonSchema() map[string]*schema.Schema { - return map[string]*schema.Schema{ - "volume_id": &schema.Schema{ - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - } -} - func newDefDisk() defDisk { disk := defDisk{} disk.Type = "volume" diff --git a/libvirt/resource_libvirt_domain.go b/libvirt/resource_libvirt_domain.go index 849385b3..bfbf235d 100644 --- a/libvirt/resource_libvirt_domain.go +++ b/libvirt/resource_libvirt_domain.go @@ -78,8 +78,8 @@ func resourceLibvirtDomain() *schema.Resource { Optional: true, Required: false, ForceNew: true, - Elem: &schema.Resource{ - Schema: diskCommonSchema(), + Elem: &schema.Schema{ + Type: schema.TypeMap, }, }, "network_interface": &schema.Schema{ @@ -151,11 +151,12 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error disksCount := d.Get("disk.#").(int) var disks []defDisk for i := 0; i < disksCount; i++ { - prefix := fmt.Sprintf("disk.%d", i) disk := newDefDisk() disk.Target.Dev = fmt.Sprintf("vd%s", DiskLetterForIndex(i)) - volumeKey := d.Get(prefix + ".volume_id").(string) + diskKey := fmt.Sprintf("disk.%d", i) + diskMap := d.Get(diskKey).(map[string]interface{}) + volumeKey := diskMap["volume_id"].(string) diskVolume, err := virConn.LookupStorageVolByKey(volumeKey) if err != nil { return fmt.Errorf("Can't retrieve volume %s", volumeKey) |