Skip to content

Commit

Permalink
Require env var for this behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMoat committed Jul 1, 2024
1 parent f104f87 commit 7e223b9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/command/deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package command

import (
"os"

"github.com/72636c/stratus/internal/config"
"github.com/72636c/stratus/internal/context"
"github.com/72636c/stratus/internal/stratus"
Expand All @@ -18,9 +20,14 @@ func Deploy(
changeSet, err := client.FindExistingChangeSet(ctx, stack)

if err != nil {
logger.Title("Could not find existing change set. Creating new change set.")

if _, changeSet, err = Stage(ctx, client, stack); err != nil {
if os.Getenv("FORCE_DEPLOY") == "true" {
logger.Title("Could not find existing change set. FORCE_DEPLOY is true, so creating a new change set.")

if _, changeSet, err = Stage(ctx, client, stack); err != nil {
return err
}
} else {
logger.Title("Could not find existing change set, exiting. To force a deployment with a new change set, set FORCE_DEPLOY=true and retry.")
return err
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command_test

import (
"os"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -530,6 +531,8 @@ func Test_Deploy_Happy_ImplicitStage(t *testing.T) {
Checksum: mockChecksum,
}

os.Setenv("FORCE_DEPLOY", "true")

cfn := stratus.NewCloudFormationMock()
defer cfn.AssertExpectations(t)
cfn.
Expand Down Expand Up @@ -672,4 +675,44 @@ func Test_Deploy_Happy_ImplicitStage(t *testing.T) {

err := command.Deploy(context.Background(), client, stack)
assert.NoError(err)

os.Unsetenv("FORCE_DEPLOY")
}

func Test_Deploy_NoImplicitStage_Fails(t *testing.T) {
assert := assert.New(t)

stack := &config.Stack{
Name: mockStackName,

Capabilities: make([]string, 0),
Parameters: make(config.StackParameters, 0),
TerminationProtection: true,

Policy: []byte(mockStackPolicy),
Template: []byte(mockStackTemplate),

Checksum: mockChecksum,
}

cfn := stratus.NewCloudFormationMock()
defer cfn.AssertExpectations(t)
cfn.
On(
"ListChangeSetsWithContext",
&cloudformation.ListChangeSetsInput{
StackName: aws.String(stack.Name),
},
).
Return(
&cloudformation.ListChangeSetsOutput{
Summaries: []*cloudformation.ChangeSetSummary{},
},
nil,
)

client := stratus.NewClient(cfn, nil)

err := command.Deploy(context.Background(), client, stack)
assert.Error(err)
}

0 comments on commit 7e223b9

Please sign in to comment.