Skip to content

Commit

Permalink
throw error if datasource not found (GoogleCloudPlatform#6786)
Browse files Browse the repository at this point in the history
* throw error if datasource not found

* update case

Co-authored-by: Edward Sun <sunedward@google.com>
  • Loading branch information
2 people authored and googlerjk committed Nov 25, 2022
1 parent 4464ee5 commit f75a661
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -35,7 +37,17 @@ func datasourceContainerClusterRead(d *schema.ResourceData, meta interface{}) er
return err
}

d.SetId(containerClusterFullName(project, location, clusterName))
id := containerClusterFullName(project, location, clusterName)

d.SetId(id)

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

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

return resourceContainerClusterRead(d, meta)
return nil
}

0 comments on commit f75a661

Please sign in to comment.