Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1260.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
Group operations (create, delete, update, update members) now block client-side if an operationID is present in the response.
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/hcp-sdk-go v0.140.0
github.com/hashicorp/hcp-sdk-go v0.141.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.14.1
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/hashicorp/hc-install v0.9.1 h1:gkqTfE3vVbafGQo6VZXcy2v5yoz2bE0+nhZXru
github.com/hashicorp/hc-install v0.9.1/go.mod h1:pWWvN/IrfeBK4XPeXXYkL6EjMufHkCK5DvwxeLKuBf0=
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
github.com/hashicorp/hcp-sdk-go v0.140.0 h1:SUbzlp7SfMwEFQXHhgq5CRVvfOkc7QrBM1CDk9OvW2M=
github.com/hashicorp/hcp-sdk-go v0.140.0/go.mod h1:ZxsZZjErm3E2sj2OjDeVsGJAkWtcRLUS+FrNLGPsUyw=
github.com/hashicorp/hcp-sdk-go v0.141.0 h1:5bRZa54gI4KYWceKWcZJwhy8ZV32ZdqUDLUa6ftUWBQ=
github.com/hashicorp/hcp-sdk-go v0.141.0/go.mod h1:ZxsZZjErm3E2sj2OjDeVsGJAkWtcRLUS+FrNLGPsUyw=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/terraform-exec v0.22.0 h1:G5+4Sz6jYZfRYUCg6eQgDsqTzkNXV+fP8l+uRmZHj64=
Expand Down
37 changes: 33 additions & 4 deletions internal/clients/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package clients

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

"github.com/hashicorp/hcp-sdk-go/clients/cloud-iam/stable/2019-12-10/client/groups_service"
)
Expand All @@ -19,7 +20,14 @@ func CreateGroupRetry(client *Client, params *groups_service.GroupsServiceCreate
op := func() error {
var err error
res, err = client.Groups.GroupsServiceCreateGroup(params, nil)
return err
if err != nil {
return err
}
if res.Payload.OperationID != "" {
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
return WaitForOperation(params.Context, client, "create group", loc, res.Payload.OperationID)
}
return nil
}

serviceErr := &groups_service.GroupsServiceCreateGroupDefault{}
Expand All @@ -34,7 +42,14 @@ func UpdateGroupRetry(client *Client, params *groups_service.GroupsServiceUpdate
op := func() error {
var err error
res, err = client.Groups.GroupsServiceUpdateGroup2(params, nil)
return err
if err != nil {
return err
}
if res.Payload.OperationID != "" {
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
return WaitForOperation(params.Context, client, "update group", loc, res.Payload.OperationID)
}
return nil
}

serviceErr := &groups_service.GroupsServiceUpdateGroup2Default{}
Expand All @@ -49,7 +64,14 @@ func DeleteGroupRetry(client *Client, params *groups_service.GroupsServiceDelete
op := func() error {
var err error
res, err = client.Groups.GroupsServiceDeleteGroup(params, nil)
return err
if err != nil {
return err
}
if res.Payload.OperationID != "" {
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
return WaitForOperation(params.Context, client, "delete group", loc, res.Payload.OperationID)
}
return nil
}

serviceErr := &groups_service.GroupsServiceDeleteGroupDefault{}
Expand All @@ -66,7 +88,14 @@ func UpdateGroupMembersRetry(client *Client, params *groups_service.GroupsServic
op := func() error {
var err error
res, err = client.Groups.GroupsServiceUpdateGroupMembers(params, nil)
return err
if err != nil {
return err
}
if res.Payload.OperationID != "" {
loc := &sharedmodels.HashicorpCloudLocationLocation{OrganizationID: client.Config.OrganizationID}
return WaitForOperation(params.Context, client, "update group members", loc, res.Payload.OperationID)
}
return nil
}

serviceErr := &groups_service.GroupsServiceUpdateGroupMembersDefault{}
Expand Down
6 changes: 5 additions & 1 deletion internal/clients/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func WaitForOperation(ctx context.Context, client *Client, operationName string,
waitParams.ID = operationID
waitParams.Timeout = &waitTimeout
waitParams.LocationOrganizationID = loc.OrganizationID
waitParams.LocationProjectID = loc.ProjectID
if loc.ProjectID == "" {
waitParams.LocationProjectID = "-"
} else {
waitParams.LocationProjectID = loc.ProjectID
}
Comment on lines +32 to +36
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: save an else by defaulting to "-" and setting when non ""


// Start with no consecutive errors.
consecutiveErrors := 0
Expand Down
Loading