-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Justin Alvarez <[email protected]>
- Loading branch information
Showing
9 changed files
with
137 additions
and
6 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
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,56 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { CfnMaintenanceWindow, CfnMaintenanceWindowTarget, CfnMaintenanceWindowTask } from 'aws-cdk-lib/aws-ssm'; | ||
import { Construct } from 'constructs'; | ||
import { applyTerminationProtectionOnStacks } from './aspects/stack-termination-protection'; | ||
|
||
export class SSMPatchingStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
applyTerminationProtectionOnStacks([this]); | ||
|
||
const maintenanceWindow = new CfnMaintenanceWindow(this, 'MaintenanceWindow', { | ||
name: `Patching-Window`, | ||
allowUnassociatedTargets: false, | ||
cutoff: 0, | ||
duration: 2, | ||
// Every Sunday at 3 AM | ||
schedule: 'cron(0 3 ? * SUN *)' | ||
}); | ||
|
||
const maintenanceTarget = new CfnMaintenanceWindowTarget(this, 'MaintenanceWindowTarget', { | ||
name: 'All-Instances-Patch-Target', | ||
windowId: maintenanceWindow.ref, | ||
resourceType: 'INSTANCE', | ||
targets: [ | ||
{ | ||
key: 'tag:PVRE-Reporting', | ||
values: ['SSM'] | ||
} | ||
] | ||
}); | ||
|
||
new CfnMaintenanceWindowTask(this, 'MaintenanceWindowTask', { | ||
taskArn: 'AWS-RunPatchBaseline', | ||
priority: 1, | ||
taskType: 'RUN_COMMAND', | ||
windowId: maintenanceWindow.ref, | ||
name: 'Patch-Task', | ||
targets: [ | ||
{ | ||
key: 'WindowTargetIds', | ||
values: [maintenanceTarget.ref] | ||
} | ||
], | ||
taskInvocationParameters: { | ||
maintenanceWindowRunCommandParameters: { | ||
parameters: { | ||
Operation: ['Install'] | ||
}, | ||
documentVersion: '$LATEST' | ||
} | ||
}, | ||
maxErrors: '0', | ||
maxConcurrency: '1' | ||
}); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { Template } from 'aws-cdk-lib/assertions'; | ||
import { SSMPatchingStack } from '../lib/ssm-patching-stack'; | ||
|
||
describe('SSMPatchingStack', () => { | ||
test('synthesizes the way we expect', () => { | ||
const app = new cdk.App(); | ||
const ssmPatchingStack = new SSMPatchingStack(app, 'SSMPatchingStack'); | ||
|
||
const template = Template.fromStack(ssmPatchingStack); | ||
|
||
template.hasResource('AWS::SSM::MaintenanceWindow', { | ||
Properties: { | ||
AllowUnassociatedTargets: false, | ||
Cutoff: 0, | ||
Duration: 2, | ||
Name: 'Patching-Window', | ||
Schedule: 'cron(0 3 ? * SUN *)' | ||
} | ||
}); | ||
|
||
template.hasResource('AWS::SSM::MaintenanceWindowTarget', { | ||
Properties: { | ||
Name: 'All-Instances-Patch-Target', | ||
ResourceType: 'INSTANCE', | ||
Targets: [ | ||
{ | ||
Key: 'tag:PVRE-Reporting', | ||
Values: ['SSM'] | ||
} | ||
], | ||
WindowId: { | ||
Ref: 'MaintenanceWindow' | ||
} | ||
} | ||
}); | ||
|
||
template.hasResource('AWS::SSM::MaintenanceWindowTask', { | ||
Properties: { | ||
MaxConcurrency: '1', | ||
MaxErrors: '0', | ||
Name: 'Patch-Task', | ||
Priority: 1, | ||
Targets: [ | ||
{ | ||
Key: 'WindowTargetIds', | ||
Values: [ | ||
{ | ||
Ref: 'MaintenanceWindowTarget' | ||
} | ||
] | ||
} | ||
], | ||
TaskArn: 'AWS-RunPatchBaseline', | ||
TaskInvocationParameters: { | ||
MaintenanceWindowRunCommandParameters: { | ||
Parameters: { | ||
Operation: ['Install'] | ||
}, | ||
DocumentVersion: '$LATEST' | ||
} | ||
}, | ||
TaskType: 'RUN_COMMAND', | ||
WindowId: { | ||
Ref: 'MaintenanceWindow' | ||
} | ||
} | ||
}); | ||
|
||
expect(ssmPatchingStack.terminationProtection).toBeTruthy(); | ||
}); | ||
}); |