Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional options to google provider #1426

Merged
merged 3 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -81,6 +81,11 @@ func resourceComputeInstance() *schema.Resource {
Optional: true,
ForceNew: true,
},

"device_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -339,6 +344,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