Skip to content

bug(deploy): diff flag diffs all stacks instead of filtering to the specified target #983

Description

@allandsouza

Description

agentcore deploy --target <name> --diff shows CDK diff for all stacks in the synthesized app, not just the stack corresponding to the specified --target. When multiple targets are defined in aws-targets.json, the --diff flag ignores the --target filter.

Steps to Reproduce

  1. Configure two or more targets in aws-targets.json:
[
  { "name": "preprod-east2", "account": "...", "region": "us-east-2" },
  { "name": "default", "account": "...", "region": "us-west-2" }
]
  1. Run agentcore deploy --target default --diff
  2. Observe the output shows diff for both Stack AgentCore--preprod-east2 and Stack AgentCore--default

Expected Behavior

Only the stack for the specified target (AgentCore-<project>-default) should be diffed. The --target flag should filter the diff to the selected target's stack, consistent with how --target scopes other deploy operations.

Actual Behavior

Both stacks are diffed. The output shows Number of stacks with differences: 2 and includes full diff output for both targets, even though only default was specified.

CLI Version

0.11.0

Operating System

macOS

Additional Context

Root cause is in actions.ts. The diff code path calls toolkitWrapper.diff() without passing a stack selection filter:

// line ~197 in actions.ts
await toolkitWrapper.diff();

The CdkToolkitWrapper.diff() method in wrapper.ts accepts a DiffOptions with optional stacks selection, but it's never provided. Since cdk.ts synthesizes a stack per target, CDK diffs all of them.

Suggested fix - pass the target-specific stack name:

import { StackSelectionStrategy } from '@aws-cdk/toolkit-lib';

await toolkitWrapper.diff({
  stacks: {
    strategy: StackSelectionStrategy.PATTERN_MUST_MATCH,
    patterns: [stackName],
  },
});

Note: the same issue may also affect toolkitWrapper.deploy() which is also called without stack selection

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions