Skip to content

Commit bb1661f

Browse files
committed
chore: add StackDeploymentGroupsSummary resource
1 parent 03d63d1 commit bb1661f

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

stack_deployment_groups_summary.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package tfe
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/url"
7+
)
8+
9+
type StackDeploymentGroupSummaries interface {
10+
// List lists all the stack configuration summaries for a stack.
11+
List(ctx context.Context, configurationID string, options *StackDeploymentGroupSummaryListOptions) (*StackDeploymentGroupSummaryList, error)
12+
}
13+
14+
type stackDeploymentGroupSummaries struct {
15+
client *Client
16+
}
17+
18+
var _ StackDeploymentGroupSummaries = &stackDeploymentGroupSummaries{}
19+
20+
type StackDeploymentGroupSummaryList struct {
21+
*Pagination
22+
Items []*StackDeploymentGroupSummary
23+
}
24+
25+
type StackDeploymentGroupSummaryListOptions struct {
26+
ListOptions
27+
}
28+
29+
type StackDeploymentGroupStatusCounts struct {
30+
Pending int `jsonapi:"attr,pending"`
31+
PreDeploying int `jsonapi:"attr,pre-deploying"`
32+
PreDeployingPendingOperator int `jsonapi:"attr,pending-operator"`
33+
AcquiringLock int `jsonapi:"attr,acquiring-lock"`
34+
Deploying int `jsonapi:"attr,deploying"`
35+
Succeeded int `jsonapi:"attr,succeeded"`
36+
Failed int `jsonapi:"attr,failed"`
37+
Abandoned int `jsonapi:"attr,abandoned"`
38+
}
39+
40+
type StackDeploymentGroupSummary struct {
41+
ID string `jsonapi:"primary,stack-deployment-group-summaries"`
42+
43+
// Attributes
44+
Name string `jsonapi:"attr,name"`
45+
Status string `jsonapi:"attr,status"`
46+
StatusCounts *StackDeploymentGroupStatusCounts `jsonapi:"attr,status-counts"`
47+
48+
// Relationships
49+
StackDeploymentGroup *StackDeploymentGroup `jsonapi:"relation,stack-deployment-group"`
50+
}
51+
52+
func (s stackDeploymentGroupSummaries) List(ctx context.Context, stackID string, options *StackDeploymentGroupSummaryListOptions) (*StackDeploymentGroupSummaryList, error) {
53+
if !validStringID(&stackID) {
54+
return nil, fmt.Errorf("invalid stack ID: %s", stackID)
55+
}
56+
57+
if options == nil {
58+
options = &StackDeploymentGroupSummaryListOptions{}
59+
}
60+
61+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-group-summaries", url.PathEscape(stackID)), options)
62+
if err != nil {
63+
return nil, err
64+
}
65+
66+
scl := &StackDeploymentGroupSummaryList{}
67+
err = req.Do(ctx, scl)
68+
if err != nil {
69+
return nil, err
70+
}
71+
72+
return scl, nil
73+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package tfe
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestStackDeploymentGroupSummaryList(t *testing.T) {
15+
skipUnlessBeta(t)
16+
17+
client := testClient(t)
18+
ctx := context.Background()
19+
20+
orgTest, orgTestCleanup := createOrganization(t, client)
21+
t.Cleanup(orgTestCleanup)
22+
23+
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
24+
t.Cleanup(cleanup)
25+
26+
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
27+
Name: "aa-test-stack",
28+
VCSRepo: &StackVCSRepoOptions{
29+
Identifier: "ctrombley/linked-stacks-demo-network",
30+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
31+
},
32+
Project: &Project{
33+
ID: orgTest.DefaultProject.ID,
34+
},
35+
})
36+
require.NoError(t, err)
37+
require.NotNil(t, stack)
38+
stack2, err := client.Stacks.Create(ctx, StackCreateOptions{
39+
Name: "bb-test-stack",
40+
VCSRepo: &StackVCSRepoOptions{
41+
Identifier: "ctrombley/linked-stacks-demo-network",
42+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
43+
},
44+
Project: &Project{
45+
ID: orgTest.DefaultProject.ID,
46+
},
47+
})
48+
require.NoError(t, err)
49+
require.NotNil(t, stack2)
50+
51+
// Trigger first stack configuration with a fetch
52+
_, err = client.Stacks.FetchConfiguration(ctx, stack.ID)
53+
require.NoError(t, err)
54+
55+
updatedStack := pollStackDeploymentGroups(t, ctx, client, stack.ID)
56+
require.NotNil(t, updatedStack.LatestStackConfiguration.ID)
57+
58+
// Trigger second stack configuration with a fetch
59+
_, err = client.Stacks.FetchConfiguration(ctx, stack2.ID)
60+
require.NoError(t, err)
61+
62+
updatedStack2 := pollStackDeploymentGroups(t, ctx, client, stack2.ID)
63+
require.NotNil(t, updatedStack2.LatestStackConfiguration.ID)
64+
65+
t.Run("Successful multiple deployment group summary list", func(t *testing.T) {
66+
stackConfigSummaryList, err := client.StackDeploymentGroupSummaries.List(ctx, updatedStack2.LatestStackConfiguration.ID, nil)
67+
require.NoError(t, err)
68+
69+
assert.Len(t, stackConfigSummaryList.Items, 2)
70+
})
71+
72+
t.Run("Unsuccessful list", func(t *testing.T) {
73+
_, err := client.StackDeploymentGroupSummaries.List(ctx, "", nil)
74+
require.Error(t, err)
75+
})
76+
}

tfe.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ type Client struct {
168168
StackConfigurations StackConfigurations
169169
StackConfigurationSummaries StackConfigurationSummaries
170170
StackDeploymentGroups StackDeploymentGroups
171+
StackDeploymentGroupSummaries StackDeploymentGroupSummaries
171172
StackDeploymentRuns StackDeploymentRuns
172173
StackDeploymentSteps StackDeploymentSteps
173174
StateVersionOutputs StateVersionOutputs
@@ -499,6 +500,7 @@ func NewClient(cfg *Config) (*Client, error) {
499500
client.StackConfigurations = &stackConfigurations{client: client}
500501
client.StackConfigurationSummaries = &stackConfigurationSummaries{client: client}
501502
client.StackDeploymentGroups = &stackDeploymentGroups{client: client}
503+
client.StackDeploymentGroupSummaries = &stackDeploymentGroupSummaries{client: client}
502504
client.StackDeploymentRuns = &stackDeploymentRuns{client: client}
503505
client.StackDeploymentSteps = &stackDeploymentSteps{client: client}
504506
client.StateVersionOutputs = &stateVersionOutputs{client: client}

0 commit comments

Comments
 (0)