Skip to content

Commit

Permalink
feat(cdk): option to set cdk-diff WF assumed role validity[CLK-462684] (
Browse files Browse the repository at this point in the history
#240)

* feat: option to set cdk-diff WF assumed role validity[CLK-462684]

* chore: updating docs & adding UT
  • Loading branch information
rudrateja-clickup authored Jan 26, 2024
1 parent 03ffb31 commit d1de930
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 1 deletion.
26 changes: 26 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/cdk-diff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ Details follow.
+ oidcRoleArn: `arn:aws:iam::${core.Environment.usQa.account}:role/${name}-github-actions-role`,
+ labelToApplyWhenNoDiffPresent: 'no-changes-qa',
+ stackSearchString: 'Qa',
roleDuration: 1800, // Set this value to a desired value only if the diff workflow is expected to take longer than 900 seconds.
+ },
+ {
+ name: 'staging',
+ oidcRoleArn: `arn:aws:iam::${core.Environment.globalStaging.account}:role/${name}-github-actions-role`,
+ labelToApplyWhenNoDiffPresent: 'no-changes-staging',
+ stackSearchString: 'Staging',
roleDuration: 1800, // Set this value to a desired value only if the diff workflow is expected to take longer than 900 seconds.
+ },
+ {
+ name: 'prod',
+ oidcRoleArn: `arn:aws:iam::${core.Environment.globalProd.account}:role/${name}-github-actions-role`,
+ labelToApplyWhenNoDiffPresent: 'no-changes-prod',
+ stackSearchString: 'Prod',
roleDuration: 1800, // Set this value to a desired value only if the diff workflow is expected to take longer than 900 seconds.
+ },
+ ],
+ createOidcRoleStack: true,
Expand Down
8 changes: 7 additions & 1 deletion src/cdk-diff-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export module cdkDiffWorkflow {
uses: 'aws-actions/configure-aws-credentials@v1',
with: {
'role-to-assume': env.oidcRoleArn,
'role-duration-seconds': 900,
'role-duration-seconds': env.roleDuration ?? 900,
'aws-region': 'us-west-2',
},
},
Expand Down Expand Up @@ -249,6 +249,12 @@ export module cdkDiffWorkflow {
* Example: `no-qa-changes`
*/
readonly labelToApplyWhenNoDiffPresent: string;

/**
* Duration in seconds for the assumed role to be valid
* Defaut value: `900`
*/
readonly roleDuration?: number;
}

export interface EnvToDiff extends BaseEnvToDiff {
Expand Down
114 changes: 114 additions & 0 deletions test/__snapshots__/cdk-diff-workflow.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/cdk-diff-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ describe('addCdkDiffWorkflowYml - cdk diff.yml file added', () => {
expect(synth['.github/workflows/cdk-diff.yml']).toMatchSnapshot();
});

test('diff with roleDuration value set', () => {
const project = new clickupCdk.ClickUpCdkTypeScriptApp({
cdkVersion: '2.91.0',
defaultReleaseBranch: 'main',
name: 'test',
});
cdkDiffWorkflow.addCdkDiffWorkflowYml(project, {
envsToDiff: [
{
name: 'qa',
oidcRoleArn: 'arn:aws:iam::123456789012:role/squad-github-actions-oidc-role-name-qa',
labelToApplyWhenNoDiffPresent: 'qa-no-changes',
stackSearchString: 'Qa',
roleDuration: 1800,
},
],
});
const synth = Testing.synth(project);
expect(synth['.github/workflows/cdk-diff.yml']).toMatchSnapshot();
});

test('node20', () => {
const project = new clickupCdk.ClickUpCdkTypeScriptApp({
cdkVersion: '2.91.0',
Expand Down

0 comments on commit d1de930

Please sign in to comment.