Skip to content

Commit 68fc9b1

Browse files
authored
feat: add method to approve all plans for a stack deployment run (#1136)
* feat: add method to approve all plans for a stack deployment run * chore: update changelog
1 parent 4df1be7 commit 68fc9b1

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
## Enhancements
4+
5+
* 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)
6+
37
# v1.83.0
48

59
## Enhancements

stack_deployment_runs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type StackDeploymentRuns interface {
1515
// List returns a list of stack deployment runs for a given deployment group.
1616
List(ctx context.Context, deploymentGroupID string, options *StackDeploymentRunListOptions) (*StackDeploymentRunList, error)
17+
ApproveAllPlans(ctx context.Context, deploymentRunID string) error
1718
}
1819

1920
// stackDeploymentRuns implements StackDeploymentRuns.
@@ -60,3 +61,12 @@ func (s *stackDeploymentRuns) List(ctx context.Context, deploymentGroupID string
6061

6162
return sdrl, nil
6263
}
64+
65+
func (s stackDeploymentRuns) ApproveAllPlans(ctx context.Context, stackDeploymentRunID string) error {
66+
req, err := s.client.NewRequest("POST", fmt.Sprintf("stack-deployment-runs/%s/approve-all-plans", url.PathEscape(stackDeploymentRunID)), nil)
67+
if err != nil {
68+
return err
69+
}
70+
71+
return req.Do(ctx, nil)
72+
}

stack_deployment_runs_integration_test.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
func TestStackDeploymentRunList(t *testing.T) {
14+
func TestStackDeploymentRunsList(t *testing.T) {
1515
skipUnlessBeta(t)
1616

1717
client := testClient(t)
@@ -72,3 +72,59 @@ func TestStackDeploymentRunList(t *testing.T) {
7272
assert.NotNil(t, runList)
7373
})
7474
}
75+
76+
func TestStackDeploymentRunsApproveAllPlans(t *testing.T) {
77+
skipUnlessBeta(t)
78+
79+
client := testClient(t)
80+
ctx := context.Background()
81+
82+
orgTest, orgTestCleanup := createOrganization(t, client)
83+
t.Cleanup(orgTestCleanup)
84+
85+
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
86+
t.Cleanup(cleanup)
87+
88+
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
89+
Name: "test-stack",
90+
VCSRepo: &StackVCSRepoOptions{
91+
// Identifier: "hashicorp-guides/pet-nulls-stack",
92+
Identifier: "ctrombley/tf-stacks-pet-nulls",
93+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
94+
Branch: "main",
95+
},
96+
Project: &Project{
97+
ID: orgTest.DefaultProject.ID,
98+
},
99+
})
100+
require.NoError(t, err)
101+
require.NotNil(t, stack)
102+
103+
stackUpdated, err := client.Stacks.UpdateConfiguration(ctx, stack.ID)
104+
require.NoError(t, err)
105+
require.NotNil(t, stackUpdated)
106+
107+
stack = pollStackDeployments(t, ctx, client, stackUpdated.ID)
108+
require.NotNil(t, stack.LatestStackConfiguration)
109+
110+
// Get the deployment group ID from the stack configuration
111+
deploymentGroups, err := client.StackDeploymentGroups.List(ctx, stack.LatestStackConfiguration.ID, nil)
112+
require.NoError(t, err)
113+
require.NotNil(t, deploymentGroups)
114+
require.NotEmpty(t, deploymentGroups.Items)
115+
116+
deploymentGroupID := deploymentGroups.Items[0].ID
117+
118+
runList, err := client.StackDeploymentRuns.List(ctx, deploymentGroupID, nil)
119+
require.NoError(t, err)
120+
assert.NotNil(t, runList)
121+
122+
deploymentRunID := runList.Items[0].ID
123+
124+
t.Run("Approve all plans", func(t *testing.T) {
125+
t.Parallel()
126+
127+
err := client.StackDeploymentRuns.ApproveAllPlans(ctx, deploymentRunID)
128+
require.NoError(t, err)
129+
})
130+
}

0 commit comments

Comments
 (0)