Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions packages/core/src/awsService/cloudformation/commands/cfnCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type OptionalFlagSelection = ChangeSetOptionalFlags & {
shouldSaveOptions?: boolean
}

function shouldPromptForDeploymentMode(
function canDefaultToRevertDrift(
stackDetails: Stack | undefined,
importExistingResources: boolean | undefined,
includeNestedStacks: boolean | undefined,
Expand Down Expand Up @@ -246,7 +246,7 @@ export async function promptForOptionalFlags(
// default to REVERT_DRIFT if possible because it's generally useful
deploymentMode:
fileFlags?.deploymentMode ??
(shouldPromptForDeploymentMode(
(canDefaultToRevertDrift(
stackDetails,
fileFlags?.importExistingResources,
fileFlags?.includeNestedStacks,
Expand All @@ -259,21 +259,17 @@ export async function promptForOptionalFlags(

break
case OptionalFlagMode.Input: {
const onStackFailure = fileFlags?.onStackFailure ?? (await getOnStackFailure(!!stackDetails))
const includeNestedStacks = fileFlags?.includeNestedStacks ?? (await getIncludeNestedStacks())
const importExistingResources = fileFlags?.importExistingResources ?? (await getImportExistingResources())

let deploymentMode = fileFlags?.deploymentMode
if (
!deploymentMode &&
shouldPromptForDeploymentMode(
stackDetails,
importExistingResources,
includeNestedStacks,
onStackFailure
)
) {
deploymentMode = await getDeploymentMode()
// Only available for UPDATE stack
const deploymentMode = fileFlags?.deploymentMode ?? (stackDetails && (await getDeploymentMode()))

let onStackFailure: OnStackFailure | undefined
let includeNestedStacks: boolean | undefined
let importExistingResources: boolean | undefined

if (deploymentMode !== DeploymentMode.REVERT_DRIFT) {
onStackFailure = fileFlags?.onStackFailure ?? (await getOnStackFailure(!!stackDetails))
includeNestedStacks = fileFlags?.includeNestedStacks ?? (await getIncludeNestedStacks())
importExistingResources = fileFlags?.importExistingResources ?? (await getImportExistingResources())
}

optionalFlags = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/awsService/cloudformation/ui/inputBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export async function getDeploymentMode(): Promise<DeploymentMode | undefined> {
[
{
label: 'Revert Drift',
description: 'Revert drift during deployment',
description: 'Revert drift during deployment (disables dev friendly flags)',
value: DeploymentMode.REVERT_DRIFT,
},
{ label: 'Standard', description: 'No special handling during deployment', value: undefined },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('CfnCommands', function () {

it('should set shouldSaveOptions to true when input mode collects new values', async function () {
chooseOptionalFlagModeStub.resolves(OptionalFlagMode.Input)
getDeploymentModeStub.resolves(undefined)
getOnStackFailureStub.resolves(OnStackFailure.DELETE)
getIncludeNestedStacksStub.resolves(true)
getTagsStub.resolves([{ Key: 'Environment', Value: 'prod' }])
Expand All @@ -129,53 +130,74 @@ describe('CfnCommands', function () {
})
})

it('should prompt for deployment mode on stack update when conditions are met', async function () {
it('should not prompt for deployment mode for CREATE stack', async function () {
chooseOptionalFlagModeStub.resolves(OptionalFlagMode.Input)
getOnStackFailureStub.resolves(OnStackFailure.ROLLBACK)
getIncludeNestedStacksStub.resolves(false)
getTagsStub.resolves(undefined)
getImportExistingResourcesStub.resolves(false)
getDeploymentModeStub.resolves('INCREMENTAL')

const stackDetails = { StackName: 'test-stack' }
const result = await promptForOptionalFlags(undefined, stackDetails as any)
const result = await promptForOptionalFlags()

assert.ok(getDeploymentModeStub.calledOnce)
assert.ok(getDeploymentModeStub.notCalled)
assert.ok(getOnStackFailureStub.calledOnce)
assert.ok(getIncludeNestedStacksStub.calledOnce)
assert.ok(getImportExistingResourcesStub.calledOnce)
assert.deepStrictEqual(result, {
onStackFailure: OnStackFailure.ROLLBACK,
includeNestedStacks: false,
tags: undefined,
importExistingResources: false,
deploymentMode: 'INCREMENTAL',
deploymentMode: undefined,
shouldSaveOptions: true,
})
})

it('should not prompt for deployment mode on stack create', async function () {
it('should prompt for deployment mode and other flags when not REVERT_DRIFT', async function () {
chooseOptionalFlagModeStub.resolves(OptionalFlagMode.Input)
getDeploymentModeStub.resolves(undefined)
getOnStackFailureStub.resolves(OnStackFailure.ROLLBACK)
getIncludeNestedStacksStub.resolves(false)
getTagsStub.resolves(undefined)
getImportExistingResourcesStub.resolves(false)

const result = await promptForOptionalFlags()
const stackDetails = { StackName: 'test-stack' }
const result = await promptForOptionalFlags(undefined, stackDetails as any)

assert.ok(getDeploymentModeStub.notCalled)
assert.strictEqual(result?.deploymentMode, undefined)
assert.ok(getDeploymentModeStub.calledOnce)
assert.ok(getOnStackFailureStub.calledOnce)
assert.ok(getIncludeNestedStacksStub.calledOnce)
assert.ok(getImportExistingResourcesStub.calledOnce)
assert.deepStrictEqual(result, {
onStackFailure: OnStackFailure.ROLLBACK,
includeNestedStacks: false,
tags: undefined,
importExistingResources: false,
deploymentMode: undefined,
shouldSaveOptions: true,
})
})

it('should not prompt for deployment mode when importExistingResources is true', async function () {
it('should skip other prompts when deploymentMode is REVERT_DRIFT', async function () {
chooseOptionalFlagModeStub.resolves(OptionalFlagMode.Input)
getOnStackFailureStub.resolves(OnStackFailure.ROLLBACK)
getIncludeNestedStacksStub.resolves(false)
getDeploymentModeStub.resolves('REVERT_DRIFT')
getTagsStub.resolves(undefined)
getImportExistingResourcesStub.resolves(true)

const stackDetails = { StackName: 'test-stack' }
const result = await promptForOptionalFlags(undefined, stackDetails as any)

assert.ok(getDeploymentModeStub.notCalled)
assert.strictEqual(result?.deploymentMode, undefined)
assert.ok(getDeploymentModeStub.calledOnce)
assert.ok(getOnStackFailureStub.notCalled)
assert.ok(getIncludeNestedStacksStub.notCalled)
assert.ok(getImportExistingResourcesStub.notCalled)
assert.deepStrictEqual(result, {
onStackFailure: undefined,
includeNestedStacks: undefined,
tags: undefined,
importExistingResources: undefined,
deploymentMode: 'REVERT_DRIFT',
shouldSaveOptions: true,
})
})

it('should include deploymentMode from fileFlags in skip mode', async function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Cloudformation: Shorten/simplify deployment prompts by prompting for deployment mode first"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CloudFormation*

}
Loading