@@ -17,6 +17,7 @@ package google
17
17
import (
18
18
"fmt"
19
19
"log"
20
+ "reflect"
20
21
"regexp"
21
22
"strconv"
22
23
"strings"
@@ -434,64 +435,74 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
434
435
return err
435
436
}
436
437
438
+ obj := make (map [string ]interface {})
437
439
descriptionProp , err := expandComputeDiskDescription (d .Get ("description" ), d , config )
438
440
if err != nil {
439
441
return err
442
+ } else if v , ok := d .GetOkExists ("description" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , descriptionProp )) {
443
+ obj ["description" ] = descriptionProp
440
444
}
441
445
labelsProp , err := expandComputeDiskLabels (d .Get ("labels" ), d , config )
442
446
if err != nil {
443
447
return err
448
+ } else if v , ok := d .GetOkExists ("labels" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , labelsProp )) {
449
+ obj ["labels" ] = labelsProp
444
450
}
445
451
nameProp , err := expandComputeDiskName (d .Get ("name" ), d , config )
446
452
if err != nil {
447
453
return err
454
+ } else if v , ok := d .GetOkExists ("name" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , nameProp )) {
455
+ obj ["name" ] = nameProp
448
456
}
449
457
sizeGbProp , err := expandComputeDiskSize (d .Get ("size" ), d , config )
450
458
if err != nil {
451
459
return err
460
+ } else if v , ok := d .GetOkExists ("size" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sizeGbProp )) {
461
+ obj ["sizeGb" ] = sizeGbProp
452
462
}
453
463
sourceImageProp , err := expandComputeDiskImage (d .Get ("image" ), d , config )
454
464
if err != nil {
455
465
return err
466
+ } else if v , ok := d .GetOkExists ("image" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sourceImageProp )) {
467
+ obj ["sourceImage" ] = sourceImageProp
456
468
}
457
469
typeProp , err := expandComputeDiskType (d .Get ("type" ), d , config )
458
470
if err != nil {
459
471
return err
472
+ } else if v , ok := d .GetOkExists ("type" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , typeProp )) {
473
+ obj ["type" ] = typeProp
460
474
}
461
475
zoneProp , err := expandComputeDiskZone (d .Get ("zone" ), d , config )
462
476
if err != nil {
463
477
return err
478
+ } else if v , ok := d .GetOkExists ("zone" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , zoneProp )) {
479
+ obj ["zone" ] = zoneProp
464
480
}
465
481
diskEncryptionKeyProp , err := expandComputeDiskDiskEncryptionKey (d .Get ("disk_encryption_key" ), d , config )
466
482
if err != nil {
467
483
return err
484
+ } else if v , ok := d .GetOkExists ("disk_encryption_key" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , diskEncryptionKeyProp )) {
485
+ obj ["diskEncryptionKey" ] = diskEncryptionKeyProp
468
486
}
469
487
sourceImageEncryptionKeyProp , err := expandComputeDiskSourceImageEncryptionKey (d .Get ("source_image_encryption_key" ), d , config )
470
488
if err != nil {
471
489
return err
490
+ } else if v , ok := d .GetOkExists ("source_image_encryption_key" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sourceImageEncryptionKeyProp )) {
491
+ obj ["sourceImageEncryptionKey" ] = sourceImageEncryptionKeyProp
472
492
}
473
493
sourceSnapshotProp , err := expandComputeDiskSnapshot (d .Get ("snapshot" ), d , config )
474
494
if err != nil {
475
495
return err
496
+ } else if v , ok := d .GetOkExists ("snapshot" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sourceSnapshotProp )) {
497
+ obj ["sourceSnapshot" ] = sourceSnapshotProp
476
498
}
477
499
sourceSnapshotEncryptionKeyProp , err := expandComputeDiskSourceSnapshotEncryptionKey (d .Get ("source_snapshot_encryption_key" ), d , config )
478
500
if err != nil {
479
501
return err
502
+ } else if v , ok := d .GetOkExists ("source_snapshot_encryption_key" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sourceSnapshotEncryptionKeyProp )) {
503
+ obj ["sourceSnapshotEncryptionKey" ] = sourceSnapshotEncryptionKeyProp
480
504
}
481
505
482
- obj := map [string ]interface {}{
483
- "description" : descriptionProp ,
484
- "labels" : labelsProp ,
485
- "name" : nameProp ,
486
- "sizeGb" : sizeGbProp ,
487
- "sourceImage" : sourceImageProp ,
488
- "type" : typeProp ,
489
- "zone" : zoneProp ,
490
- "diskEncryptionKey" : diskEncryptionKeyProp ,
491
- "sourceImageEncryptionKey" : sourceImageEncryptionKeyProp ,
492
- "sourceSnapshot" : sourceSnapshotProp ,
493
- "sourceSnapshotEncryptionKey" : sourceSnapshotEncryptionKeyProp ,
494
- }
495
506
obj , err = resourceComputeDiskEncoder (d , meta , obj )
496
507
if err != nil {
497
508
return err
@@ -631,24 +642,23 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
631
642
return err
632
643
}
633
644
634
- var obj map [string ]interface {}
635
645
var url string
636
646
var res map [string ]interface {}
637
647
op := & compute.Operation {}
638
648
639
649
d .Partial (true )
640
650
641
651
if d .HasChange ("label_fingerprint" ) || d .HasChange ("labels" ) {
652
+ obj := make (map [string ]interface {})
642
653
labelFingerprintProp := d .Get ("label_fingerprint" )
654
+ obj ["labelFingerprint" ] = labelFingerprintProp
643
655
labelsProp , err := expandComputeDiskLabels (d .Get ("labels" ), d , config )
644
656
if err != nil {
645
657
return err
658
+ } else if v , ok := d .GetOkExists ("labels" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , labelsProp )) {
659
+ obj ["labels" ] = labelsProp
646
660
}
647
661
648
- obj = map [string ]interface {}{
649
- "labelFingerprint" : labelFingerprintProp ,
650
- "labels" : labelsProp ,
651
- }
652
662
url , err = replaceVars (d , config , "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/setLabels" )
653
663
if err != nil {
654
664
return err
@@ -675,14 +685,14 @@ func resourceComputeDiskUpdate(d *schema.ResourceData, meta interface{}) error {
675
685
d .SetPartial ("labels" )
676
686
}
677
687
if d .HasChange ("size" ) {
688
+ obj := make (map [string ]interface {})
678
689
sizeGbProp , err := expandComputeDiskSize (d .Get ("size" ), d , config )
679
690
if err != nil {
680
691
return err
692
+ } else if v , ok := d .GetOkExists ("size" ); ! isEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , sizeGbProp )) {
693
+ obj ["sizeGb" ] = sizeGbProp
681
694
}
682
695
683
- obj = map [string ]interface {}{
684
- "sizeGb" : sizeGbProp ,
685
- }
686
696
url , err = replaceVars (d , config , "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/disks/{{name}}/resize" )
687
697
if err != nil {
688
698
return err
0 commit comments