From 149adb7bf8133509b8b6fbb1023f6b0c0b957a81 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 14 Aug 2024 14:21:17 +0200 Subject: [PATCH] stacks: add options to create stack source request --- stack_source.go | 13 ++++++++++--- stack_source_integration_test.go | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/stack_source.go b/stack_source.go index 127e68d44..cca06859d 100644 --- a/stack_source.go +++ b/stack_source.go @@ -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 @@ -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 { @@ -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 } diff --git a/stack_source_integration_test.go b/stack_source_integration_test.go index 6988beff9..fafaaa617 100644 --- a/stack_source_integration_test.go +++ b/stack_source_integration_test.go @@ -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)