Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

existing Data Sources now return errors on 404s #15799

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/8858.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change

```
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dataSourceAccessApprovalFolderServiceAccountRead(d *schema.ResourceData, me
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("AccessApprovalFolderServiceAccount %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("AccessApprovalFolderServiceAccount %q", d.Id()), url)
}

if err := d.Set("name", res["name"]); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dataSourceAccessApprovalOrganizationServiceAccountRead(d *schema.ResourceDa
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("AccessApprovalOrganizationServiceAccount %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("AccessApprovalOrganizationServiceAccount %q", d.Id()), url)
}

if err := d.Set("name", res["name"]); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dataSourceAccessApprovalProjectServiceAccountRead(d *schema.ResourceData, m
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("AccessApprovalProjectServiceAccount %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("AccessApprovalProjectServiceAccount %q", d.Id()), url)
}

if err := d.Set("name", res["name"]); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions google/services/alloydb/data_source_alloydb_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func dataSourceAlloydbLocationsRead(d *schema.ResourceData, meta interface{}) er
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Locations %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Locations %q", d.Id()), url)
}
var locations []map[string]interface{}
for {
Expand Down Expand Up @@ -144,7 +144,7 @@ func dataSourceAlloydbLocationsRead(d *schema.ResourceData, meta interface{}) er
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Locations %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Locations %q", d.Id()), url)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func dataSourceAlloydbSupportedDatabaseFlagsRead(d *schema.ResourceData, meta in
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("SupportedDatabaseFlags %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("SupportedDatabaseFlags %q", d.Id()), url)
}
var supportedDatabaseFlags []map[string]interface{}
for {
Expand Down Expand Up @@ -223,7 +223,7 @@ func dataSourceAlloydbSupportedDatabaseFlagsRead(d *schema.ResourceData, meta in
UserAgent: userAgent,
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("SupportedDatabaseFlags %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("SupportedDatabaseFlags %q", d.Id()), url)
}
}
if err := d.Set("supported_database_flags", supportedDatabaseFlags); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func dataSourceGoogleAppEngineDefaultServiceAccountRead(d *schema.ResourceData,

sa, err := config.NewIamClient(userAgent).Projects.ServiceAccounts.Get(serviceAccountName).Do()
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Service Account %q", serviceAccountName))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Service Account %q", serviceAccountName), serviceAccountName)
}

d.SetId(sa.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ func dataSourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta inter
}

repository_id := d.Get("repository_id").(string)
d.SetId(fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id))
id := fmt.Sprintf("projects/%s/locations/%s/repositories/%s", project, location, repository_id)
d.SetId(id)

err = resourceArtifactRegistryRepositoryRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ func dataSourceGoogleBeyondcorpAppConnectionRead(d *schema.ResourceData, meta in
return err
}

d.SetId(fmt.Sprintf("projects/%s/locations/%s/appConnections/%s", project, region, name))
id := fmt.Sprintf("projects/%s/locations/%s/appConnections/%s", project, region, name)
d.SetId(id)

return resourceBeyondcorpAppConnectionRead(d, meta)
err = resourceBeyondcorpAppConnectionRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ func dataSourceGoogleBeyondcorpAppConnectorRead(d *schema.ResourceData, meta int
return err
}

d.SetId(fmt.Sprintf("projects/%s/locations/%s/appConnectors/%s", project, region, name))
id := fmt.Sprintf("projects/%s/locations/%s/appConnectors/%s", project, region, name)
d.SetId(id)

return resourceBeyondcorpAppConnectorRead(d, meta)
err = resourceBeyondcorpAppConnectorRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ func dataSourceGoogleBeyondcorpAppGatewayRead(d *schema.ResourceData, meta inter
return err
}

d.SetId(fmt.Sprintf("projects/%s/locations/%s/appGateways/%s", project, region, name))
id := fmt.Sprintf("projects/%s/locations/%s/appGateways/%s", project, region, name)
d.SetId(id)

return resourceBeyondcorpAppGatewayRead(d, meta)
err = resourceBeyondcorpAppGatewayRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func dataSourceGoogleBigqueryDefaultServiceAccountRead(d *schema.ResourceData, m

projectResource, err := config.NewBigQueryClient(userAgent).Projects.GetServiceAccount(project).Do()
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, "BigQuery service account not found")
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Project %q BigQuery service account", project), fmt.Sprintf("Project %q BigQuery service account", project))
}

d.SetId(projectResource.Email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func dataSourceBillingAccountRead(d *schema.ResourceData, meta interface{}) erro
if v, ok := d.GetOk("billing_account"); ok {
resp, err := config.NewBillingClient(userAgent).BillingAccounts.Get(CanonicalBillingAccountName(v.(string))).Do()
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Billing Account Not Found : %s", v))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Billing Account Not Found : %s", v), CanonicalBillingAccountName(v.(string)))
}

if openOk && resp.Open != open.(bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ func dataSourceGoogleCloudBuildTriggerRead(d *schema.ResourceData, meta interfac
}

id = strings.ReplaceAll(id, "/locations/global/", "/")

d.SetId(id)
return resourceCloudBuildTriggerRead(d, meta)

err = resourceCloudBuildTriggerRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package cloudfunctions

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
Expand Down Expand Up @@ -50,5 +52,9 @@ func dataSourceGoogleCloudFunctionsFunctionRead(d *schema.ResourceData, meta int
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", cloudFuncId.CloudFunctionId())
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ func dataSourceGoogleCloudFunctions2FunctionRead(d *schema.ResourceData, meta in
return err
}

d.SetId(fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, d.Get("location").(string), d.Get("name").(string)))
id := fmt.Sprintf("projects/%s/locations/%s/functions/%s", project, d.Get("location").(string), d.Get("name").(string))
d.SetId(id)

err = resourceCloudfunctions2functionRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func dataSourceGoogleCloudIdentityGroupMembershipsRead(d *schema.ResourceData, m
return nil
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("CloudIdentityGroupMemberships %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("CloudIdentityGroupMemberships %q", d.Id()), "")
}

if err := d.Set("memberships", result); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func dataSourceGoogleCloudIdentityGroupsRead(d *schema.ResourceData, meta interf
return nil
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("CloudIdentityGroups %q", d.Id()))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("CloudIdentityGroups %q", d.Id()), "Groups")
}

if err := d.Set("groups", result); err != nil {
Expand Down
11 changes: 10 additions & 1 deletion google/services/cloudrun/data_source_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,14 @@ func dataSourceGoogleCloudRunServiceRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return resourceCloudRunServiceRead(d, meta)
err = resourceCloudRunServiceRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ func dataSourceGoogleComposerEnvironmentRead(d *schema.ResourceData, meta interf
}
envName := d.Get("name").(string)

d.SetId(fmt.Sprintf("projects/%s/locations/%s/environments/%s", project, region, envName))
id := fmt.Sprintf("projects/%s/locations/%s/environments/%s", project, region, envName)
d.SetId(id)
err = resourceComposerEnvironmentRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return resourceComposerEnvironmentRead(d, meta)
return nil
}
13 changes: 12 additions & 1 deletion google/services/compute/data_source_compute_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package compute

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
Expand Down Expand Up @@ -31,5 +33,14 @@ func dataSourceGoogleComputeHealthCheckRead(d *schema.ResourceData, meta interfa
}
d.SetId(id)

return resourceComputeHealthCheckRead(d, meta)
err = resourceComputeHealthCheckRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func DataSourceGoogleComputeNetworkEndpointGroup() *schema.Resource {

func dataSourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
id := ""
if name, ok := d.GetOk("name"); ok {
project, err := tpgresource.GetProject(d, config)
if err != nil {
Expand All @@ -38,7 +39,8 @@ func dataSourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta inte
if err != nil {
return err
}
d.SetId(fmt.Sprintf("projects/%s/zones/%s/networkEndpointGroups/%s", project, zone, name.(string)))
id = fmt.Sprintf("projects/%s/zones/%s/networkEndpointGroups/%s", project, zone, name.(string))
d.SetId(id)
} else if selfLink, ok := d.GetOk("self_link"); ok {
parsed, err := tpgresource.ParseNetworkEndpointGroupFieldValue(selfLink.(string), d, config)
if err != nil {
Expand All @@ -53,10 +55,20 @@ func dataSourceComputeNetworkEndpointGroupRead(d *schema.ResourceData, meta inte
if err := d.Set("project", parsed.Project); err != nil {
return fmt.Errorf("Error setting project: %s", err)
}
d.SetId(fmt.Sprintf("projects/%s/zones/%s/networkEndpointGroups/%s", parsed.Project, parsed.Zone, parsed.Name))
id = fmt.Sprintf("projects/%s/zones/%s/networkEndpointGroups/%s", parsed.Project, parsed.Zone, parsed.Name)
d.SetId(id)
} else {
return errors.New("Must provide either `self_link` or `zone/name`")
}

return resourceComputeNetworkEndpointGroupRead(d, meta)
err := resourceComputeNetworkEndpointGroupRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
14 changes: 12 additions & 2 deletions google/services/compute/data_source_compute_network_peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ func dataSourceComputeNetworkPeeringRead(d *schema.ResourceData, meta interface{
if err != nil {
return err
}
d.SetId(fmt.Sprintf("%s/%s", networkFieldValue.Name, d.Get("name").(string)))
id := fmt.Sprintf("%s/%s", networkFieldValue.Name, d.Get("name").(string))
d.SetId(id)

return resourceComputeNetworkPeeringRead(d, meta)
err = resourceComputeNetworkPeeringRead(d, meta)
if err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}

return nil
}
6 changes: 4 additions & 2 deletions google/services/compute/data_source_google_compute_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ func dataSourceGoogleComputeAddressRead(d *schema.ResourceData, meta interface{}
}
name := d.Get("name").(string)

id := fmt.Sprintf("projects/%s/regions/%s/addresses/%s", project, region, name)

address, err := config.NewComputeClient(userAgent).Addresses.Get(project, region, name).Do()
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Address Not Found : %s", name))
return transport_tpg.HandleDataSourceNotFoundError(err, d, fmt.Sprintf("Address Not Found : %s", name), id)
}

if err := d.Set("address", address.Address); err != nil {
Expand Down Expand Up @@ -149,7 +151,7 @@ func dataSourceGoogleComputeAddressRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error setting region: %s", err)
}

d.SetId(fmt.Sprintf("projects/%s/regions/%s/addresses/%s", project, region, name))
d.SetId(id)
return nil
}

Expand Down
Loading