Skip to content

Commit

Permalink
UserProjectOverride for ContainerOperationWaiter (#4874) (#3345)
Browse files Browse the repository at this point in the history
* UserProjectOverride for ContainerOperationWaiter

fixes hashicorp/terraform-provider-google#9368

* Document container_cluster user_project_override

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jun 15, 2021
1 parent 2a8a585 commit f7f6a0b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .changelog/4874.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: Added `user_project_override` support to the ContainerOperationWaiter used by `google_container_cluster`
```
28 changes: 17 additions & 11 deletions google-beta/container_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

type ContainerOperationWaiter struct {
Service *container.Service
Context context.Context
Op *container.Operation
Project string
Location string
Service *container.Service
Context context.Context
Op *container.Operation
Project string
Location string
UserProjectOverride bool
}

func (w *ContainerOperationWaiter) State() string {
Expand Down Expand Up @@ -75,7 +76,11 @@ func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) {
// default must be here to keep the previous case from blocking
}
err := retryTimeDuration(func() (opErr error) {
op, opErr = w.Service.Projects.Locations.Operations.Get(name).Do()
opGetCall := w.Service.Projects.Locations.Operations.Get(name)
if w.UserProjectOverride {
opGetCall.Header().Add("X-Goog-User-Project", w.Project)
}
op, opErr = opGetCall.Do()
return opErr
}, DefaultRequestTimeout)

Expand All @@ -99,11 +104,12 @@ func (w *ContainerOperationWaiter) TargetStates() []string {

func containerOperationWait(config *Config, op *container.Operation, project, location, activity, userAgent string, timeout time.Duration) error {
w := &ContainerOperationWaiter{
Service: config.NewContainerBetaClient(userAgent),
Context: config.context,
Op: op,
Project: project,
Location: location,
Service: config.NewContainerBetaClient(userAgent),
Context: config.context,
Op: op,
Project: project,
Location: location,
UserProjectOverride: config.UserProjectOverride,
}

if err := w.SetOp(op); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_gke_hub_feature_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -947,3 +947,7 @@ For example, the following fields will show diffs if set in config:

- `min_master_version`
- `remove_default_node_pool`

## User Project Overrides

This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).

0 comments on commit f7f6a0b

Please sign in to comment.