-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Add Stack Set support #977
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
237 changes: 237 additions & 0 deletions
237
src/constructs/stack-set/__snapshots__/stack-set.test.ts.snap
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,237 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`The GuStackSet construct should correctly provision a stack with a stack set resource 1`] = ` | ||
Object { | ||
"Resources": Object { | ||
"StackSet": Object { | ||
"Properties": Object { | ||
"AutoDeployment": Object { | ||
"Enabled": true, | ||
"RetainStacksOnAccountRemoval": false, | ||
}, | ||
"Description": "this stack set provisions some common infrastructure", | ||
"Parameters": Array [], | ||
"PermissionModel": "SERVICE_MANAGED", | ||
"StackInstancesGroup": Array [ | ||
Object { | ||
"DeploymentTargets": Object { | ||
"OrganizationalUnitIds": Array [ | ||
"o-12345abcde", | ||
], | ||
}, | ||
"Regions": Array [ | ||
Object { | ||
"Ref": "AWS::Region", | ||
}, | ||
], | ||
}, | ||
], | ||
"StackSetName": "my-stack-set", | ||
"Tags": Array [ | ||
Object { | ||
"Key": "gu:cdk:version", | ||
"Value": "TEST", | ||
}, | ||
Object { | ||
"Key": "gu:repo", | ||
"Value": "guardian/cdk", | ||
}, | ||
Object { | ||
"Key": "Stack", | ||
"Value": "test", | ||
}, | ||
Object { | ||
"Key": "Stage", | ||
"Value": "INFRA", | ||
}, | ||
], | ||
"TemplateBody": "{ | ||
\\"Resources\\": { | ||
\\"accountloggingstreamB8733874\\": { | ||
\\"Type\\": \\"AWS::Kinesis::Stream\\", | ||
\\"Properties\\": { | ||
\\"ShardCount\\": 1, | ||
\\"RetentionPeriodHours\\": 24, | ||
\\"StreamEncryption\\": { | ||
\\"Fn::If\\": [ | ||
\\"AwsCdkKinesisEncryptedStreamsUnsupportedRegions\\", | ||
{ | ||
\\"Ref\\": \\"AWS::NoValue\\" | ||
}, | ||
{ | ||
\\"EncryptionType\\": \\"KMS\\", | ||
\\"KeyId\\": \\"alias/aws/kinesis\\" | ||
} | ||
] | ||
}, | ||
\\"Tags\\": [ | ||
{ | ||
\\"Key\\": \\"gu:cdk:version\\", | ||
\\"Value\\": \\"TEST\\" | ||
}, | ||
{ | ||
\\"Key\\": \\"gu:repo\\", | ||
\\"Value\\": \\"guardian/cdk\\" | ||
}, | ||
{ | ||
\\"Key\\": \\"Stack\\", | ||
\\"Value\\": \\"test\\" | ||
}, | ||
{ | ||
\\"Key\\": \\"Stage\\", | ||
\\"Value\\": \\"INFRA\\" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
\\"Conditions\\": { | ||
\\"AwsCdkKinesisEncryptedStreamsUnsupportedRegions\\": { | ||
\\"Fn::Or\\": [ | ||
{ | ||
\\"Fn::Equals\\": [ | ||
{ | ||
\\"Ref\\": \\"AWS::Region\\" | ||
}, | ||
\\"cn-north-1\\" | ||
] | ||
}, | ||
{ | ||
\\"Fn::Equals\\": [ | ||
{ | ||
\\"Ref\\": \\"AWS::Region\\" | ||
}, | ||
\\"cn-northwest-1\\" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}", | ||
}, | ||
"Type": "AWS::CloudFormation::StackSet", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`The GuStackSet construct should support parameters in the stack set instance 1`] = ` | ||
Object { | ||
"Resources": Object { | ||
"StackSet": Object { | ||
"Properties": Object { | ||
"AutoDeployment": Object { | ||
"Enabled": true, | ||
"RetainStacksOnAccountRemoval": false, | ||
}, | ||
"Description": "this stack set provisions some common infrastructure", | ||
"Parameters": Array [ | ||
Object { | ||
"ParameterKey": "CentralSnsTopicArn", | ||
"ParameterValue": Object { | ||
"Ref": "accountalertsD9982E6F", | ||
}, | ||
}, | ||
], | ||
"PermissionModel": "SERVICE_MANAGED", | ||
"StackInstancesGroup": Array [ | ||
Object { | ||
"DeploymentTargets": Object { | ||
"OrganizationalUnitIds": Array [ | ||
"o-12345abcde", | ||
], | ||
}, | ||
"Regions": Array [ | ||
Object { | ||
"Ref": "AWS::Region", | ||
}, | ||
], | ||
}, | ||
], | ||
"StackSetName": "my-stack-set", | ||
"Tags": Array [ | ||
Object { | ||
"Key": "gu:cdk:version", | ||
"Value": "TEST", | ||
}, | ||
Object { | ||
"Key": "gu:repo", | ||
"Value": "guardian/cdk", | ||
}, | ||
Object { | ||
"Key": "Stack", | ||
"Value": "test", | ||
}, | ||
Object { | ||
"Key": "Stage", | ||
"Value": "INFRA", | ||
}, | ||
], | ||
"TemplateBody": "{ | ||
\\"Parameters\\": { | ||
\\"CentralSnsTopicArn\\": { | ||
\\"Type\\": \\"String\\", | ||
\\"AllowedPattern\\": \\"arn:aws:[a-z0-9]*:[a-z0-9\\\\\\\\-]*:[0-9]{12}:.*\\" | ||
} | ||
} | ||
}", | ||
}, | ||
"Type": "AWS::CloudFormation::StackSet", | ||
}, | ||
"accountalertsD9982E6F": Object { | ||
"Properties": Object { | ||
"Tags": Array [ | ||
Object { | ||
"Key": "gu:cdk:version", | ||
"Value": "TEST", | ||
}, | ||
Object { | ||
"Key": "gu:repo", | ||
"Value": "guardian/cdk", | ||
}, | ||
Object { | ||
"Key": "Stack", | ||
"Value": "test", | ||
}, | ||
Object { | ||
"Key": "Stage", | ||
"Value": "INFRA", | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::SNS::Topic", | ||
}, | ||
"accountalertsPolicy8E37A8FA": Object { | ||
"Properties": Object { | ||
"PolicyDocument": Object { | ||
"Statement": Array [ | ||
Object { | ||
"Action": "sns:Publish", | ||
"Condition": Object { | ||
"StringEquals": Object { | ||
"aws:PrincipalOrgID": "o-12345abcde", | ||
}, | ||
}, | ||
"Effect": "Allow", | ||
"Principal": Object { | ||
"AWS": "*", | ||
}, | ||
"Resource": Object { | ||
"Ref": "accountalertsD9982E6F", | ||
}, | ||
"Sid": "0", | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"Topics": Array [ | ||
Object { | ||
"Ref": "accountalertsD9982E6F", | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::SNS::TopicPolicy", | ||
}, | ||
}, | ||
} | ||
`; |
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 @@ | ||
export * from "./stack-set"; |
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,70 @@ | ||
import { SynthUtils } from "@aws-cdk/assert"; | ||
import { OrganizationPrincipal } from "@aws-cdk/aws-iam"; | ||
import { Topic } from "@aws-cdk/aws-sns"; | ||
import { App } from "@aws-cdk/core"; | ||
import { RegexPattern } from "../../constants"; | ||
import { GuStackForInfrastructure, GuStackForStackSetInstance, GuStringParameter } from "../core"; | ||
import { GuKinesisStream } from "../kinesis"; | ||
import { GuSnsTopic } from "../sns"; | ||
import { GuStackSet } from "./stack-set"; | ||
|
||
describe("The GuStackSet construct", () => { | ||
it("should correctly provision a stack with a stack set resource", () => { | ||
const theStackSetInstance = new GuStackForStackSetInstance("the-stack-set", { stack: "test" }); | ||
new GuKinesisStream(theStackSetInstance, "account-logging-stream"); | ||
|
||
const parentStack = new GuStackForInfrastructure(new App(), "Test", { stack: "test" }); | ||
|
||
new GuStackSet(parentStack, "StackSet", { | ||
name: "my-stack-set", | ||
description: "this stack set provisions some common infrastructure", | ||
organisationUnitTargets: ["o-12345abcde"], | ||
stackSetInstance: theStackSetInstance, | ||
}); | ||
|
||
expect(SynthUtils.toCloudFormation(parentStack)).toMatchSnapshot(); | ||
}); | ||
|
||
it("should support parameters in the stack set instance", () => { | ||
const theStackSetInstance = new GuStackForStackSetInstance("the-stack-set", { stack: "test" }); | ||
Topic.fromTopicArn( | ||
theStackSetInstance, | ||
"central-topic", | ||
new GuStringParameter(theStackSetInstance, "CentralSnsTopicArn", { allowedPattern: RegexPattern.ARN }) | ||
.valueAsString | ||
); | ||
|
||
const awsOrgId = "o-12345abcde"; | ||
const parentStack = new GuStackForInfrastructure(new App(), "Test", { stack: "test" }); | ||
const centralTopic = new GuSnsTopic(parentStack, "account-alerts"); | ||
centralTopic.grantPublish(new OrganizationPrincipal(awsOrgId)); | ||
|
||
new GuStackSet(parentStack, "StackSet", { | ||
name: "my-stack-set", | ||
description: "this stack set provisions some common infrastructure", | ||
organisationUnitTargets: [awsOrgId], | ||
stackSetInstance: theStackSetInstance, | ||
stackSetInstanceParameters: { | ||
CentralSnsTopicArn: centralTopic.topicArn, | ||
}, | ||
}); | ||
|
||
expect(SynthUtils.toCloudFormation(parentStack)).toMatchSnapshot(); | ||
}); | ||
|
||
it("should error if the parent stack does not specify all parameters for the stack set instance template", () => { | ||
const theStackSetInstance = new GuStackForStackSetInstance("the-stack-set", { stack: "test" }); | ||
new GuStringParameter(theStackSetInstance, "CentralSnsTopic", { allowedPattern: RegexPattern.ARN }); | ||
|
||
const parentStack = new GuStackForInfrastructure(new App(), "Test", { stack: "test" }); | ||
|
||
expect(() => { | ||
new GuStackSet(parentStack, "StackSet", { | ||
name: "my-stack-set", | ||
description: "this stack set provisions some common infrastructure", | ||
organisationUnitTargets: ["o-12345abcde"], | ||
stackSetInstance: theStackSetInstance, | ||
}); | ||
}).toThrow("There are undefined stack set parameters: CentralSnsTopic"); | ||
}); | ||
}); |
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 find this naming very clear 👍