Skip to content

Commit

Permalink
Follow user project override settings in Cloud Identity datasources (h…
Browse files Browse the repository at this point in the history
…ashicorp#4612) (hashicorp#3081)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 24, 2021
1 parent 6d41e0a commit 8d9a702
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/4612.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudidentity: `google_cloud_identity_groups` and `google_cloud_identity_group_memberships ` will respect the `user_project_override` and `billing_project` configurations and send the appropriate headers to establish a quota project
```
19 changes: 18 additions & 1 deletion google-beta/data_source_cloud_identity_group_memberships.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,25 @@ func dataSourceGoogleCloudIdentityGroupMembershipsRead(d *schema.ResourceData, m
}

result := []map[string]interface{}{}
err = config.NewCloudIdentityClient(userAgent).Groups.Memberships.List(d.Get("group").(string)).View("FULL").Pages(config.context, func(resp *cloudidentity.ListMembershipsResponse) error {
membershipsCall := config.NewCloudIdentityClient(userAgent).Groups.Memberships.List(d.Get("group").(string)).View("FULL")
if config.UserProjectOverride {
billingProject := ""
// err may be nil - project isn't required for this resource
if project, err := getProject(d, config); err == nil {
billingProject = project
}

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

if billingProject != "" {
membershipsCall.Header().Set("X-Goog-User-Project", billingProject)
}
}

err = membershipsCall.Pages(config.context, func(resp *cloudidentity.ListMembershipsResponse) error {
for _, member := range resp.Memberships {
result = append(result, map[string]interface{}{
"name": member.Name,
Expand Down
19 changes: 18 additions & 1 deletion google-beta/data_source_cloud_identity_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,24 @@ func dataSourceGoogleCloudIdentityGroupsRead(d *schema.ResourceData, meta interf
}

result := []map[string]interface{}{}
err = config.NewCloudIdentityClient(userAgent).Groups.List().Parent(d.Get("parent").(string)).View("FULL").Pages(config.context, func(resp *cloudidentity.ListGroupsResponse) error {
groupsCall := config.NewCloudIdentityClient(userAgent).Groups.List().Parent(d.Get("parent").(string)).View("FULL")
if config.UserProjectOverride {
billingProject := ""
// err may be nil - project isn't required for this resource
if project, err := getProject(d, config); err == nil {
billingProject = project
}

// err == nil indicates that the billing_project value was found
if bp, err := getBillingProject(d, config); err == nil {
billingProject = bp
}

if billingProject != "" {
groupsCall.Header().Set("X-Goog-User-Project", billingProject)
}
}
err = groupsCall.Pages(config.context, func(resp *cloudidentity.ListGroupsResponse) error {
for _, group := range resp.Groups {
result = append(result, map[string]interface{}{
"name": group.Name,
Expand Down
3 changes: 1 addition & 2 deletions google-beta/resource_dataproc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"google.golang.org/api/googleapi"

dataproc "google.golang.org/api/dataproc/v1beta2"
"google.golang.org/api/googleapi"
)

func TestDataprocExtractInitTimeout(t *testing.T) {
Expand Down

0 comments on commit 8d9a702

Please sign in to comment.