Skip to content

Commit 6d7a407

Browse files
Merge pull request #1119 from hashicorp/hw/custom-stack-config-upload
Added `SpeculativeEnabled` option to `CreateStackSourceOptions` for supporting speculative runs on manual stack uploads
2 parents 766691b + 2109a62 commit 6d7a407

File tree

5 files changed

+68
-11
lines changed

5 files changed

+68
-11
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 speculative runs with `Stacks` resources and removes VCS repo validity check on `Stack` creation, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @hwatkins05-hashicorp [#1119](https://github.com/hashicorp/go-tfe/pull/1119)
6+
37
# v1.81.0
48

59
## Enhancements

examples/projects/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ func main() {
2828

2929
// Create a new project
3030
p, err := client.Projects.Create(ctx, "org-test", tfe.ProjectCreateOptions{
31-
Name: "my-app-tst",
31+
Name: "my-app-tst",
3232
})
3333
if err != nil {
3434
log.Fatal(err)
3535
}
3636

3737
// Update the project auto destroy activity duration
3838
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
39-
AutoDestroyActivityDuration: jsonapi.NewNullableAttrWithValue("3d"),
39+
AutoDestroyActivityDuration: jsonapi.NewNullableAttrWithValue("3d"),
4040
})
4141
if err != nil {
4242
log.Fatal(err)
4343
}
4444

4545
// Disable auto destroy
4646
p, err = client.Projects.Update(ctx, p.ID, tfe.ProjectUpdateOptions{
47-
AutoDestroyActivityDuration: jsonapi.NewNullNullableAttr[string](),
47+
AutoDestroyActivityDuration: jsonapi.NewNullNullableAttr[string](),
4848
})
4949
if err != nil {
5050
log.Fatal(err)

stack.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,6 @@ func (s StackCreateOptions) valid() error {
331331
return ErrRequiredProject
332332
}
333333

334-
return s.VCSRepo.valid()
335-
}
336-
337-
func (s StackVCSRepoOptions) valid() error {
338-
if s.Identifier == "" {
339-
return ErrRequiredVCSRepo
340-
}
341-
342334
return nil
343335
}
344336

stack_source.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type StackSources interface {
3232

3333
type CreateStackSourceOptions struct {
3434
SelectedDeployments []string `jsonapi:"attr,selected-deployments,omitempty"`
35+
SpeculativeEnabled *bool `jsonapi:"attr,speculative,omitempty"`
3536
}
3637

3738
var _ StackSources = (*stackSources)(nil)

stack_source_integration_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,63 @@ func TestStackSourceCreateUploadAndRead(t *testing.T) {
6666
require.Fail(t, "timed out waiting for stack source to be processed")
6767
}
6868
}
69+
70+
func TestStackSourceSpeculatives(t *testing.T) {
71+
skipUnlessBeta(t)
72+
73+
client := testClient(t)
74+
ctx := context.Background()
75+
76+
orgTest, orgTestCleanup := createOrganization(t, client)
77+
t.Cleanup(orgTestCleanup)
78+
79+
oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil)
80+
t.Cleanup(cleanup)
81+
82+
stackVCS, err := client.Stacks.Create(ctx, StackCreateOptions{
83+
Project: orgTest.DefaultProject,
84+
Name: "test-stack-vcs",
85+
VCSRepo: &StackVCSRepoOptions{
86+
Identifier: "hashicorp-guides/pet-nulls-stack",
87+
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
88+
},
89+
})
90+
require.NoError(t, err)
91+
92+
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
93+
Project: &Project{
94+
ID: orgTest.DefaultProject.ID,
95+
},
96+
Name: "test-stack",
97+
})
98+
require.NoError(t, err)
99+
100+
t.Run("with speculative run enabled for VCS upload", func(t *testing.T) {
101+
ss, err := client.StackSources.CreateAndUpload(ctx, stackVCS.ID, "test-fixtures/stack-source", &CreateStackSourceOptions{
102+
SelectedDeployments: []string{"simple"},
103+
SpeculativeEnabled: Bool(true),
104+
})
105+
require.NoError(t, err)
106+
require.NotNil(t, ss)
107+
require.NotNil(t, ss.UploadURL)
108+
})
109+
110+
t.Run("with speculative run disabled for manual upload", func(t *testing.T) {
111+
ss, err := client.StackSources.CreateAndUpload(ctx, stack.ID, "test-fixtures/stack-source", &CreateStackSourceOptions{
112+
SelectedDeployments: []string{"simple"},
113+
SpeculativeEnabled: Bool(false),
114+
})
115+
require.NoError(t, err)
116+
require.NotNil(t, ss)
117+
require.NotNil(t, ss.UploadURL)
118+
})
119+
120+
t.Run("with invalid speculative run option for VCS upload", func(t *testing.T) {
121+
ss, err := client.StackSources.CreateAndUpload(ctx, stackVCS.ID, "test-fixtures/stack-source", &CreateStackSourceOptions{
122+
SelectedDeployments: []string{"simple"},
123+
SpeculativeEnabled: Bool(false),
124+
})
125+
require.Nil(t, ss)
126+
require.Error(t, err)
127+
})
128+
}

0 commit comments

Comments
 (0)