Skip to content

Commit 43cccf3

Browse files
modular-magiciannat-henderson
authored andcommitted
Minor cleanup of disk's labelFingerprint. (hashicorp#1651)
1 parent 8591ab1 commit 43cccf3

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

google/resource_compute_disk.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ func resourceComputeDisk() *schema.Resource {
371371
Type: schema.TypeString,
372372
Computed: true,
373373
},
374+
"label_fingerprint": {
375+
Type: schema.TypeString,
376+
Computed: true,
377+
},
374378
"last_attach_timestamp": {
375379
Type: schema.TypeString,
376380
Computed: true,
@@ -408,11 +412,6 @@ func resourceComputeDisk() *schema.Resource {
408412
Computed: true,
409413
Deprecated: "Use disk_encryption_key.sha256 instead.",
410414
},
411-
412-
"label_fingerprint": &schema.Schema{
413-
Type: schema.TypeString,
414-
Computed: true,
415-
},
416415
"project": {
417416
Type: schema.TypeString,
418417
Optional: true,
@@ -560,6 +559,9 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
560559
return err
561560
}
562561

562+
if err := d.Set("label_fingerprint", flattenComputeDiskLabelFingerprint(res["labelFingerprint"])); err != nil {
563+
return fmt.Errorf("Error reading Disk: %s", err)
564+
}
563565
if err := d.Set("creation_timestamp", flattenComputeDiskCreationTimestamp(res["creationTimestamp"])); err != nil {
564566
return fmt.Errorf("Error reading Disk: %s", err)
565567
}
@@ -636,15 +638,17 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
636638

637639
d.Partial(true)
638640

639-
if d.HasChange("labels") {
641+
if d.HasChange("label_fingerprint") || d.HasChange("labels") {
642+
labelFingerprintProp := d.Get("label_fingerprint")
640643
labelsProp, err := expandComputeDiskLabels(d.Get("labels"), d, config)
641644
if err != nil {
642645
return err
643646
}
644647

645648
obj = map[string]interface{}{
649+
"labelFingerprint": labelFingerprintProp,
646650
"labels": labelsProp,
647-
"labelFingerprint": d.Get("label_fingerprint").(string)}
651+
}
648652
url, err = replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels")
649653
if err != nil {
650654
return err
@@ -667,6 +671,7 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
667671
return err
668672
}
669673

674+
d.SetPartial("label_fingerprint")
670675
d.SetPartial("labels")
671676
}
672677
if d.HasChange("size") {
@@ -834,6 +839,10 @@ func resourceComputeDiskImport(d *schema.ResourceData, meta interface{}) ([]*sch
834839
return []*schema.ResourceData{d}, nil
835840
}
836841

842+
func flattenComputeDiskLabelFingerprint(v interface{}) interface{} {
843+
return v
844+
}
845+
837846
func flattenComputeDiskCreationTimestamp(v interface{}) interface{} {
838847
return v
839848
}
@@ -1140,7 +1149,5 @@ func resourceComputeDiskDecoder(d *schema.ResourceData, meta interface{}, res ma
11401149
res["sourceSnapshotEncryptionKey"] = transformed
11411150
}
11421151

1143-
d.Set("label_fingerprint", res["labelFingerprint"])
1144-
11451152
return res, nil
11461153
}

website/docs/r/compute_disk.html.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ The `source_snapshot_encryption_key` block supports:
187187

188188
In addition to the arguments listed above, the following computed attributes are exported:
189189

190+
* `label_fingerprint` -
191+
The fingerprint used for optimistic locking of this resource. Used
192+
internally during updates.
190193
* `creation_timestamp` -
191194
Creation timestamp in RFC3339 text format.
192195
* `last_attach_timestamp` -
@@ -216,8 +219,6 @@ In addition to the arguments listed above, the following computed attributes are
216219
`disk_encryption_key.sha256`. It is deprecated to enhance
217220
consistency with `source_image_encryption_key` and
218221
`source_snapshot_encryption_key`.
219-
* `label_fingerprint`: The fingerprint of the assigned labels. Provided
220-
when labels are updated to prevent contention (first-write-wins).
221222
## Timeouts
222223

223224
This resource provides the following

0 commit comments

Comments
 (0)