Skip to content

Commit 334c180

Browse files
Merge pull request #963 from hashicorp/add-stack-include-options
stacks: add includes for stack read and list
2 parents 6ad8729 + 95a58ca commit 334c180

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

stack.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Stacks interface {
1818
List(ctx context.Context, organization string, options *StackListOptions) (*StackList, error)
1919

2020
// Read returns a stack by its ID.
21-
Read(ctx context.Context, stackID string) (*Stack, error)
21+
Read(ctx context.Context, stackID string, options *StackReadOptions) (*Stack, error)
2222

2323
// Create creates a new stack.
2424
Create(ctx context.Context, options StackCreateOptions) (*Stack, error)
@@ -143,12 +143,27 @@ type StackState struct {
143143
ID string `jsonapi:"primary,stack-states"`
144144
}
145145

146+
// StackIncludeOpt represents the include options for a stack.
147+
type StackIncludeOpt string
148+
149+
const (
150+
StackIncludeOrganization StackIncludeOpt = "organization"
151+
StackIncludeProject StackIncludeOpt = "project"
152+
StackIncludeLatestStackConfiguration StackIncludeOpt = "latest_stack_configuration"
153+
StackIncludeStackDiagnostics StackIncludeOpt = "stack_diagnostics"
154+
)
155+
146156
// StackListOptions represents the options for listing stacks.
147157
type StackListOptions struct {
148158
ListOptions
149-
ProjectID string `url:"filter[project[id]],omitempty"`
150-
Sort StackSortColumn `url:"sort,omitempty"`
151-
SearchByName string `url:"search[name],omitempty"`
159+
ProjectID string `url:"filter[project[id]],omitempty"`
160+
Sort StackSortColumn `url:"sort,omitempty"`
161+
SearchByName string `url:"search[name],omitempty"`
162+
Include []StackIncludeOpt `url:"include,omitempty"`
163+
}
164+
165+
type StackReadOptions struct {
166+
Include []StackIncludeOpt `url:"include,omitempty"`
152167
}
153168

154169
// StackCreateOptions represents the options for creating a stack. The project
@@ -221,8 +236,8 @@ func (s stacks) List(ctx context.Context, organization string, options *StackLis
221236
}
222237

223238
// Read returns a stack by its ID.
224-
func (s stacks) Read(ctx context.Context, stackID string) (*Stack, error) {
225-
req, err := s.client.NewRequest("GET", fmt.Sprintf("stacks/%s", url.PathEscape(stackID)), nil)
239+
func (s stacks) Read(ctx context.Context, stackID string, options *StackReadOptions) (*Stack, error) {
240+
req, err := s.client.NewRequest("GET", fmt.Sprintf("stacks/%s", url.PathEscape(stackID)), options)
226241
if err != nil {
227242
return nil, err
228243
}

stack_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
155155
require.NoError(t, err)
156156
require.NotNil(t, stack)
157157

158-
stackRead, err := client.Stacks.Read(ctx, stack.ID)
158+
stackRead, err := client.Stacks.Read(ctx, stack.ID, nil)
159159
require.NoError(t, err)
160160

161161
assert.Equal(t, stack, stackRead)
@@ -174,7 +174,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
174174
err = client.Stacks.Delete(ctx, stack.ID)
175175
require.NoError(t, err)
176176

177-
stackReadAfterDelete, err := client.Stacks.Read(ctx, stack.ID)
177+
stackReadAfterDelete, err := client.Stacks.Read(ctx, stack.ID, nil)
178178
require.ErrorIs(t, err, ErrResourceNotFound)
179179
require.Nil(t, stackReadAfterDelete)
180180
}
@@ -199,7 +199,7 @@ func pollStackDeployments(t *testing.T, ctx context.Context, client *Client, sta
199199
t.Fatalf("Stack %q had no deployments at deadline", stackID)
200200
case <-ticker.C:
201201
var err error
202-
stack, err = client.Stacks.Read(ctx, stackID)
202+
stack, err = client.Stacks.Read(ctx, stackID, nil)
203203
if err != nil {
204204
t.Fatalf("Failed to read stack %q: %s", stackID, err)
205205
}

0 commit comments

Comments
 (0)