Skip to content

Commit f7f6a0b

Browse files
UserProjectOverride for ContainerOperationWaiter (#4874) (#3345)
* UserProjectOverride for ContainerOperationWaiter fixes hashicorp/terraform-provider-google#9368 * Document container_cluster user_project_override Signed-off-by: Modular Magician <[email protected]>
1 parent 2a8a585 commit f7f6a0b

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

.changelog/4874.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: Added `user_project_override` support to the ContainerOperationWaiter used by `google_container_cluster`
3+
```

google-beta/container_operation.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111
)
1212

1313
type ContainerOperationWaiter struct {
14-
Service *container.Service
15-
Context context.Context
16-
Op *container.Operation
17-
Project string
18-
Location string
14+
Service *container.Service
15+
Context context.Context
16+
Op *container.Operation
17+
Project string
18+
Location string
19+
UserProjectOverride bool
1920
}
2021

2122
func (w *ContainerOperationWaiter) State() string {
@@ -75,7 +76,11 @@ func (w *ContainerOperationWaiter) QueryOp() (interface{}, error) {
7576
// default must be here to keep the previous case from blocking
7677
}
7778
err := retryTimeDuration(func() (opErr error) {
78-
op, opErr = w.Service.Projects.Locations.Operations.Get(name).Do()
79+
opGetCall := w.Service.Projects.Locations.Operations.Get(name)
80+
if w.UserProjectOverride {
81+
opGetCall.Header().Add("X-Goog-User-Project", w.Project)
82+
}
83+
op, opErr = opGetCall.Do()
7984
return opErr
8085
}, DefaultRequestTimeout)
8186

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

100105
func containerOperationWait(config *Config, op *container.Operation, project, location, activity, userAgent string, timeout time.Duration) error {
101106
w := &ContainerOperationWaiter{
102-
Service: config.NewContainerBetaClient(userAgent),
103-
Context: config.context,
104-
Op: op,
105-
Project: project,
106-
Location: location,
107+
Service: config.NewContainerBetaClient(userAgent),
108+
Context: config.context,
109+
Op: op,
110+
Project: project,
111+
Location: location,
112+
UserProjectOverride: config.UserProjectOverride,
107113
}
108114

109115
if err := w.SetOp(op); err != nil {

google-beta/resource_gke_hub_feature_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
8+
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
99
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

website/docs/r/container_cluster.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,7 @@ For example, the following fields will show diffs if set in config:
947947

948948
- `min_master_version`
949949
- `remove_default_node_pool`
950+
951+
## User Project Overrides
952+
953+
This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override).

0 commit comments

Comments
 (0)