Minor cleanup of disk's labelFingerprint. (#1651)

This commit is contained in:
The Magician 2018-06-14 18:34:11 -07:00 committed by Nathan McKinley
parent 8591ab1577
commit 43cccf3e2c
2 changed files with 19 additions and 11 deletions

View File

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

View File

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