diff --git a/google/resource_compute_backend_bucket_signed_url_key.go b/google/resource_compute_backend_bucket_signed_url_key.go index d9463514616..5933ad9dca9 100644 --- a/google/resource_compute_backend_bucket_signed_url_key.go +++ b/google/resource_compute_backend_bucket_signed_url_key.go @@ -256,32 +256,40 @@ func flattenNestedComputeBackendBucketSignedUrlKey(d *schema.ResourceData, meta return nil, nil } - // Final nested resource is either a list of resources we need to filter - // or just the resource itself, which we return. switch v.(type) { case []interface{}: break case map[string]interface{}: - return v.(map[string]interface{}), nil + // Construct list out of single nested resource + v = []interface{}{v} default: - return nil, fmt.Errorf("invalid value for cdnPolicy.signedUrlKeyNames: %v", v) + return nil, fmt.Errorf("expected list or map for value cdnPolicy.signedUrlKeyNames. Actual value: %v", v) } + expectedName, err := expandComputeBackendBucketSignedUrlKeyName(d.Get("name"), d, meta.(*Config)) + if err != nil { + return nil, err + } + + // Search list for this resource. items := v.([]interface{}) - for _, vRaw := range items { - // If only an id is given in parent resource, - // construct a resource map for that id KV pair. - item := map[string]interface{}{"keyName": vRaw} - itemIdV, err := expandComputeBackendBucketSignedUrlKeyName(d.Get("name"), d, meta.(*Config)) - if err != nil { - return nil, err + for _, itemRaw := range items { + if itemRaw == nil { + continue } - actualIdV := flattenComputeBackendBucketSignedUrlKeyName(item["keyName"], d) - log.Printf("[DEBUG] Checking if item's keyName (%#v) is equal to resource's (%#v)", itemIdV, actualIdV) - if !reflect.DeepEqual(itemIdV, actualIdV) { + // List response only contains the ID - construct a response object. + item := map[string]interface{}{ + "keyName": itemRaw, + } + + itemName := flattenComputeBackendBucketSignedUrlKeyName(item["keyName"], d) + if !reflect.DeepEqual(itemName, expectedName) { + log.Printf("[DEBUG] Skipping item with keyName= %#v, looking for %#v)", itemName, expectedName) continue } + log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item) return item, nil } + return nil, nil } diff --git a/google/resource_compute_backend_service_signed_url_key.go b/google/resource_compute_backend_service_signed_url_key.go index ee809fbd529..e6131260262 100644 --- a/google/resource_compute_backend_service_signed_url_key.go +++ b/google/resource_compute_backend_service_signed_url_key.go @@ -256,32 +256,40 @@ func flattenNestedComputeBackendServiceSignedUrlKey(d *schema.ResourceData, meta return nil, nil } - // Final nested resource is either a list of resources we need to filter - // or just the resource itself, which we return. switch v.(type) { case []interface{}: break case map[string]interface{}: - return v.(map[string]interface{}), nil + // Construct list out of single nested resource + v = []interface{}{v} default: - return nil, fmt.Errorf("invalid value for cdnPolicy.signedUrlKeyNames: %v", v) + return nil, fmt.Errorf("expected list or map for value cdnPolicy.signedUrlKeyNames. Actual value: %v", v) } + expectedName, err := expandComputeBackendServiceSignedUrlKeyName(d.Get("name"), d, meta.(*Config)) + if err != nil { + return nil, err + } + + // Search list for this resource. items := v.([]interface{}) - for _, vRaw := range items { - // If only an id is given in parent resource, - // construct a resource map for that id KV pair. - item := map[string]interface{}{"keyName": vRaw} - itemIdV, err := expandComputeBackendServiceSignedUrlKeyName(d.Get("name"), d, meta.(*Config)) - if err != nil { - return nil, err + for _, itemRaw := range items { + if itemRaw == nil { + continue } - actualIdV := flattenComputeBackendServiceSignedUrlKeyName(item["keyName"], d) - log.Printf("[DEBUG] Checking if item's keyName (%#v) is equal to resource's (%#v)", itemIdV, actualIdV) - if !reflect.DeepEqual(itemIdV, actualIdV) { + // List response only contains the ID - construct a response object. + item := map[string]interface{}{ + "keyName": itemRaw, + } + + itemName := flattenComputeBackendServiceSignedUrlKeyName(item["keyName"], d) + if !reflect.DeepEqual(itemName, expectedName) { + log.Printf("[DEBUG] Skipping item with keyName= %#v, looking for %#v)", itemName, expectedName) continue } + log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item) return item, nil } + return nil, nil } diff --git a/google/resource_resource_manager_lien.go b/google/resource_resource_manager_lien.go index cb22d7fd745..ba0e4738722 100644 --- a/google/resource_resource_manager_lien.go +++ b/google/resource_resource_manager_lien.go @@ -290,28 +290,41 @@ func flattenNestedResourceManagerLien(d *schema.ResourceData, meta interface{}, return nil, nil } - // Final nested resource is either a list of resources we need to filter - // or just the resource itself, which we return. switch v.(type) { case []interface{}: break case map[string]interface{}: - return v.(map[string]interface{}), nil + // Construct list out of single nested resource + v = []interface{}{v} default: - return nil, fmt.Errorf("invalid value for liens: %v", v) + return nil, fmt.Errorf("expected list or map for value liens. Actual value: %v", v) } + expectedName := d.Get("name") + + // Search list for this resource. items := v.([]interface{}) - for _, vRaw := range items { - item := vRaw.(map[string]interface{}) - itemIdV := d.Get("name") - actualIdV := flattenResourceManagerLienName(item["name"], d) - log.Printf("[DEBUG] Checking if item's name (%#v) is equal to resource's (%#v)", itemIdV, actualIdV) - if !reflect.DeepEqual(itemIdV, actualIdV) { + for _, itemRaw := range items { + if itemRaw == nil { + continue + } + item := itemRaw.(map[string]interface{}) + + // Decode list item before comparing. + item, err := resourceResourceManagerLienDecoder(d, meta, item) + if err != nil { + return nil, err + } + + itemName := flattenResourceManagerLienName(item["name"], d) + if !reflect.DeepEqual(itemName, expectedName) { + log.Printf("[DEBUG] Skipping item with name= %#v, looking for %#v)", itemName, expectedName) continue } + log.Printf("[DEBUG] Found item for resource %q: %#v)", d.Id(), item) return item, nil } + return nil, nil } diff --git a/website/docs/getting_started.html.markdown b/website/docs/getting_started.html.markdown index 6bfe5b6be85..fea66ac4c20 100644 --- a/website/docs/getting_started.html.markdown +++ b/website/docs/getting_started.html.markdown @@ -81,7 +81,7 @@ resource "google_compute_instance" "vm_instance" { network_interface { # A default network is created for all GCP projects network = "default" - access_config { + access_config = { } } } @@ -135,7 +135,7 @@ network_interface { - # A default network is created for all GCP projects - network = "default" + network = "${google_compute_network.vpc_network.self_link}" - access_config { + access_config = { ``` This means that when we create the VM instance, it will use @@ -190,7 +190,7 @@ resource "google_compute_instance" "vm_instance" { network_interface { # A default network is created for all GCP projects network = "${google_compute_network.vpc_network.self_link}" - access_config { + access_config = { } } }