diff --git a/.changeset/fuzzy-mails-dream.md b/.changeset/fuzzy-mails-dream.md new file mode 100644 index 000000000..16db2913e --- /dev/null +++ b/.changeset/fuzzy-mails-dream.md @@ -0,0 +1,5 @@ +--- +"sst": patch +--- + +Passing cdk role to stack remove diff --git a/packages/sst/src/stacks/deploy.ts b/packages/sst/src/stacks/deploy.ts index f1e995a15..2d67bc462 100644 --- a/packages/sst/src/stacks/deploy.ts +++ b/packages/sst/src/stacks/deploy.ts @@ -248,7 +248,7 @@ async function addInUseExports( } } -async function createCdkDeployments() { +export async function createCdkDeployments() { const cdkToolkitUrl = await import.meta.resolve!("@aws-cdk/toolkit-lib"); const cdkToolkitPath = fileURLToPath(cdkToolkitUrl); const { Deployments } = await import( diff --git a/packages/sst/src/stacks/remove.ts b/packages/sst/src/stacks/remove.ts index 05a075542..b98915d91 100644 --- a/packages/sst/src/stacks/remove.ts +++ b/packages/sst/src/stacks/remove.ts @@ -7,10 +7,14 @@ import { useBus } from "../bus.js"; import { useAWSClient, useAWSProvider } from "../credentials.js"; import { Logger } from "../logger.js"; import { StackDeploymentResult, monitor, isFailed } from "./monitor.js"; +import { createCdkDeployments } from "./deploy.js"; +import { ConfigOptions, useProject } from "../project.js"; export async function removeMany(stacks: CloudFormationStackArtifact[]) { await useAWSProvider(); const bus = useBus(); + const { cdk } = useProject().config; + const deployment = await createCdkDeployments(); const complete = new Set(); const todo = new Set(stacks.map((s) => s.id)); @@ -35,7 +39,7 @@ export async function removeMany(stacks: CloudFormationStackArtifact[]) { continue; } - remove(stack).then((result) => { + remove(deployment, stack, cdk).then((result) => { results[stack.id] = result; complete.add(stack.id); @@ -71,14 +75,21 @@ export async function removeMany(stacks: CloudFormationStackArtifact[]) { } export async function remove( - stack: CloudFormationStackArtifact + deployment: Awaited>, + stack: CloudFormationStackArtifact, + cdkOptions?: ConfigOptions["cdk"] ): Promise { Logger.debug("Removing stack", stack.id); const cfn = useAWSClient(CloudFormationClient); + + const env = await deployment.envs.accessStackForMutableStackOperations(stack); + const executionRoleArn = cdkOptions?.cloudFormationExecutionRole ?? await env.replacePlaceholders(stack.cloudFormationExecutionRoleArn); + try { await cfn.send( new DeleteStackCommand({ StackName: stack.stackName, + RoleARN: executionRoleArn, }) ); return monitor(stack.stackName);