Skip to content

Commit

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

fixes hashicorp#9368

* Document container_cluster user_project_override

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jun 15, 2021
1 parent b62053e commit f9c5a58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 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/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
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 f9c5a58

Please sign in to comment.