Skip to content

Commit 23adb11

Browse files
committed
remake error logic for datasource
1 parent 5b2be28 commit 23adb11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mmv1/third_party/terraform/services/compute/data_source_google_compute_instance_guest_attributes.go.tmpl

+7-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ func dataSourceGoogleComputeInstanceGuestAttributesRead(d *schema.ResourceData,
9292
return err
9393
}
9494

95+
//Check if instance exists
9596
id := fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, name)
96-
instanceGuestAttributes := &compute.GuestAttributes{}
97+
_, err = config.NewComputeClient(userAgent).Instances.Get(project, zone, name).Do()
98+
if err != nil {
99+
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Instance %s", name), id)
100+
}
97101

102+
instanceGuestAttributes := &compute.GuestAttributes{}
98103
// You can either query based on variable_key, query_path or just get the first value
99104
if d.Get("query_path").(string) != "" {
100105
instanceGuestAttributes, err = config.NewComputeClient(userAgent).Instances.GetGuestAttributes(project, zone, name).QueryPath(d.Get("query_path").(string)).Do()
@@ -104,7 +109,7 @@ func dataSourceGoogleComputeInstanceGuestAttributesRead(d *schema.ResourceData,
104109
instanceGuestAttributes, err = config.NewComputeClient(userAgent).Instances.GetGuestAttributes(project, zone, name).Do()
105110
}
106111
if err != nil {
107-
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Instance's Guest Attributes %s", name), id)
112+
return nil
108113
}
109114

110115
// Set query results

0 commit comments

Comments
 (0)