Skip to content

Commit efd1958

Browse files
Setup request for listing deployment groups
1 parent 3b35abc commit efd1958

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

stack_deployment_groups.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package tfe
2+
3+
import (
4+
"context"
5+
"fmt"
6+
)
7+
8+
type StackDeploymentGroups interface {
9+
// List returns a list of Deployment Groups in a stack.
10+
List(ctx context.Context, stackConfigID string) (*StackDeploymentGroupList, error)
11+
}
12+
13+
type DeploymentGroupStatus string
14+
15+
const (
16+
DeploymentGroupStatusPending DeploymentGroupStatus = "pending"
17+
DeploymentGroupStatusDeploying DeploymentGroupStatus = "deploying"
18+
DeploymentGroupStatusSucceeded DeploymentGroupStatus = "succeeded"
19+
DeploymentGroupStatusFailed DeploymentGroupStatus = "failed"
20+
DeploymentGroupStatusAbandoned DeploymentGroupStatus = "abandoned"
21+
)
22+
23+
var DeploymentGroupStatuses = []DeploymentGroupStatus{
24+
DeploymentGroupStatusPending,
25+
DeploymentGroupStatusDeploying,
26+
DeploymentGroupStatusSucceeded,
27+
DeploymentGroupStatusFailed,
28+
DeploymentGroupStatusAbandoned,
29+
}
30+
31+
type stackDeploymentGroups struct {
32+
client *Client
33+
}
34+
35+
var _ StackDeploymentGroups = &stackDeploymentGroups{}
36+
37+
type StackDeploymentGroup struct {
38+
Id string
39+
Name string
40+
Status DeploymentGroupStatus
41+
CreatedAt string
42+
UpdatedAt string // time.RFC3339
43+
StackConfigurationId string
44+
FailureCount int
45+
}
46+
47+
// StackDeploymentGroupList represents a list of stack deployment groups.
48+
type StackDeploymentGroupList struct {
49+
*Pagination
50+
Items []*StackDeploymentGroup
51+
}
52+
53+
func (s stackDeploymentGroups) List(ctx context.Context, stackConfigID string) (*StackDeploymentGroupList, error) {
54+
if !validStringID(&stackConfigID) {
55+
return nil, fmt.Errorf("invalid stack configuration ID: %s", stackConfigID)
56+
}
57+
58+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-groups", stackConfigID), nil)
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
sdgl := &StackDeploymentGroupList{}
64+
err = req.Do(ctx, sdgl)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
return sdgl, nil
70+
}

tfe.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ type Client struct {
164164
Stacks Stacks
165165
StackConfigurations StackConfigurations
166166
StackDeployments StackDeployments
167+
StackDeploymentGroups StackDeploymentGroups
167168
StackPlans StackPlans
168169
StackPlanOperations StackPlanOperations
169170
StackSources StackSources
@@ -492,6 +493,7 @@ func NewClient(cfg *Config) (*Client, error) {
492493
client.Stacks = &stacks{client: client}
493494
client.StackConfigurations = &stackConfigurations{client: client}
494495
client.StackDeployments = &stackDeployments{client: client}
496+
client.StackDeploymentGroups = &stackDeploymentGroups{client: client}
495497
client.StackPlans = &stackPlans{client: client}
496498
client.StackPlanOperations = &stackPlanOperations{client: client}
497499
client.StackSources = &stackSources{client: client}

0 commit comments

Comments
 (0)