Skip to content

Commit

Permalink
Escape folder display name with string quotes rather than query escap…
Browse files Browse the repository at this point in the history
…ing. (#4032) (#2528)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 30, 2020
1 parent 211f41b commit 1276685
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/4032.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resourcemanager: Fixed a bug in retrieving `google_active_folder` data source when the display name included whitespace
```
3 changes: 1 addition & 2 deletions google-beta/data_source_google_active_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package google

import (
"fmt"
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
resourceManagerV2Beta1 "google.golang.org/api/cloudresourcemanager/v2beta1"
Expand Down Expand Up @@ -40,7 +39,7 @@ func dataSourceGoogleActiveFolderRead(d *schema.ResourceData, meta interface{})
parent := d.Get("parent").(string)
displayName := d.Get("display_name").(string)

queryString := fmt.Sprintf("lifecycleState=ACTIVE AND parent=%s AND displayName=%s", parent, url.QueryEscape(displayName))
queryString := fmt.Sprintf("lifecycleState=ACTIVE AND parent=%s AND displayName=\"%s\"", parent, displayName)
searchRequest := &resourceManagerV2Beta1.SearchFoldersRequest{
Query: queryString,
}
Expand Down
20 changes: 20 additions & 0 deletions google-beta/data_source_google_active_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ func TestAccDataSourceGoogleActiveFolder_space(t *testing.T) {
})
}

func TestAccDataSourceGoogleActiveFolder_dash(t *testing.T) {
org := getTestOrgFromEnv(t)

parent := fmt.Sprintf("organizations/%s", org)
displayName := "terraform - test " + randString(t, 10)

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleActiveFolderConfig(parent, displayName),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceGoogleActiveFolderCheck("data.google_active_folder.my_folder", "google_folder.foobar"),
),
},
},
})
}

func testAccDataSourceGoogleActiveFolderCheck(data_source_name string, resource_name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ds, ok := s.RootModule().Resources[data_source_name]
Expand Down

0 comments on commit 1276685

Please sign in to comment.