Skip to content

Commit 15022cd

Browse files
ncabatoffyuriikomarss
authored andcommitted
Do client-side blocking for group operations with an operation id in response (hashicorp#1260)
1 parent cd50c35 commit 15022cd

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

.changelog/1260.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
Group operations (create, delete, update, update members) now block client-side if an operationID is present in the response.
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
1414
github.com/hashicorp/go-uuid v1.0.3
1515
github.com/hashicorp/go-version v1.7.0
16-
github.com/hashicorp/hcp-sdk-go v0.140.0
16+
github.com/hashicorp/hcp-sdk-go v0.141.0
1717
github.com/hashicorp/terraform-plugin-docs v0.20.1
1818
github.com/hashicorp/terraform-plugin-framework v1.14.1
1919
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ github.com/hashicorp/hc-install v0.9.1 h1:gkqTfE3vVbafGQo6VZXcy2v5yoz2bE0+nhZXru
126126
github.com/hashicorp/hc-install v0.9.1/go.mod h1:pWWvN/IrfeBK4XPeXXYkL6EjMufHkCK5DvwxeLKuBf0=
127127
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
128128
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
129-
github.com/hashicorp/hcp-sdk-go v0.140.0 h1:SUbzlp7SfMwEFQXHhgq5CRVvfOkc7QrBM1CDk9OvW2M=
130-
github.com/hashicorp/hcp-sdk-go v0.140.0/go.mod h1:ZxsZZjErm3E2sj2OjDeVsGJAkWtcRLUS+FrNLGPsUyw=
129+
github.com/hashicorp/hcp-sdk-go v0.141.0 h1:5bRZa54gI4KYWceKWcZJwhy8ZV32ZdqUDLUa6ftUWBQ=
130+
github.com/hashicorp/hcp-sdk-go v0.141.0/go.mod h1:ZxsZZjErm3E2sj2OjDeVsGJAkWtcRLUS+FrNLGPsUyw=
131131
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
132132
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
133133
github.com/hashicorp/terraform-exec v0.22.0 h1:G5+4Sz6jYZfRYUCg6eQgDsqTzkNXV+fP8l+uRmZHj64=

internal/clients/group.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package clients
55

66
import (
77
"github.com/cenkalti/backoff/v4"
8+
sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
89

910
"github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/groups_service"
1011
)
@@ -19,7 +20,14 @@ func CreateGroupRetry(client *Client, params *groups_service.GroupsServiceCreate
1920
op := func() error {
2021
var err error
2122
res, err = client.Groups.GroupsServiceCreateGroup(params, nil)
22-
return err
23+
if err != nil {
24+
return err
25+
}
26+
if res.Payload.OperationID != "" {
27+
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
28+
return WaitForOperation(params.Context, client, "create group", loc, res.Payload.OperationID)
29+
}
30+
return nil
2331
}
2432

2533
serviceErr := &groups_service.GroupsServiceCreateGroupDefault{}
@@ -34,7 +42,14 @@ func UpdateGroupRetry(client *Client, params *groups_service.GroupsServiceUpdate
3442
op := func() error {
3543
var err error
3644
res, err = client.Groups.GroupsServiceUpdateGroup2(params, nil)
37-
return err
45+
if err != nil {
46+
return err
47+
}
48+
if res.Payload.OperationID != "" {
49+
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
50+
return WaitForOperation(params.Context, client, "update group", loc, res.Payload.OperationID)
51+
}
52+
return nil
3853
}
3954

4055
serviceErr := &groups_service.GroupsServiceUpdateGroup2Default{}
@@ -49,7 +64,14 @@ func DeleteGroupRetry(client *Client, params *groups_service.GroupsServiceDelete
4964
op := func() error {
5065
var err error
5166
res, err = client.Groups.GroupsServiceDeleteGroup(params, nil)
52-
return err
67+
if err != nil {
68+
return err
69+
}
70+
if res.Payload.OperationID != "" {
71+
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
72+
return WaitForOperation(params.Context, client, "delete group", loc, res.Payload.OperationID)
73+
}
74+
return nil
5375
}
5476

5577
serviceErr := &groups_service.GroupsServiceDeleteGroupDefault{}
@@ -66,7 +88,14 @@ func UpdateGroupMembersRetry(client *Client, params *groups_service.GroupsServic
6688
op := func() error {
6789
var err error
6890
res, err = client.Groups.GroupsServiceUpdateGroupMembers(params, nil)
69-
return err
91+
if err != nil {
92+
return err
93+
}
94+
if res.Payload.OperationID != "" {
95+
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
96+
return WaitForOperation(params.Context, client, "update group members", loc, res.Payload.OperationID)
97+
}
98+
return nil
7099
}
71100

72101
serviceErr := &groups_service.GroupsServiceUpdateGroupMembersDefault{}

internal/clients/operation.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ func WaitForOperation(ctx context.Context, client *Client, operationName string,
2929
waitParams.ID = operationID
3030
waitParams.Timeout = &waitTimeout
3131
waitParams.LocationOrganizationID = loc.OrganizationID
32-
waitParams.LocationProjectID = loc.ProjectID
32+
if loc.ProjectID == "" {
33+
waitParams.LocationProjectID = "-"
34+
} else {
35+
waitParams.LocationProjectID = loc.ProjectID
36+
}
3337

3438
// Start with no consecutive errors.
3539
consecutiveErrors := 0

0 commit comments

Comments
 (0)