diff --git a/builtin/providers/google/resource_compute_disk.go b/builtin/providers/google/resource_compute_disk.go index 56b7ed25f..7202e45d9 100644 --- a/builtin/providers/google/resource_compute_disk.go +++ b/builtin/providers/google/resource_compute_disk.go @@ -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, @@ -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 { @@ -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 { diff --git a/builtin/providers/google/resource_compute_instance.go b/builtin/providers/google/resource_compute_instance.go index a12975b10..565d2f2c1 100644 --- a/builtin/providers/google/resource_compute_instance.go +++ b/builtin/providers/google/resource_compute_instance.go @@ -84,6 +84,11 @@ func resourceComputeInstance() *schema.Resource { Optional: true, ForceNew: true, }, + + "device_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -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) } diff --git a/website/source/docs/providers/google/r/compute_disk.html.markdown b/website/source/docs/providers/google/r/compute_disk.html.markdown index 4a8388bca..f38da7e40 100644 --- a/website/source/docs/providers/google/r/compute_disk.html.markdown +++ b/website/source/docs/providers/google/r/compute_disk.html.markdown @@ -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. diff --git a/website/source/docs/providers/google/r/compute_instance.html.markdown b/website/source/docs/providers/google/r/compute_instance.html.markdown index 3d3104d17..a0361c5a5 100644 --- a/website/source/docs/providers/google/r/compute_instance.html.markdown +++ b/website/source/docs/providers/google/r/compute_instance.html.markdown @@ -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.