Skip to content

Commit 17bdfaa

Browse files
committed
chore: incorporate review feedback
1 parent a45a812 commit 17bdfaa

10 files changed

+97
-51
lines changed

stack.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type Stacks interface {
3232
// ForceDelete deletes a stack.
3333
ForceDelete(ctx context.Context, stackID string) error
3434

35-
// FetchConfiguration updates the configuration of a stack, triggering stack preparation.
36-
FetchConfiguration(ctx context.Context, stackID string) (*Stack, error)
35+
// FetchLatestFromVcs updates the configuration of a stack, triggering stack preparation.
36+
FetchLatestFromVcs(ctx context.Context, stackID string) (*Stack, error)
3737
}
3838

3939
// stacks implements Stacks.
@@ -202,8 +202,8 @@ type WaitForStatusResult struct {
202202
const minimumPollingIntervalMs = 3000
203203
const maximumPollingIntervalMs = 5000
204204

205-
// FetchConfiguration fetches the latest configuration of a stack from VCS, triggering stack operations
206-
func (s *stacks) FetchConfiguration(ctx context.Context, stackID string) (*Stack, error) {
205+
// FetchLatestFromVcs fetches the latest configuration of a stack from VCS, triggering stack operations
206+
func (s *stacks) FetchLatestFromVcs(ctx context.Context, stackID string) (*Stack, error) {
207207
req, err := s.client.NewRequest("POST", fmt.Sprintf("stacks/%s/fetch-latest-from-vcs", url.PathEscape(stackID)), nil)
208208
if err != nil {
209209
return nil, err

stack_configuration_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestStackConfigurationList(t *testing.T) {
2727
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2828
Name: "test-stack-list",
2929
VCSRepo: &StackVCSRepoOptions{
30-
Identifier: "ctrombley/linked-stacks-demo-network",
30+
Identifier: "hashicorp-guides/pet-nulls-stack",
3131
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3232
},
3333
Project: &Project{
@@ -37,12 +37,12 @@ func TestStackConfigurationList(t *testing.T) {
3737
require.NoError(t, err)
3838

3939
// Trigger first stack configuration by updating configuration
40-
_, err = client.Stacks.FetchConfiguration(ctx, stack.ID)
40+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
4141
require.NoError(t, err)
4242

4343
// Wait a bit and trigger second stack configuration
4444
time.Sleep(2 * time.Second)
45-
_, err = client.Stacks.FetchConfiguration(ctx, stack.ID)
45+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
4646
require.NoError(t, err)
4747

4848
list, err := client.StackConfigurations.List(ctx, stack.ID, nil)

stack_configuration_summary_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestStackConfigurationSummaryList(t *testing.T) {
2727
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2828
Name: "aa-test-stack",
2929
VCSRepo: &StackVCSRepoOptions{
30-
Identifier: "ctrombley/linked-stacks-demo-network",
30+
Identifier: "hashicorp-guides/pet-nulls-stack",
3131
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3232
},
3333
Project: &Project{
@@ -39,7 +39,7 @@ func TestStackConfigurationSummaryList(t *testing.T) {
3939
stack2, err := client.Stacks.Create(ctx, StackCreateOptions{
4040
Name: "bb-test-stack",
4141
VCSRepo: &StackVCSRepoOptions{
42-
Identifier: "ctrombley/linked-stacks-demo-network",
42+
Identifier: "hashicorp-guides/pet-nulls-stack",
4343
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
4444
},
4545
Project: &Project{
@@ -50,12 +50,12 @@ func TestStackConfigurationSummaryList(t *testing.T) {
5050
require.NotNil(t, stack2)
5151

5252
// Trigger first stack configuration by updating configuration
53-
_, err = client.Stacks.FetchConfiguration(ctx, stack2.ID)
53+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack2.ID)
5454
require.NoError(t, err)
5555

5656
// Wait a bit and trigger second stack configuration
5757
time.Sleep(2 * time.Second)
58-
_, err = client.Stacks.FetchConfiguration(ctx, stack2.ID)
58+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack2.ID)
5959
require.NoError(t, err)
6060

6161
t.Run("Successful empty list", func(t *testing.T) {

stack_deployment_groups_integration_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestStackDeploymentGroupsList(t *testing.T) {
2525
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2626
Name: "test-stack",
2727
VCSRepo: &StackVCSRepoOptions{
28-
Identifier: "ctrombley/linked-stacks-demo-network",
28+
Identifier: "hashicorp-guides/pet-nulls-stack",
2929
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3030
},
3131
Project: &Project{
@@ -36,7 +36,7 @@ func TestStackDeploymentGroupsList(t *testing.T) {
3636
require.NoError(t, err)
3737
require.NotNil(t, stack)
3838

39-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
39+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
4040
require.NoError(t, err)
4141
require.NotNil(t, stackUpdated)
4242

@@ -90,7 +90,7 @@ func TestStackDeploymentGroupsRead(t *testing.T) {
9090
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
9191
Name: "test-stack",
9292
VCSRepo: &StackVCSRepoOptions{
93-
Identifier: "ctrombley/linked-stacks-demo-network",
93+
Identifier: "hashicorp-guides/pet-nulls-stack",
9494
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
9595
},
9696
Project: &Project{
@@ -101,7 +101,7 @@ func TestStackDeploymentGroupsRead(t *testing.T) {
101101
require.NoError(t, err)
102102
require.NotNil(t, stack)
103103

104-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
104+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
105105
require.NoError(t, err)
106106
require.NotNil(t, stackUpdated)
107107

@@ -142,7 +142,7 @@ func TestStackDeploymentGroupsApproveAllPlans(t *testing.T) {
142142
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
143143
Name: "test-stack",
144144
VCSRepo: &StackVCSRepoOptions{
145-
Identifier: "ctrombley/linked-stacks-demo-network",
145+
Identifier: "hashicorp-guides/pet-nulls-stack",
146146
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
147147
Branch: "main",
148148
},
@@ -153,7 +153,7 @@ func TestStackDeploymentGroupsApproveAllPlans(t *testing.T) {
153153
require.NoError(t, err)
154154
require.NotNil(t, stack)
155155

156-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
156+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
157157
require.NoError(t, err)
158158
require.NotNil(t, stackUpdated)
159159

@@ -189,7 +189,7 @@ func TestStackDeploymentGroupsRerun(t *testing.T) {
189189
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
190190
Name: "test-stack",
191191
VCSRepo: &StackVCSRepoOptions{
192-
Identifier: "ctrombley/linked-stacks-demo-network",
192+
Identifier: "hashicorp-guides/pet-nulls-stack",
193193
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
194194
Branch: "main",
195195
},
@@ -200,7 +200,7 @@ func TestStackDeploymentGroupsRerun(t *testing.T) {
200200
require.NoError(t, err)
201201
require.NotNil(t, stack)
202202

203-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
203+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
204204
require.NoError(t, err)
205205
require.NotNil(t, stackUpdated)
206206

stack_deployment_groups_summary_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestStackDeploymentGroupSummaryList(t *testing.T) {
2626
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2727
Name: "aa-test-stack",
2828
VCSRepo: &StackVCSRepoOptions{
29-
Identifier: "ctrombley/linked-stacks-demo-network",
29+
Identifier: "hashicorp-guides/pet-nulls-stack",
3030
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3131
},
3232
Project: &Project{
@@ -38,7 +38,7 @@ func TestStackDeploymentGroupSummaryList(t *testing.T) {
3838
stack2, err := client.Stacks.Create(ctx, StackCreateOptions{
3939
Name: "bb-test-stack",
4040
VCSRepo: &StackVCSRepoOptions{
41-
Identifier: "ctrombley/linked-stacks-demo-network",
41+
Identifier: "hashicorp-guides/pet-nulls-stack",
4242
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
4343
},
4444
Project: &Project{
@@ -49,14 +49,14 @@ func TestStackDeploymentGroupSummaryList(t *testing.T) {
4949
require.NotNil(t, stack2)
5050

5151
// Trigger first stack configuration with a fetch
52-
_, err = client.Stacks.FetchConfiguration(ctx, stack.ID)
52+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
5353
require.NoError(t, err)
5454

5555
updatedStack := pollStackDeploymentGroups(t, ctx, client, stack.ID)
5656
require.NotNil(t, updatedStack.LatestStackConfiguration.ID)
5757

5858
// Trigger second stack configuration with a fetch
59-
_, err = client.Stacks.FetchConfiguration(ctx, stack2.ID)
59+
_, err = client.Stacks.FetchLatestFromVcs(ctx, stack2.ID)
6060
require.NoError(t, err)
6161

6262
updatedStack2 := pollStackDeploymentGroups(t, ctx, client, stack2.ID)

stack_deployment_runs.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ type StackDeploymentRun struct {
3737
StackDeploymentGroup *StackDeploymentGroup `jsonapi:"relation,stack-deployment-group"`
3838
}
3939

40+
type SDRIncludeOpt string
41+
42+
const (
43+
SDRDeploymentGroup SDRIncludeOpt = "stack-deployment-group"
44+
)
45+
46+
type StackDeploymentRunReadOptions struct {
47+
// Optional: A list of relations to include.
48+
Include []SDRIncludeOpt `url:"include,omitempty"`
49+
}
50+
4051
// StackDeploymentRunList represents a list of stack deployment runs.
4152
type StackDeploymentRunList struct {
4253
*Pagination
@@ -46,6 +57,9 @@ type StackDeploymentRunList struct {
4657
// StackDeploymentRunListOptions represents the options for listing stack deployment runs.
4758
type StackDeploymentRunListOptions struct {
4859
ListOptions
60+
61+
// Optional: A list of relations to include.
62+
Include []SDRIncludeOpt `url:"include,omitempty"`
4963
}
5064

5165
// List returns a list of stack deployment runs for a given deployment group.
@@ -78,6 +92,26 @@ func (s stackDeploymentRuns) Read(ctx context.Context, stackDeploymentRunID stri
7892

7993
return &run, nil
8094
}
95+
96+
func (s stackDeploymentRuns) ReadWithOptions(ctx context.Context, stackDeploymentRunID string, options *StackDeploymentRunReadOptions) (*StackDeploymentRun, error) {
97+
if err := options.valid(); err != nil {
98+
return nil, err
99+
}
100+
101+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-deployment-runs/%s", url.PathEscape(stackDeploymentRunID)), options)
102+
if err != nil {
103+
return nil, err
104+
}
105+
106+
run := StackDeploymentRun{}
107+
err = req.Do(ctx, &run)
108+
if err != nil {
109+
return nil, err
110+
}
111+
112+
return &run, nil
113+
}
114+
81115
func (s stackDeploymentRuns) ApproveAllPlans(ctx context.Context, stackDeploymentRunID string) error {
82116
req, err := s.client.NewRequest("POST", fmt.Sprintf("stack-deployment-runs/%s/approve-all-plans", url.PathEscape(stackDeploymentRunID)), nil)
83117
if err != nil {
@@ -95,3 +129,15 @@ func (s stackDeploymentRuns) Cancel(ctx context.Context, stackDeploymentRunID st
95129

96130
return req.Do(ctx, nil)
97131
}
132+
133+
func (o *StackDeploymentRunReadOptions) valid() error {
134+
for _, include := range o.Include {
135+
switch include {
136+
case SDRDeploymentGroup:
137+
// Valid option, do nothing.
138+
default:
139+
return fmt.Errorf("invalid include option: %s", include)
140+
}
141+
}
142+
return nil
143+
}

stack_deployment_runs_integration_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestStackDeploymentRunsList(t *testing.T) {
2727
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
2828
Name: "test-stack",
2929
VCSRepo: &StackVCSRepoOptions{
30-
Identifier: "ctrombley/linked-stacks-demo-network",
30+
Identifier: "hashicorp-guides/pet-nulls-stack",
3131
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3232
Branch: "main",
3333
},
@@ -38,7 +38,7 @@ func TestStackDeploymentRunsList(t *testing.T) {
3838
require.NoError(t, err)
3939
require.NotNil(t, stack)
4040

41-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
41+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
4242
require.NoError(t, err)
4343
require.NotNil(t, stackUpdated)
4444

@@ -90,15 +90,15 @@ func TestStackDeploymentRunsRead(t *testing.T) {
9090
Project: orgTest.DefaultProject,
9191
Name: "test-stack",
9292
VCSRepo: &StackVCSRepoOptions{
93-
Identifier: "ctrombley/linked-stacks-demo-network",
93+
Identifier: "hashicorp-guides/pet-nulls-stack",
9494
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
9595
Branch: "main",
9696
},
9797
})
9898
require.NoError(t, err)
9999
require.NotNil(t, stack)
100100

101-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
101+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
102102
require.NoError(t, err)
103103
require.NotNil(t, stackUpdated)
104104

@@ -145,15 +145,15 @@ func TestStackDeploymentRunsApproveAllPlans(t *testing.T) {
145145
Project: orgTest.DefaultProject,
146146
Name: "test-stack",
147147
VCSRepo: &StackVCSRepoOptions{
148-
Identifier: "ctrombley/linked-stacks-demo-network",
148+
Identifier: "hashicorp-guides/pet-nulls-stack",
149149
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
150150
Branch: "main",
151151
},
152152
})
153153
require.NoError(t, err)
154154
require.NotNil(t, stack)
155155

156-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
156+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
157157
require.NoError(t, err)
158158
require.NotNil(t, stackUpdated)
159159

@@ -198,15 +198,15 @@ func TestStackDeploymentRunsCancel(t *testing.T) {
198198
Project: orgTest.DefaultProject,
199199
Name: "test-stack",
200200
VCSRepo: &StackVCSRepoOptions{
201-
Identifier: "ctrombley/linked-stacks-demo-network",
201+
Identifier: "hashicorp-guides/pet-nulls-stack",
202202
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
203203
Branch: "main",
204204
},
205205
})
206206
require.NoError(t, err)
207207
require.NotNil(t, stack)
208208

209-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
209+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
210210
require.NoError(t, err)
211211
require.NotNil(t, stackUpdated)
212212

stack_deployment_steps_integration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func TestStackDeploymentStepsList(t *testing.T) {
2828
Project: orgTest.DefaultProject,
2929
Name: "test-stack",
3030
VCSRepo: &StackVCSRepoOptions{
31-
Identifier: "ctrombley/linked-stacks-demo-network", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
31+
Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
3232
Branch: "main",
3333
},
3434
})
3535
require.NoError(t, err)
3636
require.NotNil(t, stack)
3737

38-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
38+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
3939
require.NoError(t, err)
4040
require.NotNil(t, stackUpdated)
4141

@@ -117,14 +117,14 @@ func TestStackDeploymentStepsRead(t *testing.T) {
117117
Project: orgTest.DefaultProject,
118118
Name: "test-stack",
119119
VCSRepo: &StackVCSRepoOptions{
120-
Identifier: "ctrombley/linked-stacks-demo-network", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
120+
Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
121121
Branch: "main",
122122
},
123123
})
124124
require.NoError(t, err)
125125
require.NotNil(t, stack)
126126

127-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
127+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
128128
require.NoError(t, err)
129129
require.NotNil(t, stackUpdated)
130130

@@ -178,14 +178,14 @@ func TestStackDeploymentStepsAdvance(t *testing.T) {
178178
Project: orgTest.DefaultProject,
179179
Name: "testing-stack",
180180
VCSRepo: &StackVCSRepoOptions{
181-
Identifier: "ctrombley/linked-stacks-demo-network", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
181+
Identifier: "hashicorp-guides/pet-nulls-stack", OAuthTokenID: oauthClient.OAuthTokens[0].ID,
182182
Branch: "main",
183183
},
184184
})
185185
require.NoError(t, err)
186186
require.NotNil(t, stack)
187187

188-
stackUpdated, err := client.Stacks.FetchConfiguration(ctx, stack.ID)
188+
stackUpdated, err := client.Stacks.FetchLatestFromVcs(ctx, stack.ID)
189189
require.NoError(t, err)
190190
require.NotNil(t, stackUpdated)
191191

stack_diagnostic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ type StackDiagnostic struct {
1919
CreatedAt *time.Time `jsonapi:"attr,created-at,iso8601"`
2020

2121
// Relationships
22-
StackDeploymentStep *StackConfiguration `jsonapi:"relation,stack-deployment-step"`
23-
StackConfiguration *StackConfiguration `jsonapi:"relation,stack-configuration"`
24-
AcknowledgedBy *User `jsonapi:"relation,acknowledged-by"`
22+
StackDeploymentStep *StackDeploymentStep `jsonapi:"relation,stack-deployment-step"`
23+
StackConfiguration *StackConfiguration `jsonapi:"relation,stack-configuration"`
24+
AcknowledgedBy *User `jsonapi:"relation,acknowledged-by"`
2525
}
2626

2727
// DiagnosticPos represents a position in the source code.

0 commit comments

Comments
 (0)