Skip to content

Commit

Permalink
stacks: add options to create stack source request
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Sep 17, 2024
1 parent bd1cdb9 commit 149adb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 10 additions & 3 deletions stack_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type StackSources interface {

// CreateAndUpload packages and uploads the specified Terraform Stacks
// configuration files in association with a Stack.
CreateAndUpload(ctx context.Context, stackID string, path string) (*StackSource, error)
CreateAndUpload(ctx context.Context, stackID string, path string, opts *CreateStackSourceOptions) (*StackSource, error)

// UploadTarGzip is used to upload Terraform configuration files contained a tar gzip archive.
// Any stream implementing io.Reader can be passed into this method. This method is also
Expand All @@ -30,6 +30,10 @@ type StackSources interface {
UploadTarGzip(ctx context.Context, uploadURL string, archive io.Reader) error
}

type CreateStackSourceOptions struct {
SelectedDeployments []string `jsonapi:"attr,selected-deployments,omitempty"`
}

var _ StackSources = (*stackSources)(nil)

type stackSources struct {
Expand Down Expand Up @@ -63,9 +67,12 @@ func (s *stackSources) Read(ctx context.Context, stackSourceID string) (*StackSo

// CreateAndUpload packages and uploads the specified Terraform Stacks
// configuration files in association with a Stack.
func (s *stackSources) CreateAndUpload(ctx context.Context, stackID, path string) (*StackSource, error) {
func (s *stackSources) CreateAndUpload(ctx context.Context, stackID, path string, opts *CreateStackSourceOptions) (*StackSource, error) {
if opts == nil {
opts = &CreateStackSourceOptions{}
}
u := fmt.Sprintf("stacks/%s/stack-sources", url.PathEscape(stackID))
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, opts)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion stack_source_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func TestStackSourceCreateUploadAndRead(t *testing.T) {
})
require.NoError(t, err)

ss, err := client.StackSources.CreateAndUpload(ctx, stack.ID, "test-fixtures/stack-source")
ss, err := client.StackSources.CreateAndUpload(ctx, stack.ID, "test-fixtures/stack-source", &CreateStackSourceOptions{
SelectedDeployments: []string{"simple"},
})
require.NoError(t, err)
require.NotNil(t, ss)
require.Nil(t, ss.StackConfiguration)
Expand Down

0 comments on commit 149adb7

Please sign in to comment.