-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathstack_deployment_groups.go
More file actions
101 lines (81 loc) · 3.17 KB
/
stack_deployment_groups.go
File metadata and controls
101 lines (81 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package tfe
import (
"context"
"fmt"
"net/url"
"time"
)
// StackDeploymentGroups describes all the stack-deployment-groups related methods that the HCP Terraform API supports.
type StackDeploymentGroups interface {
// List returns a list of Deployment Groups in a stack.
List(ctx context.Context, stackConfigID string, options *StackDeploymentGroupListOptions) (*StackDeploymentGroupList, error)
// Read retrieves a stack deployment group by its ID.
Read(ctx context.Context, stackDeploymentGroupID string) (*StackDeploymentGroup, error)
}
type DeploymentGroupStatus string
const (
DeploymentGroupStatusPending DeploymentGroupStatus = "pending"
DeploymentGroupStatusDeploying DeploymentGroupStatus = "deploying"
DeploymentGroupStatusSucceeded DeploymentGroupStatus = "succeeded"
DeploymentGroupStatusFailed DeploymentGroupStatus = "failed"
DeploymentGroupStatusAbandoned DeploymentGroupStatus = "abandoned"
)
// stackDeploymentGroups implements StackDeploymentGroups.
type stackDeploymentGroups struct {
client *Client
}
var _ StackDeploymentGroups = &stackDeploymentGroups{}
// StackDeploymentGroup represents a stack deployment group.
type StackDeploymentGroup struct {
ID string `jsonapi:"primary,stacks-deployment-groups"`
Name string `jsonapi:"attr,name"`
Status string `jsonapi:"attr,status"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
// Relationships
StackConfiguration *StackConfiguration `jsonapi:"relation,stack-configuration"`
}
// StackDeploymentGroupList represents a list of stack deployment groups.
type StackDeploymentGroupList struct {
*Pagination
Items []*StackDeploymentGroup
}
// StackDeploymentGroupListOptions represents additional options when listing stack deployment groups.
type StackDeploymentGroupListOptions struct {
ListOptions
}
// List returns a list of Deployment Groups in a stack, optionally filtered by additional parameters.
func (s stackDeploymentGroups) List(ctx context.Context, stackConfigID string, options *StackDeploymentGroupListOptions) (*StackDeploymentGroupList, error) {
if !validStringID(&stackConfigID) {
return nil, fmt.Errorf("invalid stack configuration ID: %s", stackConfigID)
}
if options == nil {
options = &StackDeploymentGroupListOptions{}
}
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-groups", url.PathEscape(stackConfigID)), options)
if err != nil {
return nil, err
}
sdgl := &StackDeploymentGroupList{}
err = req.Do(ctx, sdgl)
if err != nil {
return nil, err
}
return sdgl, nil
}
// Read retrieves a stack deployment group by its ID.
func (s stackDeploymentGroups) Read(ctx context.Context, stackDeploymentGroupID string) (*StackDeploymentGroup, error) {
if !validStringID(&stackDeploymentGroupID) {
return nil, fmt.Errorf("invalid stack deployment group ID: %s", stackDeploymentGroupID)
}
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-deployment-groups/%s", url.PathEscape(stackDeploymentGroupID)), nil)
if err != nil {
return nil, err
}
sdg := &StackDeploymentGroup{}
err = req.Do(ctx, sdg)
if err != nil {
return nil, err
}
return sdg, nil
}