Merge pull request #1426 from dainis/master

provider/google: add additional options to google provider
This commit is contained in:
Mitchell Hashimoto 2015-04-22 08:50:22 +02:00
commit 9037a3a4bc
4 changed files with 43 additions and 1 deletions

View File

@ -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()
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 {

View File

@ -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)
}

View File

@ -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.

View File

@ -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.