Skip to content

Commit

Permalink
add initial volumes to instances
Browse files Browse the repository at this point in the history
  • Loading branch information
rmb938 committed Feb 9, 2018
1 parent 1b4e4c0 commit 5f6d470
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
32 changes: 16 additions & 16 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import:
- package: github.com/hashicorp/terraform
version: 0.10.0
- package: github.com/sandwichcloud/deli-cli
version: 0.0.23
version: 0.0.24
31 changes: 30 additions & 1 deletion sandwich/resource_sandwich_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ func resourceInstance() *schema.Resource {
Type: schema.TypeString,
},
},
"volumes": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"size": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
},
"auto_delete": {
Type: schema.TypeBool,
Default: true,
Optional: true,
ForceNew: true,
},
},
},
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -104,6 +124,7 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error {
disk := d.Get("disk").(int)
userData := d.Get("user_data").(string)
var keypairIDs []string
var initialVolumes []api.InstanceInitialVolume
tags := map[string]string{}

for _, keypairID := range d.Get("keypair_ids").([]interface{}) {
Expand All @@ -114,7 +135,15 @@ func resourceInstanceCreate(d *schema.ResourceData, meta interface{}) error {
tags[k] = v.(string)
}

instance, err := instanceClient.Create(name, imageID, regionID, zoneID, networkID, serviceAccountID, flavorID, disk, keypairIDs, tags, userData)
for _, volumeInfoInt := range d.Get("volumes").([]interface{}) {
volumeInfo := volumeInfoInt.(map[string]interface{})
initialVolumes = append(initialVolumes, api.InstanceInitialVolume{
Size: volumeInfo["size"].(int),
AutoDelete: volumeInfo["auto_delete"].(bool),
})
}

instance, err := instanceClient.Create(name, imageID, regionID, zoneID, networkID, serviceAccountID, flavorID, disk, keypairIDs, initialVolumes, tags, userData)
if err != nil {
return err
}
Expand Down

0 comments on commit 5f6d470

Please sign in to comment.