Skip to content

Commit

Permalink
throw error if datasource not found (#6786) (#13070)
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>
Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Edward Sun <sunedward@google.com>
  • Loading branch information
modular-magician and Edward Sun committed Nov 17, 2022
1 parent c2514e8 commit 6c62647
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6786.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: throw exception if the data source `google_container_cluster` does not exist
```
16 changes: 14 additions & 2 deletions google/data_source_google_container_cluster.go
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 6c62647

Please sign in to comment.