Skip to content

Commit 5aecfdd

Browse files
Merge pull request #1137 from hashicorp/hw/approve-deployment-group
Added support for approving all plans in a `StackDeploymentGroup`
2 parents 95b83f4 + 9f56096 commit 5aecfdd

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Adds BETA support for approving all plans for a stack deployment run, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @ctrombley [#1136](https://github.com/hashicorp/go-tfe/pull/1136)
66
* Adds BETA support for listing and reading `StackDeploymentSteps`, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @ctrombley [#1133](https://github.com/hashicorp/go-tfe/pull/1133)
7+
* Adds BETA support for approving all plans in `StackDeploymentGroups`, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @hwatkins05-hashicorp [#1137](https://github.com/hashicorp/go-tfe/pull/1137)
78

89
# v1.83.0
910

stack_deployment_groups.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type StackDeploymentGroups interface {
1717

1818
// Read retrieves a stack deployment group by its ID.
1919
Read(ctx context.Context, stackDeploymentGroupID string) (*StackDeploymentGroup, error)
20+
21+
// ApproveAllPlans approves all pending plans in a stack deployment group.
22+
ApproveAllPlans(ctx context.Context, stackDeploymentGroupID string) error
2023
}
2124

2225
type DeploymentGroupStatus string
@@ -103,3 +106,17 @@ func (s stackDeploymentGroups) Read(ctx context.Context, stackDeploymentGroupID
103106

104107
return sdg, nil
105108
}
109+
110+
// ApproveAllPlans approves all pending plans in a stack deployment group.
111+
func (s stackDeploymentGroups) ApproveAllPlans(ctx context.Context, stackDeploymentGroupID string) error {
112+
if !validStringID(&stackDeploymentGroupID) {
113+
return fmt.Errorf("invalid stack deployment group ID: %s", stackDeploymentGroupID)
114+
}
115+
116+
req, err := s.client.NewRequest("POST", fmt.Sprintf("stack-deployment-groups/%s/approve-all-plans", url.PathEscape(stackDeploymentGroupID)), nil)
117+
if err != nil {
118+
return err
119+
}
120+
121+
return req.Do(ctx, nil)
122+
}

stack_deployment_groups_integration_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,50 @@ func TestStackDeploymentGroupsRead(t *testing.T) {
124124
require.Error(t, err)
125125
})
126126
}
127+
128+
func TestStackDeploymentGroupsApproveAllPlans(t *testing.T) {
129+
skipUnlessBeta(t)
130+
131+
client := testClient(t)
132+
ctx := context.Background()
133+
134+
orgTest, orgTestCleanup := createOrganization(t, client)
135+
t.Cleanup(orgTestCleanup)
136+
137+
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
138+
t.Cleanup(cleanup)
139+
140+
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
141+
Name: "test-stack",
142+
VCSRepo: &StackVCSRepoOptions{
143+
Identifier: "hashicorp-guides/pet-nulls-stack",
144+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
145+
Branch: "main",
146+
},
147+
Project: &Project{
148+
ID: orgTest.DefaultProject.ID,
149+
},
150+
})
151+
require.NoError(t, err)
152+
require.NotNil(t, stack)
153+
154+
stackUpdated, err := client.Stacks.UpdateConfiguration(ctx, stack.ID)
155+
require.NoError(t, err)
156+
require.NotNil(t, stackUpdated)
157+
158+
stack = pollStackDeployments(t, ctx, client, stackUpdated.ID)
159+
require.NotNil(t, stack.LatestStackConfiguration)
160+
161+
// Get the deployment group ID from the stack configuration
162+
deploymentGroups, err := client.StackDeploymentGroups.List(ctx, stack.LatestStackConfiguration.ID, nil)
163+
require.NoError(t, err)
164+
require.NotNil(t, deploymentGroups)
165+
require.NotEmpty(t, deploymentGroups.Items)
166+
167+
deploymentGroupID := deploymentGroups.Items[0].ID
168+
169+
t.Run("Approving all plans", func(t *testing.T) {
170+
err := client.StackDeploymentGroups.ApproveAllPlans(ctx, deploymentGroupID)
171+
require.NoError(t, err)
172+
})
173+
}

0 commit comments

Comments
 (0)