Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepfunctions): imported State Machine still has region and account from its Stack, instead of its ARN #19026

Merged
merged 2 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
public readonly stateMachineArn = stateMachineArn;
public readonly grantPrincipal = new iam.UnknownPrincipal({ resource: this });
}
return new Import(scope, id);
return new Import(scope, id, {
environmentFromArn: stateMachineArn,
});
}

public abstract readonly stateMachineArn: string;
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-stepfunctions/test/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,35 @@ describe('State Machine', () => {
],
});
});

describe('StateMachine.fromStateMachineArn()', () => {
let stack: cdk.Stack;

beforeEach(() => {
const app = new cdk.App();
stack = new cdk.Stack(app, 'Base', {
env: { account: '111111111111', region: 'stack-region' },
});
});

describe('for a state machine in a different account and region', () => {
let mach: stepfunctions.IStateMachine;

beforeEach(() => {
mach = stepfunctions.StateMachine.fromStateMachineArn(
stack,
'iMach',
'arn:aws:states:machine-region:222222222222:stateMachine:machine-name',
);
});

test("the state machine's region is taken from the ARN", () => {
expect(mach.env.region).toBe('machine-region');
});

test("the state machine's account is taken from the ARN", () => {
expect(mach.env.account).toBe('222222222222');
});
});
});
});