Merge pull request #372 from jgoldschrafe/feature-google-compute-disk-types
Configurable disk types for GCE
This commit is contained in:
commit
9e953c9908
|
@ -0,0 +1,15 @@
|
|||
package google
|
||||
|
||||
import (
|
||||
"code.google.com/p/google-api-go-client/compute/v1"
|
||||
)
|
||||
|
||||
// readDiskType finds the disk type with the given name.
|
||||
func readDiskType(c *Config, zone *compute.Zone, name string) (*compute.DiskType, error) {
|
||||
diskType, err := c.clientCompute.DiskTypes.Get(c.Project, zone.Name, name).Do()
|
||||
if err == nil && diskType != nil && diskType.SelfLink != "" {
|
||||
return diskType, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
|
@ -40,6 +40,12 @@ func resourceComputeDisk() *schema.Resource {
|
|||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +53,15 @@ func resourceComputeDisk() *schema.Resource {
|
|||
func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
|
||||
// Get the zone
|
||||
log.Printf("[DEBUG] Loading zone: %s", d.Get("zone").(string))
|
||||
zone, err := config.clientCompute.Zones.Get(
|
||||
config.Project, d.Get("zone").(string)).Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error loading zone '%s': %s", d.Get("zone").(string), err)
|
||||
}
|
||||
|
||||
// Build the disk parameter
|
||||
disk := &compute.Disk{
|
||||
Name: d.Get("name").(string),
|
||||
|
@ -66,6 +81,18 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
disk.SourceImage = image.SelfLink
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("type"); ok {
|
||||
log.Printf("[DEBUG] Loading disk type: %s", v.(string))
|
||||
diskType, err := readDiskType(config, zone, v.(string))
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error loading disk type '%s': %s",
|
||||
v.(string), err)
|
||||
}
|
||||
|
||||
disk.Type = diskType.SelfLink
|
||||
}
|
||||
|
||||
op, err := config.clientCompute.Disks.Insert(
|
||||
config.Project, d.Get("zone").(string), disk).Do()
|
||||
if err != nil {
|
||||
|
|
|
@ -80,5 +80,6 @@ resource "google_compute_disk" "foobar" {
|
|||
name = "terraform-test"
|
||||
image = "debian-7-wheezy-v20140814"
|
||||
size = 50
|
||||
type = "pd-ssd"
|
||||
zone = "us-central1-a"
|
||||
}`
|
||||
|
|
|
@ -60,6 +60,13 @@ func resourceComputeInstance() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"auto_delete": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
|
@ -204,6 +211,18 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
}
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk(prefix + ".type"); ok {
|
||||
diskTypeName := v.(string)
|
||||
diskType, err := readDiskType(config, zone, diskTypeName)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error loading disk type '%s': %s",
|
||||
diskTypeName, err)
|
||||
}
|
||||
|
||||
disk.InitializeParams.DiskType = diskType.SelfLink
|
||||
}
|
||||
|
||||
disks = append(disks, &disk)
|
||||
}
|
||||
|
||||
|
|
|
@ -299,6 +299,7 @@ resource "google_compute_instance" "foobar" {
|
|||
disk {
|
||||
disk = "terraform-test-disk"
|
||||
auto_delete = false
|
||||
type = "pd-ssd"
|
||||
}
|
||||
|
||||
network {
|
||||
|
|
|
@ -13,6 +13,7 @@ Creates a new persistent disk within GCE, based on another disk.
|
|||
```
|
||||
resource "google_compute_disk" "default" {
|
||||
name = "test-disk"
|
||||
type = "pd-ssd"
|
||||
zone = "us-central1-a"
|
||||
image = "debian7-wheezy"
|
||||
}
|
||||
|
@ -32,6 +33,8 @@ The following arguments are supported:
|
|||
* `size` - (Optional) The size of the image in gigabytes. If not specified,
|
||||
it will inherit the size of its base image.
|
||||
|
||||
* `type` - (Optional) The GCE disk type.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
|
|
@ -71,6 +71,8 @@ The `disk` block supports:
|
|||
* `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
|
||||
This defaults to true.
|
||||
|
||||
* `type` - (Optional) The GCE disk type.
|
||||
|
||||
The `network` block supports:
|
||||
|
||||
* `source` - (Required) The name of the network to attach this interface to.
|
||||
|
|
Loading…
Reference in New Issue