From f75a661c0fd6b309339b156bd0810ba4b2bd884d Mon Sep 17 00:00:00 2001 From: Edward Sun <42220489+edwardmedia@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:17:26 -0800 Subject: [PATCH] throw error if datasource not found (#6786) * throw error if datasource not found * update case Co-authored-by: Edward Sun --- .../data_source_google_container_cluster.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/data_sources/data_source_google_container_cluster.go b/mmv1/third_party/terraform/data_sources/data_source_google_container_cluster.go index bcac7e9c6595..359cbefdd3fb 100644 --- a/mmv1/third_party/terraform/data_sources/data_source_google_container_cluster.go +++ b/mmv1/third_party/terraform/data_sources/data_source_google_container_cluster.go @@ -1,6 +1,8 @@ package google import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -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 }