Skip to content

Commit 9037a3a

Browse files
committed
Merge pull request hashicorp#1426 from dainis/master
provider/google: add additional options to google provider
2 parents d02abb7 + b05780c commit 9037a3a

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

builtin/providers/google/resource_compute_disk.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func resourceComputeDisk() *schema.Resource {
4747
ForceNew: true,
4848
},
4949

50+
"snapshot": &schema.Schema{
51+
Type: schema.TypeString,
52+
Optional: true,
53+
ForceNew: true,
54+
},
55+
5056
"self_link": &schema.Schema{
5157
Type: schema.TypeString,
5258
Computed: true,
@@ -98,6 +104,21 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
98104
disk.Type = diskType.SelfLink
99105
}
100106

107+
if v, ok := d.GetOk("snapshot"); ok {
108+
snapshotName := v.(string)
109+
log.Printf("[DEBUG] Loading snapshot: %s", snapshotName)
110+
snapshotData, err := config.clientCompute.Snapshots.Get(
111+
config.Project, snapshotName).Do()
112+
113+
if err != nil {
114+
return fmt.Errorf(
115+
"Error loading snapshot '%s': %s",
116+
snapshotName, err)
117+
}
118+
119+
disk.SourceSnapshot = snapshotData.SelfLink
120+
}
121+
101122
op, err := config.clientCompute.Disks.Insert(
102123
config.Project, d.Get("zone").(string), disk).Do()
103124
if err != nil {
@@ -116,7 +137,14 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
116137
Type: OperationWaitZone,
117138
}
118139
state := w.Conf()
119-
state.Timeout = 2 * time.Minute
140+
141+
if disk.SourceSnapshot != "" {
142+
//creating disk from snapshot takes some time
143+
state.Timeout = 10 * time.Minute
144+
} else {
145+
state.Timeout = 2 * time.Minute
146+
}
147+
120148
state.MinTimeout = 1 * time.Second
121149
opRaw, err := state.WaitForState()
122150
if err != nil {

builtin/providers/google/resource_compute_instance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ func resourceComputeInstance() *schema.Resource {
8484
Optional: true,
8585
ForceNew: true,
8686
},
87+
88+
"device_name": &schema.Schema{
89+
Type: schema.TypeString,
90+
Optional: true,
91+
},
8792
},
8893
},
8994
},
@@ -341,6 +346,10 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
341346
disk.InitializeParams.DiskSizeGb = int64(diskSizeGb)
342347
}
343348

349+
if v, ok := d.GetOk(prefix + ".device_name"); ok {
350+
disk.DeviceName = v.(string)
351+
}
352+
344353
disks = append(disks, &disk)
345354
}
346355

website/source/docs/providers/google/r/compute_disk.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The following arguments are supported:
3434
contraction of the form "project/name", or just a name (in which case the current project is
3535
used).
3636

37+
* `snapshot` - (Optional) Name of snapshot from which to initialize this disk;
38+
3739
* `size` - (Optional) The size of the image in gigabytes. If not specified,
3840
it will inherit the size of its base image.
3941

website/source/docs/providers/google/r/compute_instance.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ The `disk` block supports:
9696
* `size` - (Optional) The size of the image in gigabytes. If not specified,
9797
it will inherit the size of its base image.
9898

99+
* `device_name` - (Optional) Name with which attached disk will be accessible
100+
under `/dev/disk/by-id/`
101+
99102
The `network_interface` block supports:
100103

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

0 commit comments

Comments
 (0)