From 758259b4955866cbead3d0d42b30734130e97a3c Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 6 Mar 2017 23:59:46 +0100 Subject: [PATCH 01/19] WIP: added a new resource type : google_compute_snapshot --- builtin/providers/google/provider.go | 1 + .../google/resource_compute_snapshot.go | 189 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 builtin/providers/google/resource_compute_snapshot.go diff --git a/builtin/providers/google/provider.go b/builtin/providers/google/provider.go index 7984a1f22..8571b0c94 100644 --- a/builtin/providers/google/provider.go +++ b/builtin/providers/google/provider.go @@ -66,6 +66,7 @@ func Provider() terraform.ResourceProvider { "google_compute_address": resourceComputeAddress(), "google_compute_backend_service": resourceComputeBackendService(), "google_compute_disk": resourceComputeDisk(), + "google_compute_snapshot": resourceComputeSnapshot(), "google_compute_firewall": resourceComputeFirewall(), "google_compute_forwarding_rule": resourceComputeForwardingRule(), "google_compute_global_address": resourceComputeGlobalAddress(), diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go new file mode 100644 index 000000000..210941ba9 --- /dev/null +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -0,0 +1,189 @@ +package google + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform/helper/schema" + "google.golang.org/api/compute/v1" + "google.golang.org/api/googleapi" +) + +func resourceComputeSnapshot() *schema.Resource { + return &schema.Resource{ + Create: resourceComputeSnapshotCreate, + Read: resourceComputeSnapshotRead, + Delete: resourceComputeSnapshotDelete, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "zone": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "snapshot_encryption_key_raw": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Sensitive: true, + }, + + "snapshot_encryption_key_sha256": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "sourcedisk_encryption_key_raw": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Sensitive: true, + }, + + "sourcedisk_encryption_key_sha256": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "sourcedisk_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "sourcedisk": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "disk": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "self_link": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + // Get the zone + log.Printf("[DEBUG] Loading zone: %s", d.Get("zone").(string)) + /* zone, err := config.clientCompute.Zones.Get( + project, d.Get("zone").(string)).Do() + if err != nil { + return fmt.Errorf( + "Error loading zone '%s': %s", d.Get("zone").(string), err) + } */ + + // Build the snapshot parameter + snapshot := &compute.Snapshot{ + Name: d.Get("name").(string), + } + + disk := d.Get("disk").(string) + + if v, ok := d.GetOk("snapshot_encryption_key_raw"); ok { + snapshot.SnapshotEncryptionKey = &compute.CustomerEncryptionKey{} + snapshot.SnapshotEncryptionKey.RawKey = v.(string) + } + + op, err := config.clientCompute.Disks.CreateSnapshot( + project, d.Get("zone").(string), disk, snapshot).Do() + if err != nil { + return fmt.Errorf("Error creating snapshot: %s", err) + } + + // It probably maybe worked, so store the ID now + d.SetId(snapshot.Name) + + err = computeOperationWaitZone(config, op, project, d.Get("zone").(string), "Creating Snapshot") + if err != nil { + return err + } + return resourceComputeSnapshotRead(d, meta) +} + +func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + snapshot, err := config.clientCompute.Snapshots.Get( + project, d.Id()).Do() + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + log.Printf("[WARN] Removing Snapshot %q because it's gone", d.Get("name").(string)) + // The resource doesn't exist anymore + d.SetId("") + + return nil + } + + return fmt.Errorf("Error reading snapshot: %s", err) + } + + d.Set("self_link", snapshot.SelfLink) + if snapshot.SnapshotEncryptionKey != nil && snapshot.SnapshotEncryptionKey.Sha256 != "" { + d.Set("snapshot_encryption_key_sha256", snapshot.SnapshotEncryptionKey.Sha256) + } + + return nil +} + +func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + // Delete the snapshot + op, err := config.clientCompute.Snapshots.Delete( + project, d.Id()).Do() + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + log.Printf("[WARN] Removing Snapshot %q because it's gone", d.Get("name").(string)) + // The resource doesn't exist anymore + d.SetId("") + return nil + } + return fmt.Errorf("Error deleting snapshot: %s", err) + } + + zone := d.Get("zone").(string) + err = computeOperationWaitZone(config, op, project, zone, "Creating Snapshot") + if err != nil { + return err + } + + d.SetId("") + return nil +} From a19849cd5d898de7e381a3a2c5886af5752953e6 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Tue, 7 Mar 2017 10:49:02 +0100 Subject: [PATCH 02/19] [WIP]: added a test acceptance for google_compute_snapshot --- .../google/resource_compute_snapshot_test.go | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 builtin/providers/google/resource_compute_snapshot_test.go diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go new file mode 100644 index 000000000..945eb60ee --- /dev/null +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -0,0 +1,156 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "google.golang.org/api/compute/v1" +) + +func TestAccComputeSnapshot_basic(t *testing.T) { + snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + var snapshot compute.Snapshot + diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeSnapshotDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeSnapshot_basic(snapshotName, diskName), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeSnapshotExists( + "google_compute_snapshot.foobar", &snapshot), + ), + }, + }, + }) +} + +func TestAccComputeSnapshot_encryption(t *testing.T) { + snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + var snapshot compute.Snapshot + diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeSnapshotDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeSnapshot_encryption(snapshotName, diskName), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeSnapshotExists( + "google_compute_snapshot.foobar", &snapshot), + testAccCheckSnapshotEncryptionKey( + "google_compute_snapshot.foobar", &snapshot), + ), + }, + }, + }) +} + +func testAccCheckComputeSnapshotDestroy(s *terraform.State) error { + config := testAccProvider.Meta().(*Config) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_compute_snapshot" { + continue + } + + _, err := config.clientCompute.Snapshots.Get( + config.Project, rs.Primary.ID).Do() + if err == nil { + return fmt.Errorf("Snapshot still exists") + } + } + + return nil +} + +func testAccCheckComputeSnapshotExists(n string, snapshot *compute.Snapshot) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No ID is set") + } + + config := testAccProvider.Meta().(*Config) + + found, err := config.clientCompute.Snapshots.Get( + config.Project, rs.Primary.ID).Do() + if err != nil { + return err + } + + if found.Name != rs.Primary.ID { + return fmt.Errorf("Snapshot not found") + } + + *snapshot = *found + + return nil + } +} + +func testAccCheckSnapshotEncryptionKey(n string, snapshot *compute.Snapshot) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + attr := rs.Primary.Attributes["snapshot_encryption_key_sha256"] + if snapshot.SnapshotEncryptionKey == nil && attr != "" { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v\nGCP State: ", n, attr) + } + + if attr != snapshot.SnapshotEncryptionKey.Sha256 { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, snapshot.SnapshotEncryptionKey.Sha256) + } + return nil + } +} + +func testAccComputeSnapshot_basic(snapshotName string, diskName string) string { + return fmt.Sprintf(` +resource "google_compute_disk" "foobar" { + name = "%s" + image = "debian-8-jessie-v20160803" + size = 50 + type = "pd-ssd" + zone = "us-central1-a" +} + +resource "google_compute_snapshot" "foobar" { + name = "%s" + disk = "${google_compute_disk.foobar.name}" + zone = "us-central1-a" +}`, diskName, snapshotName) +} + +func testAccComputeSnapshot_encryption(snapshotName string, diskName string) string { + return fmt.Sprintf(` +resource "google_compute_disk" "foobar" { + name = "%s" + image = "debian-8-jessie-v20160803" + size = 50 + type = "pd-ssd" + zone = "us-central1-a" +} +resource "google_compute_snapshot" "foobar" { + name = "%s" + disk = "%s" + zone = "us-central1-a" + snapshot_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" +}`, diskName, snapshotName, diskName) +} From b62f978f1bf1828972ff8f7cbe6deedaf701113b Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Wed, 8 Mar 2017 12:21:30 +0100 Subject: [PATCH 03/19] Cleanup --- builtin/providers/google/resource_compute_snapshot.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index 210941ba9..e43f1f067 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -90,15 +90,6 @@ func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) err return err } - // Get the zone - log.Printf("[DEBUG] Loading zone: %s", d.Get("zone").(string)) - /* zone, err := config.clientCompute.Zones.Get( - project, d.Get("zone").(string)).Do() - if err != nil { - return fmt.Errorf( - "Error loading zone '%s': %s", d.Get("zone").(string), err) - } */ - // Build the snapshot parameter snapshot := &compute.Snapshot{ Name: d.Get("name").(string), @@ -179,7 +170,7 @@ func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) err } zone := d.Get("zone").(string) - err = computeOperationWaitZone(config, op, project, zone, "Creating Snapshot") + err = computeOperationWaitZone(config, op, project, zone, "Deleting Snapshot") if err != nil { return err } From 64b67436abff4d509c23c31acae468403b9d2851 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 12:25:11 +0100 Subject: [PATCH 04/19] Provided sourcedisk_encryption_key_raw when creating a snapshot of a customer's self encrypted disk --- builtin/providers/google/resource_compute_snapshot.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index e43f1f067..adae6faf2 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -102,6 +102,11 @@ func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) err snapshot.SnapshotEncryptionKey.RawKey = v.(string) } + if v, ok := d.GetOk("sourcedisk_encryption_key_raw"); ok { + snapshot.SourceDiskEncryptionKey = &compute.CustomerEncryptionKey{} + snapshot.SourceDiskEncryptionKey.RawKey = v.(string) + } + op, err := config.clientCompute.Disks.CreateSnapshot( project, d.Get("zone").(string), disk, snapshot).Do() if err != nil { From d8e6b2ba8f9880156114ec5acefac779ecbc8d13 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 12:26:12 +0100 Subject: [PATCH 05/19] Snapshot operations are global by project --- builtin/providers/google/resource_compute_snapshot.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index adae6faf2..faf04cd4f 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -174,8 +174,7 @@ func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("Error deleting snapshot: %s", err) } - zone := d.Get("zone").(string) - err = computeOperationWaitZone(config, op, project, zone, "Deleting Snapshot") + err = computeOperationWaitGlobal(config, op, project, "Deleting Snapshot") if err != nil { return err } From 89a3073f0fe453b542c85f44a6123ea381aead56 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 12:26:46 +0100 Subject: [PATCH 06/19] Use a new image type --- builtin/providers/google/resource_compute_snapshot_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index 945eb60ee..104a92569 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -125,8 +125,8 @@ func testAccComputeSnapshot_basic(snapshotName string, diskName string) string { return fmt.Sprintf(` resource "google_compute_disk" "foobar" { name = "%s" - image = "debian-8-jessie-v20160803" - size = 50 + image = "debian-8-jessie-v20160921" + size = 10 type = "pd-ssd" zone = "us-central1-a" } From 1dbedf26efca2a87dbe1bf861bc643700c3a2149 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 12:27:22 +0100 Subject: [PATCH 07/19] Use a new image type --- builtin/providers/google/resource_compute_snapshot_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index 104a92569..0a6cfacdb 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -142,8 +142,8 @@ func testAccComputeSnapshot_encryption(snapshotName string, diskName string) str return fmt.Sprintf(` resource "google_compute_disk" "foobar" { name = "%s" - image = "debian-8-jessie-v20160803" - size = 50 + image = "debian-8-jessie-v20160921" + size = 10 type = "pd-ssd" zone = "us-central1-a" } From 2d1e1741bbb5e19a1ef6e234e00b849695d2cc58 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 12:27:39 +0100 Subject: [PATCH 08/19] Test encrypted snapshot of a encrypted disk --- builtin/providers/google/resource_compute_snapshot_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index 0a6cfacdb..1036da4a8 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -146,11 +146,13 @@ resource "google_compute_disk" "foobar" { size = 10 type = "pd-ssd" zone = "us-central1-a" + disk_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" } resource "google_compute_snapshot" "foobar" { name = "%s" - disk = "%s" + disk = "${google_compute_disk.foobar.name}" zone = "us-central1-a" + sourcedisk_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" snapshot_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" -}`, diskName, snapshotName, diskName) +}`, diskName, snapshotName) } From 882a8763eee0c7cafbbb521fb3c3fb4256b66d2f Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 13 Mar 2017 14:13:38 +0100 Subject: [PATCH 09/19] Documentation for the new resource : google_compute_snapshot --- .../google/r/compute_snapshot.html.markdown | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 website/source/docs/providers/google/r/compute_snapshot.html.markdown diff --git a/website/source/docs/providers/google/r/compute_snapshot.html.markdown b/website/source/docs/providers/google/r/compute_snapshot.html.markdown new file mode 100644 index 000000000..3b332de18 --- /dev/null +++ b/website/source/docs/providers/google/r/compute_snapshot.html.markdown @@ -0,0 +1,70 @@ +--- +layout: "google" +page_title: "Google: google_compute_snapshot" +sidebar_current: "docs-google-compute-snapshot" +description: |- + Creates a new snapshot of a disk within GCE. +--- + +# google\_compute\_snapshot + +Creates a new snapshot of a disk within GCE. + +## Example Usage + +```js +resource "google_compute_snapshot" "default" { + name = "test-snapshot" + disk = "test-disk" + zone = "us-central1-a" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) A unique name for the resource, required by GCE. + Changing this forces a new resource to be created. + +* `zone` - (Required) The zone where the source disk is located. + +* `disk` - (Required) + +- - - + +* `sourcedisk_encryption_key_raw` - (Optional) A 256-bit [customer-supplied encryption key] + (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption), + encoded in [RFC 4648 base64](https://tools.ietf.org/html/rfc4648#section-4) + to decrypt the source disk. + +* `snapshot_encryption_key_raw` - (Optional) A 256-bit [customer-supplied encryption key] + (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption), + encoded in [RFC 4648 base64](https://tools.ietf.org/html/rfc4648#section-4) + to encrypt this snapshot. + +* `project` - (Optional) The project in which the resource belongs. If it + is not provided, the provider project is used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are +exported: + +* `snapshot_encryption_key_sha256` - The [RFC 4648 base64] + (https://tools.ietf.org/html/rfc4648#section-4) encoded SHA-256 hash of the + [customer-supplied encryption key](https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) + that protects this resource. + +* `sourcedisk_encryption_key_sha256` - The [RFC 4648 base64] + (https://tools.ietf.org/html/rfc4648#section-4) encoded SHA-256 hash of the + [customer-supplied encryption key](https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) + that protects the source disk. + +* `sourcedisk_id` - The ID value of the source disk used to create this snapshot. + This value may be used to determine whether the snapshot was taken from the + current or a previous instance of a given disk name. + +* `sourcedisk` - The source disk used to create this snapshot. + +* `self_link` - The URI of the created resource. From 84dc163089881dad55ba1cf9d9bbbe1ee573bf78 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Wed, 22 Mar 2017 12:09:25 +0100 Subject: [PATCH 10/19] Review by @paddyforan: Rename sourcedisk to source_disk --- builtin/providers/google/resource_compute_snapshot.go | 10 +++++----- .../providers/google/resource_compute_snapshot_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index faf04cd4f..e8c6a9264 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -40,24 +40,24 @@ func resourceComputeSnapshot() *schema.Resource { Computed: true, }, - "sourcedisk_encryption_key_raw": &schema.Schema{ + "source_disk_encryption_key_raw": &schema.Schema{ Type: schema.TypeString, Optional: true, ForceNew: true, Sensitive: true, }, - "sourcedisk_encryption_key_sha256": &schema.Schema{ + "source_disk_encryption_key_sha256": &schema.Schema{ Type: schema.TypeString, Computed: true, }, - "sourcedisk_id": &schema.Schema{ + "source_disk_id": &schema.Schema{ Type: schema.TypeString, Computed: true, }, - "sourcedisk": &schema.Schema{ + "source_disk": &schema.Schema{ Type: schema.TypeString, Computed: true, }, @@ -102,7 +102,7 @@ func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) err snapshot.SnapshotEncryptionKey.RawKey = v.(string) } - if v, ok := d.GetOk("sourcedisk_encryption_key_raw"); ok { + if v, ok := d.GetOk("source_disk_encryption_key_raw"); ok { snapshot.SourceDiskEncryptionKey = &compute.CustomerEncryptionKey{} snapshot.SourceDiskEncryptionKey.RawKey = v.(string) } diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index 1036da4a8..e074de4c6 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -152,7 +152,7 @@ resource "google_compute_snapshot" "foobar" { name = "%s" disk = "${google_compute_disk.foobar.name}" zone = "us-central1-a" - sourcedisk_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" + source_disk_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" snapshot_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" }`, diskName, snapshotName) } From 00c3553f11a5ef88b5a6dfd0b9266b653832cd6b Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Wed, 22 Mar 2017 15:01:45 +0100 Subject: [PATCH 11/19] Review by @paddyforan: Add a resourceComputeSnapshotExists function --- .../google/resource_compute_snapshot.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index e8c6a9264..b136db38c 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -14,6 +14,7 @@ func resourceComputeSnapshot() *schema.Resource { Create: resourceComputeSnapshotCreate, Read: resourceComputeSnapshotRead, Delete: resourceComputeSnapshotDelete, + Exists: resourceComputeSnapshotExists, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ @@ -182,3 +183,26 @@ func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) err d.SetId("") return nil } + +func resourceComputeSnapshotExists(d *schema.ResourceData, meta interface{}) (bool, error) { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return false, err + } + + _, err = config.clientCompute.Snapshots.Get( + project, d.Id()).Do() + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + log.Printf("[WARN] Removing Snapshot %q because it's gone", d.Get("name").(string)) + // The resource doesn't exist anymore + d.SetId("") + + return false, err + } + return true, err + } + return true, nil +} From 0c4e343059ac5cf94226c202d46ee844710c7ac1 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Wed, 22 Mar 2017 15:42:05 +0100 Subject: [PATCH 12/19] Review by @paddyforan: Missing description in documentation --- .../docs/providers/google/r/compute_snapshot.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/providers/google/r/compute_snapshot.html.markdown b/website/source/docs/providers/google/r/compute_snapshot.html.markdown index 3b332de18..96306d600 100644 --- a/website/source/docs/providers/google/r/compute_snapshot.html.markdown +++ b/website/source/docs/providers/google/r/compute_snapshot.html.markdown @@ -29,7 +29,7 @@ The following arguments are supported: * `zone` - (Required) The zone where the source disk is located. -* `disk` - (Required) +* `disk` - (Required) The disk which will be used as the source of the snapshot - - - From 3d08cd07dd52e3a85501d1fc13bb0f9475ff872d Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 23 Mar 2017 10:38:57 +0100 Subject: [PATCH 13/19] Review by @paddyforan: Set attributes returned by API --- .../google/resource_compute_snapshot.go | 9 +++ .../google/resource_compute_snapshot_test.go | 56 ++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index b136db38c..9f5643a12 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -147,10 +147,19 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error } d.Set("self_link", snapshot.SelfLink) + if snapshot.SnapshotEncryptionKey != nil && snapshot.SnapshotEncryptionKey.Sha256 != "" { d.Set("snapshot_encryption_key_sha256", snapshot.SnapshotEncryptionKey.Sha256) } + if snapshot.SourceDiskEncryptionKey != nil && snapshot.SourceDiskEncryptionKey.Sha256 != "" { + d.Set("source_disk_encryption_key_sha256", snapshot.SourceDiskEncryptionKey.Sha256) + } + + d.Set("source_disk_id", snapshot.SourceDiskId) + + d.Set("source_disk", snapshot.SourceDisk) + return nil } diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index e074de4c6..2460e8459 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -92,7 +92,61 @@ func testAccCheckComputeSnapshotExists(n string, snapshot *compute.Snapshot) res } if found.Name != rs.Primary.ID { - return fmt.Errorf("Snapshot not found") + return fmt.Errorf("Snapshot %s not found", n) + } + + attr := rs.Primary.Attributes["snapshot_encryption_key_sha256"] + if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.Sha256 != attr { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SnapshotEncryptionKey.Sha256) + } else if found.SnapshotEncryptionKey == nil && attr != "" { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SnapshotEncryptionKey) + } + + attr = rs.Primary.Attributes["snapshot_encryption_key_raw"] + if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.RawKey != attr { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SnapshotEncryptionKey.RawKey) + } else if found.SnapshotEncryptionKey == nil && attr != "" { + return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SnapshotEncryptionKey) + } + + attr = rs.Primary.Attributes["source_disk_encryption_key_sha256"] + if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.Sha256 != attr { + return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDiskEncryptionKey.Sha256) + } else if found.SourceDiskEncryptionKey == nil && attr != "" { + return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDiskEncryptionKey) + } + + attr = rs.Primary.Attributes["source_disk_encryption_key_raw"] + if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.RawKey != attr { + return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDiskEncryptionKey.RawKey) + } else if found.SourceDiskEncryptionKey == nil && attr != "" { + return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDiskEncryptionKey) + } + + attr = rs.Primary.Attributes["source_disk_id"] + if found.SourceDiskId != attr { + return fmt.Errorf("Snapshot %s has mismatched source disk id.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDiskId) + } + + attr = rs.Primary.Attributes["source_disk"] + if found.SourceDisk != attr { + return fmt.Errorf("Snapshot %s has mismatched source disk.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SourceDisk) + } + + attr = rs.Primary.Attributes["self_link"] + if found.SelfLink != attr { + return fmt.Errorf("Snapshot %s has mismatched self link.\nTF State: %+v.\nGCP State: %+v", + n, attr, found.SelfLink) } *snapshot = *found From 6e76b907c7bc08f43d8ca0dc1d05ff02dec732b6 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 23 Mar 2017 12:05:14 +0100 Subject: [PATCH 14/19] Review by @paddyforan: better test possible network error --- .../google/resource_compute_snapshot_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index 2460e8459..cc74dc1fb 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "google.golang.org/api/compute/v1" + "google.golang.org/api/googleapi" ) func TestAccComputeSnapshot_basic(t *testing.T) { @@ -64,9 +65,15 @@ func testAccCheckComputeSnapshotDestroy(s *terraform.State) error { _, err := config.clientCompute.Snapshots.Get( config.Project, rs.Primary.ID).Do() - if err == nil { - return fmt.Errorf("Snapshot still exists") + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + return nil + } else if ok { + return fmt.Errorf("Error while requesting Google Cloud Plateform: http code error : %d, http message error: %s", gerr.Code, gerr.Message) + } + return fmt.Errorf("Error while requesting Google Cloud Plateform") } + return fmt.Errorf("Snapshot still exists") } return nil From 5fcc6593cd14b6ad59e82f05414a038c55270cfa Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Mon, 27 Mar 2017 10:36:39 +0200 Subject: [PATCH 15/19] Review by @paddyforan: corrected documentation. Replaced disk by source_disk. Deleted sourcedisk_id --- .../google/resource_compute_snapshot.go | 16 ++-------------- .../google/r/compute_snapshot.html.markdown | 14 ++++---------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index 9f5643a12..e8a4df452 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -53,17 +53,7 @@ func resourceComputeSnapshot() *schema.Resource { Computed: true, }, - "source_disk_id": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - "source_disk": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, - - "disk": &schema.Schema{ Type: schema.TypeString, Required: true, ForceNew: true, @@ -96,7 +86,7 @@ func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) err Name: d.Get("name").(string), } - disk := d.Get("disk").(string) + source_disk := d.Get("source_disk").(string) if v, ok := d.GetOk("snapshot_encryption_key_raw"); ok { snapshot.SnapshotEncryptionKey = &compute.CustomerEncryptionKey{} @@ -109,7 +99,7 @@ func resourceComputeSnapshotCreate(d *schema.ResourceData, meta interface{}) err } op, err := config.clientCompute.Disks.CreateSnapshot( - project, d.Get("zone").(string), disk, snapshot).Do() + project, d.Get("zone").(string), source_disk, snapshot).Do() if err != nil { return fmt.Errorf("Error creating snapshot: %s", err) } @@ -156,8 +146,6 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error d.Set("source_disk_encryption_key_sha256", snapshot.SourceDiskEncryptionKey.Sha256) } - d.Set("source_disk_id", snapshot.SourceDiskId) - d.Set("source_disk", snapshot.SourceDisk) return nil diff --git a/website/source/docs/providers/google/r/compute_snapshot.html.markdown b/website/source/docs/providers/google/r/compute_snapshot.html.markdown index 96306d600..d4d343df0 100644 --- a/website/source/docs/providers/google/r/compute_snapshot.html.markdown +++ b/website/source/docs/providers/google/r/compute_snapshot.html.markdown @@ -15,7 +15,7 @@ Creates a new snapshot of a disk within GCE. ```js resource "google_compute_snapshot" "default" { name = "test-snapshot" - disk = "test-disk" + source_disk = "test-disk" zone = "us-central1-a" } ``` @@ -29,11 +29,11 @@ The following arguments are supported: * `zone` - (Required) The zone where the source disk is located. -* `disk` - (Required) The disk which will be used as the source of the snapshot +* `source_disk` - (Required) The disk which will be used as the source of the snapshot - - - -* `sourcedisk_encryption_key_raw` - (Optional) A 256-bit [customer-supplied encryption key] +* `source_disk_encryption_key_raw` - (Optional) A 256-bit [customer-supplied encryption key] (https://cloud.google.com/compute/docs/disks/customer-supplied-encryption), encoded in [RFC 4648 base64](https://tools.ietf.org/html/rfc4648#section-4) to decrypt the source disk. @@ -56,15 +56,9 @@ exported: [customer-supplied encryption key](https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) that protects this resource. -* `sourcedisk_encryption_key_sha256` - The [RFC 4648 base64] +* `source_disk_encryption_key_sha256` - The [RFC 4648 base64] (https://tools.ietf.org/html/rfc4648#section-4) encoded SHA-256 hash of the [customer-supplied encryption key](https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) that protects the source disk. -* `sourcedisk_id` - The ID value of the source disk used to create this snapshot. - This value may be used to determine whether the snapshot was taken from the - current or a previous instance of a given disk name. - -* `sourcedisk` - The source disk used to create this snapshot. - * `self_link` - The URI of the created resource. From 573da4d72929adfd7ed7c62fd277e7100cdb9661 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 20 Apr 2017 12:12:43 +0200 Subject: [PATCH 16/19] Added a new attribute : source_disk_link --- builtin/providers/google/resource_compute_snapshot.go | 9 +++++++-- .../providers/google/r/compute_snapshot.html.markdown | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot.go b/builtin/providers/google/resource_compute_snapshot.go index e8a4df452..e482c86f9 100644 --- a/builtin/providers/google/resource_compute_snapshot.go +++ b/builtin/providers/google/resource_compute_snapshot.go @@ -59,6 +59,11 @@ func resourceComputeSnapshot() *schema.Resource { ForceNew: true, }, + "source_disk_link": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "project": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -137,6 +142,8 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error } d.Set("self_link", snapshot.SelfLink) + d.Set("source_disk_link", snapshot.SourceDisk) + d.Set("name", snapshot.Name) if snapshot.SnapshotEncryptionKey != nil && snapshot.SnapshotEncryptionKey.Sha256 != "" { d.Set("snapshot_encryption_key_sha256", snapshot.SnapshotEncryptionKey.Sha256) @@ -146,8 +153,6 @@ func resourceComputeSnapshotRead(d *schema.ResourceData, meta interface{}) error d.Set("source_disk_encryption_key_sha256", snapshot.SourceDiskEncryptionKey.Sha256) } - d.Set("source_disk", snapshot.SourceDisk) - return nil } diff --git a/website/source/docs/providers/google/r/compute_snapshot.html.markdown b/website/source/docs/providers/google/r/compute_snapshot.html.markdown index d4d343df0..cdeb4fea9 100644 --- a/website/source/docs/providers/google/r/compute_snapshot.html.markdown +++ b/website/source/docs/providers/google/r/compute_snapshot.html.markdown @@ -29,7 +29,7 @@ The following arguments are supported: * `zone` - (Required) The zone where the source disk is located. -* `source_disk` - (Required) The disk which will be used as the source of the snapshot +* `source_disk` - (Required) The disk which will be used as the source of the snapshot. - - - @@ -61,4 +61,6 @@ exported: [customer-supplied encryption key](https://cloud.google.com/compute/docs/disks/customer-supplied-encryption) that protects the source disk. +* `source_disk_link` - The URI of the source disk. + * `self_link` - The URI of the created resource. From 1b22200c440e56766cd01f33f4e65350db375bfb Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 20 Apr 2017 12:13:17 +0200 Subject: [PATCH 17/19] Corrected test for snapshot. Simplified tests. Added a new test for source_disk_link --- .../google/resource_compute_snapshot_test.go | 70 +++++-------------- 1 file changed, 17 insertions(+), 53 deletions(-) diff --git a/builtin/providers/google/resource_compute_snapshot_test.go b/builtin/providers/google/resource_compute_snapshot_test.go index cc74dc1fb..2a29f940d 100644 --- a/builtin/providers/google/resource_compute_snapshot_test.go +++ b/builtin/providers/google/resource_compute_snapshot_test.go @@ -34,8 +34,8 @@ func TestAccComputeSnapshot_basic(t *testing.T) { func TestAccComputeSnapshot_encryption(t *testing.T) { snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var snapshot compute.Snapshot diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + var snapshot compute.Snapshot resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -47,8 +47,6 @@ func TestAccComputeSnapshot_encryption(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckComputeSnapshotExists( "google_compute_snapshot.foobar", &snapshot), - testAccCheckSnapshotEncryptionKey( - "google_compute_snapshot.foobar", &snapshot), ), }, }, @@ -104,52 +102,38 @@ func testAccCheckComputeSnapshotExists(n string, snapshot *compute.Snapshot) res attr := rs.Primary.Attributes["snapshot_encryption_key_sha256"] if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.Sha256 != attr { - return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", + return fmt.Errorf("Snapshot %s has mismatched encryption key (Sha256).\nTF State: %+v.\nGCP State: %+v", n, attr, found.SnapshotEncryptionKey.Sha256) } else if found.SnapshotEncryptionKey == nil && attr != "" { return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", n, attr, found.SnapshotEncryptionKey) } - attr = rs.Primary.Attributes["snapshot_encryption_key_raw"] - if found.SnapshotEncryptionKey != nil && found.SnapshotEncryptionKey.RawKey != attr { - return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", - n, attr, found.SnapshotEncryptionKey.RawKey) - } else if found.SnapshotEncryptionKey == nil && attr != "" { - return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", - n, attr, found.SnapshotEncryptionKey) - } - attr = rs.Primary.Attributes["source_disk_encryption_key_sha256"] if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.Sha256 != attr { - return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", + return fmt.Errorf("Snapshot %s has mismatched source disk encryption key (Sha256).\nTF State: %+v.\nGCP State: %+v", n, attr, found.SourceDiskEncryptionKey.Sha256) } else if found.SourceDiskEncryptionKey == nil && attr != "" { return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", n, attr, found.SourceDiskEncryptionKey) } - attr = rs.Primary.Attributes["source_disk_encryption_key_raw"] - if found.SourceDiskEncryptionKey != nil && found.SourceDiskEncryptionKey.RawKey != attr { - return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", - n, attr, found.SourceDiskEncryptionKey.RawKey) - } else if found.SourceDiskEncryptionKey == nil && attr != "" { - return fmt.Errorf("Snapshot %s has mismatched source disk encryption key.\nTF State: %+v.\nGCP State: %+v", - n, attr, found.SourceDiskEncryptionKey) - } - - attr = rs.Primary.Attributes["source_disk_id"] - if found.SourceDiskId != attr { - return fmt.Errorf("Snapshot %s has mismatched source disk id.\nTF State: %+v.\nGCP State: %+v", - n, attr, found.SourceDiskId) - } - - attr = rs.Primary.Attributes["source_disk"] + attr = rs.Primary.Attributes["source_disk_link"] if found.SourceDisk != attr { - return fmt.Errorf("Snapshot %s has mismatched source disk.\nTF State: %+v.\nGCP State: %+v", + return fmt.Errorf("Snapshot %s has mismatched source disk link.\nTF State: %+v.\nGCP State: %+v", n, attr, found.SourceDisk) } + foundDisk, errDisk := config.clientCompute.Disks.Get( + config.Project, rs.Primary.Attributes["zone"], rs.Primary.Attributes["source_disk"]).Do() + if errDisk != nil { + return errDisk + } + if foundDisk.SelfLink != attr { + return fmt.Errorf("Snapshot %s has mismatched source disk\nTF State: %+v.\nGCP State: %+v", + n, attr, foundDisk.SelfLink) + } + attr = rs.Primary.Attributes["self_link"] if found.SelfLink != attr { return fmt.Errorf("Snapshot %s has mismatched self link.\nTF State: %+v.\nGCP State: %+v", @@ -162,26 +146,6 @@ func testAccCheckComputeSnapshotExists(n string, snapshot *compute.Snapshot) res } } -func testAccCheckSnapshotEncryptionKey(n string, snapshot *compute.Snapshot) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - attr := rs.Primary.Attributes["snapshot_encryption_key_sha256"] - if snapshot.SnapshotEncryptionKey == nil && attr != "" { - return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v\nGCP State: ", n, attr) - } - - if attr != snapshot.SnapshotEncryptionKey.Sha256 { - return fmt.Errorf("Snapshot %s has mismatched encryption key.\nTF State: %+v.\nGCP State: %+v", - n, attr, snapshot.SnapshotEncryptionKey.Sha256) - } - return nil - } -} - func testAccComputeSnapshot_basic(snapshotName string, diskName string) string { return fmt.Sprintf(` resource "google_compute_disk" "foobar" { @@ -194,7 +158,7 @@ resource "google_compute_disk" "foobar" { resource "google_compute_snapshot" "foobar" { name = "%s" - disk = "${google_compute_disk.foobar.name}" + source_disk = "${google_compute_disk.foobar.name}" zone = "us-central1-a" }`, diskName, snapshotName) } @@ -211,7 +175,7 @@ resource "google_compute_disk" "foobar" { } resource "google_compute_snapshot" "foobar" { name = "%s" - disk = "${google_compute_disk.foobar.name}" + source_disk = "${google_compute_disk.foobar.name}" zone = "us-central1-a" source_disk_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" snapshot_encryption_key_raw = "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=" From 68af7d44e8a7fcb27d1567a598204020d71187b0 Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 20 Apr 2017 12:13:47 +0200 Subject: [PATCH 18/19] Added the new resource to the nav panel --- website/source/layouts/google.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/source/layouts/google.erb b/website/source/layouts/google.erb index 074543363..c3811f4ab 100644 --- a/website/source/layouts/google.erb +++ b/website/source/layouts/google.erb @@ -123,6 +123,10 @@ google_compute_route + > + google_compute_snapshot + + > google_compute_ssl_certificate From 7ec1c66f6988191011f3a91e93f8b7fcedc4bdbf Mon Sep 17 00:00:00 2001 From: Thomas Poindessous Date: Thu, 20 Apr 2017 12:44:10 +0200 Subject: [PATCH 19/19] Merged upstream for nav --- website/source/layouts/google.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/layouts/google.erb b/website/source/layouts/google.erb index 381c29eee..6dfc3d6f5 100644 --- a/website/source/layouts/google.erb +++ b/website/source/layouts/google.erb @@ -173,7 +173,7 @@ > google_container_cluster - + > google_container_node_pool