Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local SSDs, Fix #1088 #1920

Merged
merged 1 commit into from
May 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions builtin/providers/google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func resourceComputeInstance() *schema.Resource {
ForceNew: true,
},

"scratch": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"auto_delete": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -319,6 +325,15 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
}

disk.Source = diskData.SelfLink
} else {
// Create a new disk
disk.InitializeParams = &compute.AttachedDiskInitializeParams{ }
}

if v, ok := d.GetOk(prefix + ".scratch"); ok {
if v.(bool) {
disk.Type = "SCRATCH"
}
}

// Load up the image for this disk if specified
Expand All @@ -332,9 +347,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
imageName, err)
}

disk.InitializeParams = &compute.AttachedDiskInitializeParams{
SourceImage: imageUrl,
}
disk.InitializeParams.SourceImage = imageUrl
}

if v, ok := d.GetOk(prefix + ".type"); ok {
Expand Down
41 changes: 41 additions & 0 deletions builtin/providers/google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ func TestAccComputeInstance_disks(t *testing.T) {
})
}

func TestAccComputeInstance_local_ssd(t *testing.T) {
var instance compute.Instance

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeInstance_local_ssd,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(
"google_compute_instance.local-ssd", &instance),
testAccCheckComputeInstanceDisk(&instance, "terraform-test", true, true),
),
},
},
})
}

func TestAccComputeInstance_update_deprecated_network(t *testing.T) {
var instance compute.Instance

Expand Down Expand Up @@ -609,6 +629,27 @@ resource "google_compute_instance" "foobar" {
}
}`

const testAccComputeInstance_local_ssd = `
resource "google_compute_instance" "local-ssd" {
name = "terraform-test"
machine_type = "n1-standard-1"
zone = "us-central1-a"

disk {
image = "debian-7-wheezy-v20140814"
}

disk {
type = "local-ssd"
scratch = true
}

network_interface {
network = "default"
}

}`

const testAccComputeInstance_service_account = `
resource "google_compute_instance" "foobar" {
name = "terraform-test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ resource "google_compute_instance" "default" {
image = "debian-7-wheezy-v20140814"
}

// Local SSD disk
disk {
type = "local-ssd"
scratch = true
}

network_interface {
network = "default"
access_config {
Expand Down Expand Up @@ -79,22 +85,27 @@ The following arguments are supported:

* `tags` - (Optional) Tags to attach to the instance.

The `disk` block supports:
The `disk` block supports: (Note that either disk or image is required, unless
the type is "local-ssd", in which case scratch must be true).

* `disk` - (Required if image not set) The name of the disk (such as
those managed by `google_compute_disk`) to attach.
* `disk` - The name of the existing disk (such as those managed by
`google_compute_disk`) to attach.

* `image` - (Required if disk not set) The image from which to initialize this
disk. Either the full URL, a contraction of the form "project/name", or just
a name (in which case the current project is used).
* `image` - The image from which to initialize this
disk. Either the full URL, a contraction of the form "project/name", or just
a name (in which case the current project is used).

* `auto_delete` - (Optional) Whether or not the disk should be auto-deleted.
This defaults to true.
This defaults to true. Leave true for local SSDs.

* `type` - (Optional) The GCE disk type, e.g. pd-standard, pd-ssd, or local-ssd.

* `type` - (Optional) The GCE disk type.
* `scratch` - (Optional) Whether the disk is a scratch disk as opposed to a
persistent disk (required for local-ssd).

* `size` - (Optional) The size of the image in gigabytes. If not specified,
it will inherit the size of its base image.
* `size` - (Optional) The size of the image in gigabytes. If not specified, it
will inherit the size of its base image. Do not specify for local SSDs as
their size is fixed.

* `device_name` - (Optional) Name with which attached disk will be accessible
under `/dev/disk/by-id/`
Expand Down