From 43cccf3e2c4b5d009fcc75b105ee8f38bcd6484c Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 14 Jun 2018 18:34:11 -0700 Subject: [PATCH] Minor cleanup of disk's labelFingerprint. (#1651) --- google/resource_compute_disk.go | 25 +++++++++++++++-------- website/docs/r/compute_disk.html.markdown | 5 +++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 52801989..64a0076f 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -371,6 +371,10 @@ func resourceComputeDisk() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "label_fingerprint": { + Type: schema.TypeString, + Computed: true, + }, "last_attach_timestamp": { Type: schema.TypeString, Computed: true, @@ -408,11 +412,6 @@ func resourceComputeDisk() *schema.Resource { Computed: true, Deprecated: "Use disk_encryption_key.sha256 instead.", }, - - "label_fingerprint": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, "project": { Type: schema.TypeString, Optional: true, @@ -560,6 +559,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { return err } + if err := d.Set("label_fingerprint", flattenComputeDiskLabelFingerprint(res["labelFingerprint"])); err != nil { + return fmt.Errorf("Error reading Disk: %s", err) + } if err := d.Set("creation_timestamp", flattenComputeDiskCreationTimestamp(res["creationTimestamp"])); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } @@ -636,15 +638,17 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { d.Partial(true) - if d.HasChange("labels") { + if d.HasChange("label_fingerprint") || d.HasChange("labels") { + labelFingerprintProp := d.Get("label_fingerprint") labelsProp, err := expandComputeDiskLabels(d.Get("labels"), d, config) if err != nil { return err } obj = map[string]interface{}{ + "labelFingerprint": labelFingerprintProp, "labels": labelsProp, - "labelFingerprint": d.Get("label_fingerprint").(string)} + } url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels") if err != nil { return err @@ -667,6 +671,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error { return err } + d.SetPartial("label_fingerprint") d.SetPartial("labels") } if d.HasChange("size") { @@ -834,6 +839,10 @@ func resourceComputeDiskImport(d *schema.ResourceData, meta interface{}) ([]*sch return []*schema.ResourceData{d}, nil } +func flattenComputeDiskLabelFingerprint(v interface{}) interface{} { + return v +} + func flattenComputeDiskCreationTimestamp(v interface{}) interface{} { return v } @@ -1140,7 +1149,5 @@ func resourceComputeDiskDecoder(d *schema.ResourceData, meta interface{}, res ma res["sourceSnapshotEncryptionKey"] = transformed } - d.Set("label_fingerprint", res["labelFingerprint"]) - return res, nil } diff --git a/website/docs/r/compute_disk.html.markdown b/website/docs/r/compute_disk.html.markdown index a0a8204b..0df9a2c0 100644 --- a/website/docs/r/compute_disk.html.markdown +++ b/website/docs/r/compute_disk.html.markdown @@ -187,6 +187,9 @@ The `source_snapshot_encryption_key` block supports: In addition to the arguments listed above, the following computed attributes are exported: +* `label_fingerprint` - + The fingerprint used for optimistic locking of this resource. Used + internally during updates. * `creation_timestamp` - Creation timestamp in RFC3339 text format. * `last_attach_timestamp` - @@ -216,8 +219,6 @@ In addition to the arguments listed above, the following computed attributes are `disk_encryption_key.sha256`. It is deprecated to enhance consistency with `source_image_encryption_key` and `source_snapshot_encryption_key`. -* `label_fingerprint`: The fingerprint of the assigned labels. Provided - when labels are updated to prevent contention (first-write-wins). ## Timeouts This resource provides the following