Skip to content

Commit

Permalink
Merge pull request #1426 from dainis/master
Browse files Browse the repository at this point in the history
provider/google: add additional options to google provider
  • Loading branch information
mitchellh committed Apr 22, 2015
2 parents d02abb7 + b05780c commit 9037a3a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
30 changes: 29 additions & 1 deletion builtin/providers/google/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func resourceComputeDisk() *schema.Resource {
ForceNew: true,
},

"snapshot": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"self_link": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -98,6 +104,21 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
disk.Type = diskType.SelfLink
}

if v, ok := d.GetOk("snapshot"); ok {
snapshotName := v.(string)
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
snapshotData, err := config.clientCompute.Snapshots.Get(
config.Project, snapshotName).Do()

if err != nil {
return fmt.Errorf(
"Error loading snapshot '%s': %s",
snapshotName, err)
}

disk.SourceSnapshot = snapshotData.SelfLink
}

op, err := config.clientCompute.Disks.Insert(
config.Project, d.Get("zone").(string), disk).Do()
if err != nil {
Expand All @@ -116,7 +137,14 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
Type: OperationWaitZone,
}
state := w.Conf()
state.Timeout = 2 * time.Minute

if disk.SourceSnapshot != "" {
//creating disk from snapshot takes some time
state.Timeout = 10 * time.Minute
} else {
state.Timeout = 2 * time.Minute
}

state.MinTimeout = 1 * time.Second
opRaw, err := state.WaitForState()
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions builtin/providers/google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func resourceComputeInstance() *schema.Resource {
Optional: true,
ForceNew: true,
},

"device_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -341,6 +346,10 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
disk.InitializeParams.DiskSizeGb = int64(diskSizeGb)
}

if v, ok := d.GetOk(prefix + ".device_name"); ok {
disk.DeviceName = v.(string)
}

disks = append(disks, &disk)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The following arguments are supported:
contraction of the form "project/name", or just a name (in which case the current project is
used).

* `snapshot` - (Optional) Name of snapshot from which to initialize this disk;

* `size` - (Optional) The size of the image in gigabytes. If not specified,
it will inherit the size of its base image.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ The `disk` block supports:
* `size` - (Optional) The size of the image in gigabytes. If not specified,
it will inherit the size of its base image.

* `device_name` - (Optional) Name with which attached disk will be accessible
under `/dev/disk/by-id/`

The `network_interface` block supports:

* `network` - (Required) The name of the network to attach this interface to.
Expand Down

0 comments on commit 9037a3a

Please sign in to comment.