From 085a05cefc23bef7ded45513deceb7d31ca99497 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 16 Aug 2018 12:29:39 -0700 Subject: [PATCH] Fix region disk type (#1890) /cc @danawillow --- google/resource_compute_disk.go | 12 +++---- google/resource_compute_region_disk.go | 44 +++++++++++++------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/google/resource_compute_disk.go b/google/resource_compute_disk.go index 4e75b4d846d..8412e37c990 100644 --- a/google/resource_compute_disk.go +++ b/google/resource_compute_disk.go @@ -597,10 +597,10 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("size", flattenComputeDiskSize(res["sizeGb"])); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } - if err := d.Set("type", flattenComputeDiskType(res["type"])); err != nil { + if err := d.Set("users", flattenComputeDiskUsers(res["users"])); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } - if err := d.Set("users", flattenComputeDiskUsers(res["users"])); err != nil { + if err := d.Set("type", flattenComputeDiskType(res["type"])); err != nil { return fmt.Errorf("Error reading Disk: %s", err) } if err := d.Set("image", flattenComputeDiskImage(res["sourceImage"])); err != nil { @@ -895,18 +895,18 @@ func flattenComputeDiskSize(v interface{}) interface{} { return v } -func flattenComputeDiskType(v interface{}) interface{} { +func flattenComputeDiskUsers(v interface{}) interface{} { if v == nil { return v } - return NameFromSelfLinkStateFunc(v) + return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) } -func flattenComputeDiskUsers(v interface{}) interface{} { +func flattenComputeDiskType(v interface{}) interface{} { if v == nil { return v } - return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) + return NameFromSelfLinkStateFunc(v) } func flattenComputeDiskImage(v interface{}) interface{} { diff --git a/google/resource_compute_region_disk.go b/google/resource_compute_region_disk.go index 5f1d720bd2d..c94e8cfe61c 100644 --- a/google/resource_compute_region_disk.go +++ b/google/resource_compute_region_disk.go @@ -207,18 +207,18 @@ func resourceComputeRegionDiskCreate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("size"); !isEmptyValue(reflect.ValueOf(sizeGbProp)) && (ok || !reflect.DeepEqual(v, sizeGbProp)) { obj["sizeGb"] = sizeGbProp } - typeProp, err := expandComputeRegionDiskType(d.Get("type"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) { - obj["type"] = typeProp - } replicaZonesProp, err := expandComputeRegionDiskReplicaZones(d.Get("replica_zones"), d, config) if err != nil { return err } else if v, ok := d.GetOkExists("replica_zones"); !isEmptyValue(reflect.ValueOf(replicaZonesProp)) && (ok || !reflect.DeepEqual(v, replicaZonesProp)) { obj["replicaZones"] = replicaZonesProp } + typeProp, err := expandComputeRegionDiskType(d.Get("type"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("type"); !isEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) { + obj["type"] = typeProp + } regionProp, err := expandComputeRegionDiskRegion(d.Get("region"), d, config) if err != nil { return err @@ -334,15 +334,15 @@ func resourceComputeRegionDiskRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("size", flattenComputeRegionDiskSize(res["sizeGb"])); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } - if err := d.Set("type", flattenComputeRegionDiskType(res["type"])); err != nil { - return fmt.Errorf("Error reading RegionDisk: %s", err) - } if err := d.Set("users", flattenComputeRegionDiskUsers(res["users"])); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } if err := d.Set("replica_zones", flattenComputeRegionDiskReplicaZones(res["replicaZones"])); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } + if err := d.Set("type", flattenComputeRegionDiskType(res["type"])); err != nil { + return fmt.Errorf("Error reading RegionDisk: %s", err) + } if err := d.Set("region", flattenComputeRegionDiskRegion(res["region"])); err != nil { return fmt.Errorf("Error reading RegionDisk: %s", err) } @@ -600,25 +600,25 @@ func flattenComputeRegionDiskSize(v interface{}) interface{} { return v } -func flattenComputeRegionDiskType(v interface{}) interface{} { +func flattenComputeRegionDiskUsers(v interface{}) interface{} { if v == nil { return v } - return NameFromSelfLinkStateFunc(v) + return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) } -func flattenComputeRegionDiskUsers(v interface{}) interface{} { +func flattenComputeRegionDiskReplicaZones(v interface{}) interface{} { if v == nil { return v } return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) } -func flattenComputeRegionDiskReplicaZones(v interface{}) interface{} { +func flattenComputeRegionDiskType(v interface{}) interface{} { if v == nil { return v } - return convertAndMapStringArr(v.([]interface{}), ConvertSelfLinkToV1) + return NameFromSelfLinkStateFunc(v) } func flattenComputeRegionDiskRegion(v interface{}) interface{} { @@ -702,14 +702,6 @@ func expandComputeRegionDiskSize(v interface{}, d *schema.ResourceData, config * return v, nil } -func expandComputeRegionDiskType(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { - f, err := parseZonalFieldValue("diskTypes", v.(string), "project", "zone", d, config, true) - if err != nil { - return nil, fmt.Errorf("Invalid value for type: %s", err) - } - return f.RelativeLink(), nil -} - func expandComputeRegionDiskReplicaZones(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) req := make([]interface{}, 0, len(l)) @@ -723,6 +715,14 @@ func expandComputeRegionDiskReplicaZones(v interface{}, d *schema.ResourceData, return req, nil } +func expandComputeRegionDiskType(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + f, err := parseRegionalFieldValue("diskTypes", v.(string), "project", "region", "zone", d, config, true) + if err != nil { + return nil, fmt.Errorf("Invalid value for type: %s", err) + } + return f.RelativeLink(), nil +} + func expandComputeRegionDiskRegion(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true) if err != nil {