-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): IAM Policy changes not deploying with --hotswap-fallback (#…
…28185) The hotswappable resource detectors failed to correctly identify `AWS::IAM::Policy` resources as not-hotswappable. When `--hotswap-fallback` was used and the only change to the stack was with `AWS::IAM::Policy`, this caused the deploy command to first report IAM changes, and then report `no changes` on the stack. <img width="1076" alt="image" src="https://github.com/aws/aws-cdk/assets/379814/d77320bc-fc8d-4b70-b710-2c28467d07e5"> ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
4 changed files
with
200 additions
and
49 deletions.
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