From 8ee3bb2d1678846a7171480ad84d8bd06e244376 Mon Sep 17 00:00:00 2001 From: Dainis Tillers Date: Wed, 8 Apr 2015 14:21:39 +0300 Subject: [PATCH 1/3] Added - create disk from snapshot --- .../providers/google/resource_compute_disk.go | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 { From 22616764fc7a996e44aea77f79a387b6519ce43f Mon Sep 17 00:00:00 2001 From: Dainis Tillers Date: Thu, 16 Oct 2014 16:43:52 +0300 Subject: [PATCH 2/3] Added - disk device name --- builtin/providers/google/resource_compute_instance.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/builtin/providers/google/resource_compute_instance.go b/builtin/providers/google/resource_compute_instance.go index d89e82a43..5b49a4b7a 100644 --- a/builtin/providers/google/resource_compute_instance.go +++ b/builtin/providers/google/resource_compute_instance.go @@ -81,6 +81,11 @@ func resourceComputeInstance() *schema.Resource { Optional: true, ForceNew: true, }, + + "device_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -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) } From b05780cdfef36e8b40abde0d6598adc1497568cb Mon Sep 17 00:00:00 2001 From: Dainis Tillers Date: Wed, 8 Apr 2015 14:41:47 +0300 Subject: [PATCH 3/3] Added - documentation about added features --- .../source/docs/providers/google/r/compute_disk.html.markdown | 2 ++ .../docs/providers/google/r/compute_instance.html.markdown | 3 +++ 2 files changed, 5 insertions(+) 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.