-
Notifications
You must be signed in to change notification settings - Fork 4k
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(cli): IAM Policy changes not deploying with --hotswap-fallback #28185
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/aws-cdk/test/api/hotswap/iam-policy-hotswap-deployment.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* eslint-disable import/order */ | ||
import * as setup from './hotswap-test-setup'; | ||
import { HotswapMode } from '../../../lib/api/hotswap/common'; | ||
|
||
let hotswapMockSdkProvider: setup.HotswapMockSdkProvider; | ||
|
||
beforeEach(() => { | ||
hotswapMockSdkProvider = setup.setupHotswapTests(); | ||
}); | ||
|
||
describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hotswapMode) => { | ||
test('A change to an IAM Policy results in a full deployment for HOTSWAP and a noOp for HOTSWAP_ONLY', async () => { | ||
// GIVEN | ||
setup.setCurrentCfnStackTemplate({ | ||
Resources: { | ||
RoleOne: { | ||
Type: 'AWS::IAM::Role', | ||
Properties: { | ||
AssumeRolePolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: 'sts:AssumeRole', | ||
Effect: 'Allow', | ||
Principal: { | ||
Service: 'sqs.amazonaws.com', | ||
}, | ||
}, | ||
], | ||
Version: '2012-10-17', | ||
}, | ||
}, | ||
}, | ||
RoleDefaultPolicy: { | ||
Type: 'AWS::IAM::Policy', | ||
Properties: { | ||
PolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: [ | ||
'sqs:ChangeMessageVisibility', | ||
'sqs:DeleteMessage', | ||
'sqs:GetQueueAttributes', | ||
'sqs:GetQueueUrl', | ||
'sqs:ReceiveMessage', | ||
], | ||
Effect: 'Allow', | ||
Resource: '*', | ||
}, | ||
], | ||
Version: '2012-10-17', | ||
}, | ||
PolicyName: 'roleDefaultPolicy', | ||
Roles: [ | ||
{ | ||
Ref: 'RoleOne', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}); | ||
setup.pushStackResourceSummaries({ | ||
LogicalResourceId: 'RoleOne', | ||
PhysicalResourceId: 'RoleOne', | ||
ResourceType: 'AWS::IAM::Role', | ||
ResourceStatus: 'CREATE_COMPLETE', | ||
LastUpdatedTimestamp: new Date(), | ||
}); | ||
const cdkStackArtifact = setup.cdkStackArtifactOf({ | ||
template: { | ||
Resources: { | ||
RoleOne: { | ||
Type: 'AWS::IAM::Role', | ||
Properties: { | ||
AssumeRolePolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: 'sts:AssumeRole', | ||
Effect: 'Allow', | ||
Principal: { | ||
Service: 'sqs.amazonaws.com', | ||
}, | ||
}, | ||
], | ||
Version: '2012-10-17', | ||
}, | ||
}, | ||
}, | ||
RoleDefaultPolicy: { | ||
Type: 'AWS::IAM::Policy', | ||
Properties: { | ||
PolicyDocument: { | ||
Statement: [ | ||
{ | ||
Action: [ | ||
'sqs:DeleteMessage', | ||
], | ||
Effect: 'Allow', | ||
Resource: '*', | ||
}, | ||
], | ||
Version: '2012-10-17', | ||
}, | ||
PolicyName: 'roleDefaultPolicy', | ||
Roles: [ | ||
{ | ||
Ref: 'RoleOne', | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (hotswapMode === HotswapMode.FALL_BACK) { | ||
// WHEN | ||
const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, cdkStackArtifact); | ||
|
||
// THEN | ||
expect(deployStackResult).toBeUndefined(); | ||
} else if (hotswapMode === HotswapMode.HOTSWAP_ONLY) { | ||
// WHEN | ||
const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, cdkStackArtifact); | ||
|
||
// THEN | ||
expect(deployStackResult).not.toBeUndefined(); | ||
expect(deployStackResult?.noOp).toEqual(true); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this existing test was unintentionally relying on undefined behavior.
Previously, the stack under would receive a change that changes
Policy2
from being a policy that is used exclusively by S3Deployment, to a "free-floating" policy. This was becausepolicy2Old -> policy2New
is changing the role fromServiceRole -> ServiceRole2
. HoweverServiceRole2
is not used by the S3Deployment.Without adjusting the test case, it now would have failed because this new "free-floating" policy would have been detected as non-hotswappable and also not skippable since it is not connected to an S3Deployment anymore.
I believe the intent of the test was to test the skipping (based on test case description and assertions) and this accidentally worked. So I adjusted the test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!