Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6b9bb4d
Initial Push with starter code
naveenkoppula Sep 18, 2020
358ce27
Merge remote-tracking branch 'origin/master' into feat/store-outputs-…
naveenkoppula Sep 21, 2020
74326d3
Initial Push for Network outputs
naveenkoppula Sep 21, 2020
10336ac
Prettier
naveenkoppula Sep 21, 2020
417b7bd
Update on save network outputs
naveenkoppula Sep 21, 2020
aec38d1
Saving VPC outputs
naveenkoppula Sep 21, 2020
d49466a
Using DDB for previous index while storing outputs
naveenkoppula Sep 22, 2020
4e09816
updates
naveenkoppula Sep 22, 2020
7b50b8c
adding remove prevous ssm and also code for routeTables
naveenkoppula Sep 22, 2020
8020fc0
added ssm params for iam
nachundu-amzn Sep 22, 2020
e927e83
moved ssm into category
nachundu-amzn Sep 22, 2020
c5e24f4
added removal of ssm parameters
nachundu-amzn Sep 22, 2020
1e5652a
Ignore updation for ssm params
naveenkoppula Sep 23, 2020
5734e49
Merge branch 'feat/store-outputs-to-ssm' of https://github.com/aws-sa…
naveenkoppula Sep 23, 2020
86e662b
Updates in utils
naveenkoppula Sep 23, 2020
63a134c
Merge remote-tracking branch 'origin/master' into feat/store-outputs-…
naveenkoppula Sep 23, 2020
7520e09
added kms and acm outputs
nachundu-amzn Sep 23, 2020
6709c88
Saving ELB Outputs
naveenkoppula Sep 23, 2020
3236275
Save Event outputs
naveenkoppula Sep 23, 2020
37f42e2
added encrypt outputs to parameter store
nachundu-amzn Sep 23, 2020
820cddb
added comments
nachundu-amzn Sep 23, 2020
2eb7207
Updating SM for store outputs to ssm
naveenkoppula Sep 24, 2020
cea6afb
Increasing SSM Parameter Store Throughput in all supported regions
naveenkoppula Sep 24, 2020
a6d37a2
Fixing ssh throughput incresing
naveenkoppula Sep 24, 2020
410aa02
Saving Firewall outputs to SSM
naveenkoppula Sep 24, 2020
b153978
Prettier & fixing tests
naveenkoppula Sep 25, 2020
d6d2b8f
added ssm access policy
nachundu-amzn Sep 28, 2020
4e2def2
fixed prettier issue
nachundu-amzn Sep 28, 2020
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
1 change: 1 addition & 0 deletions reference-artifacts/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"workloadaccounts-prefix": "config",
"workloadaccounts-param-filename": "config.json",
"ignored-ous": [],
"additional-global-output-regions": [],
"supported-regions": [
"ap-northeast-1",
"ap-northeast-2",
Expand Down
48 changes: 45 additions & 3 deletions src/core/cdk/src/initial-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { RunAcrossAccountsTask } from './tasks/run-across-accounts-task';
import * as fs from 'fs';
import * as sns from '@aws-cdk/aws-sns';
import { StoreOutputsTask } from './tasks/store-outputs-task';
import { StoreOutputsToSSMTask } from './tasks/store-outputs-to-ssm-task';

export namespace InitialSetup {
export interface CommonProps {
Expand Down Expand Up @@ -90,6 +91,18 @@ export namespace InitialSetup {
encryption: dynamodb.TableEncryption.DEFAULT,
});

const outputUtilsTable = new dynamodb.Table(this, 'OutputUtils', {
tableName: createName({
name: 'Output-Utils',
suffixLength: 0,
}),
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
encryption: dynamodb.TableEncryption.DEFAULT,
});

// This is the maximum time before a build times out
// The role used by the build should allow this session duration
const buildTimeout = cdk.Duration.hours(4);
Expand Down Expand Up @@ -499,7 +512,36 @@ export namespace InitialSetup {
resultPath: 'DISCARD',
});

const pass = new sfn.Pass(this, 'Success');
const storeOutputsToSsmStateMachine = new sfn.StateMachine(
this,
`${props.acceleratorPrefix}StoreOutputsToSsm_sm`,
{
stateMachineName: `${props.acceleratorPrefix}StoreOutputsToSsm_sm`,
definition: new StoreOutputsToSSMTask(this, 'StoreOutputsToSSM', {
lambdaCode,
role: pipelineRole,
}),
},
);

const storeAllOutputsToSsmTask = new sfn.Task(this, 'Store Outputs to SSM', {
// tslint:disable-next-line: deprecation
task: new tasks.StartExecution(storeOutputsToSsmStateMachine, {
integrationPattern: sfn.ServiceIntegrationPattern.SYNC,
input: {
'accounts.$': '$.accounts',
'regions.$': '$.regions',
acceleratorPrefix: props.acceleratorPrefix,
assumeRoleName: props.stateMachineExecutionRole,
outputsTableName: outputsTable.tableName,
configRepositoryName: props.configRepositoryName,
'configFilePath.$': '$.configFilePath',
'configCommitId.$': '$.configCommitId',
outputUtilsTableName: outputUtilsTable.tableName,
},
}),
resultPath: 'DISCARD',
});

const detachQuarantineScpTask = new CodeTask(this, 'Detach Quarantine SCP', {
functionProps: {
Expand All @@ -513,7 +555,7 @@ export namespace InitialSetup {
},
resultPath: 'DISCARD',
});
detachQuarantineScpTask.next(pass);
detachQuarantineScpTask.next(storeAllOutputsToSsmTask);

const enableTrustedAccessForServicesTask = new CodeTask(this, 'Enable Trusted Access For Services', {
functionProps: {
Expand Down Expand Up @@ -790,7 +832,7 @@ export namespace InitialSetup {

const baseLineCleanupChoice = new sfn.Choice(this, 'Baseline Clean Up?')
.when(sfn.Condition.stringEquals('$.baseline', 'ORGANIZATIONS'), detachQuarantineScpTask)
.otherwise(pass);
.otherwise(storeAllOutputsToSsmTask);

const commonStep1 = addScpTask.startState
.next(deployPhase1Task)
Expand Down
97 changes: 97 additions & 0 deletions src/core/cdk/src/tasks/store-outputs-to-ssm-task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as cdk from '@aws-cdk/core';
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import { CodeTask } from '@aws-accelerator/cdk-accelerator/src/stepfunction-tasks';

export namespace StoreOutputsToSSMTask {
export interface Props {
role: iam.IRole;
lambdaCode: lambda.Code;
functionPayload?: { [key: string]: unknown };
waitSeconds?: number;
}
}

export class StoreOutputsToSSMTask extends sfn.StateMachineFragment {
readonly startState: sfn.State;
readonly endStates: sfn.INextable[];

constructor(scope: cdk.Construct, id: string, props: StoreOutputsToSSMTask.Props) {
super(scope, id);

const { role, lambdaCode, functionPayload, waitSeconds = 10 } = props;

role.addToPrincipalPolicy(
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
resources: ['*'],
actions: ['logs:CreateLogGroup', 'logs:CreateLogStream', 'logs:PutLogEvents'],
}),
);

const storeAccountOutputs = new sfn.Map(this, `Store Account Outputs To SSM`, {
itemsPath: `$.accounts`,
resultPath: 'DISCARD',
maxConcurrency: 10,
parameters: {
'accountId.$': '$$.Map.Item.Value',
'regions.$': '$.regions',
'acceleratorPrefix.$': '$.acceleratorPrefix',
'assumeRoleName.$': '$.assumeRoleName',
'outputsTableName.$': '$.outputsTableName',
'configRepositoryName.$': '$.configRepositoryName',
'configFilePath.$': '$.configFilePath',
'configCommitId.$': '$.configCommitId',
'outputUtilsTableName.$': '$.outputUtilsTableName',
},
});

const getAccountInfoTask = new CodeTask(scope, `Get Account Details`, {
comment: 'Get Account Info',
resultPath: '$.account',
functionPayload,
functionProps: {
role,
code: lambdaCode,
handler: 'index.getAccountInfo',
},
});

const storeAccountRegionOutputs = new sfn.Map(this, `Store Account Region Outputs To SSM`, {
itemsPath: `$.regions`,
resultPath: 'DISCARD',
maxConcurrency: 10,
parameters: {
'account.$': '$.account',
'region.$': '$$.Map.Item.Value',
'acceleratorPrefix.$': '$.acceleratorPrefix',
'assumeRoleName.$': '$.assumeRoleName',
'outputsTableName.$': '$.outputsTableName',
'configRepositoryName.$': '$.configRepositoryName',
'configFilePath.$': '$.configFilePath',
'configCommitId.$': '$.configCommitId',
'outputUtilsTableName.$': '$.outputUtilsTableName',
},
});

getAccountInfoTask.next(storeAccountRegionOutputs);
const storeOutputsTask = new CodeTask(scope, `Store Outputs To SSM`, {
resultPath: '$.storeOutputsOutput',
functionPayload,
functionProps: {
role,
code: lambdaCode,
handler: 'index.saveOutputsToSSM',
},
});

const pass = new sfn.Pass(this, 'Store Outputs To SSM Success');
storeAccountOutputs.iterator(getAccountInfoTask);
storeAccountRegionOutputs.iterator(storeOutputsTask);
const chain = sfn.Chain.start(storeAccountOutputs).next(pass);

this.startState = chain.startState;
this.endStates = chain.endStates;
}
}
1 change: 1 addition & 0 deletions src/core/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export { handler as verifyFilesStep } from './verify-files-step';
export { handler as notifySMFailure } from './notify-statemachine-failure';
export { handler as notifySMSuccess } from './notify-statemachine-success';
export { handler as getAccountInfo } from './get-account-info';
export { handler as saveOutputsToSSM } from './save-outputs-to-ssm';

// TODO Replace with
// export * as codebuild from './codebuild';
Expand Down
Loading