From 3839e54093deef6adf6e432826f9dfc63d842675 Mon Sep 17 00:00:00 2001 From: Emily Ye Date: Mon, 5 Aug 2019 11:02:06 -0700 Subject: [PATCH] fixes --- .../data_sources/data_source_google_folder.go | 13 +++++-------- .../terraform/resources/resource_google_folder.go | 8 +++++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/third_party/terraform/data_sources/data_source_google_folder.go b/third_party/terraform/data_sources/data_source_google_folder.go index 0a537a5caf20..544df3c3ab5c 100644 --- a/third_party/terraform/data_sources/data_source_google_folder.go +++ b/third_party/terraform/data_sources/data_source_google_folder.go @@ -5,8 +5,6 @@ import ( "strings" "github.com/hashicorp/terraform/helper/schema" - - resourceManagerV2Beta1 "google.golang.org/api/cloudresourcemanager/v2beta1" ) func dataSourceGoogleFolder() *schema.Resource { @@ -63,7 +61,7 @@ func dataSourceFolderRead(d *schema.ResourceData, meta interface{}) error { } if v, ok := d.GetOk("lookup_organization"); ok && v.(bool) { - organization, err := lookupOrganizationName(folder, config) + organization, err := lookupOrganizationName(d.Id(), d, config) if err != nil { return err } @@ -82,17 +80,16 @@ func canonicalFolderName(ba string) string { return "folders/" + ba } -func lookupOrganizationName(folder *resourceManagerV2Beta1.Folder, config *Config) (string, error) { - parent := folder.Parent +func lookupOrganizationName(parent string, d *schema.ResourceData, config *Config) (string, error) { if parent == "" || strings.HasPrefix(parent, "organizations/") { return parent, nil } else if strings.HasPrefix(parent, "folders/") { - parentFolder, err := getGoogleFolder(parent, config).Do() + parentFolder, err := getGoogleFolder(parent, d, config) if err != nil { return "", fmt.Errorf("Error getting parent folder '%s': %s", parent, err) } - return lookupOrganizationName(parentFolder, config) + return lookupOrganizationName(parentFolder.Parent, d, config) } else { - return "", fmt.Errorf("Unknown parent type '%s' on folder '%s'", parent, folder.Name) + return "", fmt.Errorf("Unknown parent type '%s' on folder '%s'", parent, d.Id()) } } diff --git a/third_party/terraform/resources/resource_google_folder.go b/third_party/terraform/resources/resource_google_folder.go index 57b4e674bb3e..426bda69346c 100644 --- a/third_party/terraform/resources/resource_google_folder.go +++ b/third_party/terraform/resources/resource_google_folder.go @@ -108,7 +108,7 @@ func resourceGoogleFolderCreate(d *schema.ResourceData, meta interface{}) error func resourceGoogleFolderRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) - folder, err := getGoogleFolder(d, config) + folder, err := getGoogleFolder(d.Id(), d, config) if err != nil { return handleNotFoundError(err, d, d.Id()) } @@ -200,11 +200,13 @@ func resourceGoogleFolderImportState(d *schema.ResourceData, m interface{}) ([]* return []*schema.ResourceData{d}, nil } -func getGoogleFolder(d *schema.ResourceData, config *Config) (*resourceManagerV2Beta1.Folder, error){ +// Util to get a Folder resource from API. Note that folder described by name is not necessarily the +// ResourceData resource. +func getGoogleFolder(folderName string, d *schema.ResourceData, config *Config) (*resourceManagerV2Beta1.Folder, error){ var folder *resourceManagerV2Beta1.Folder err := retryTimeDuration(func() error { var reqErr error - folder, reqErr = config.clientResourceManagerV2Beta1.Folders.Get(d.Id()).Do() + folder, reqErr = config.clientResourceManagerV2Beta1.Folders.Get(folderName).Do() return reqErr }, d.Timeout(schema.TimeoutRead)) if err != nil {