-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Tag support for a stack with multiple apps (#326)
Currently, as noted by [this comment](https://github.com/guardian/cdk/blob/27543797cc5c2f0dbfcf5c262c5456c13e730a10/src/constructs/core/stack.ts#L11-L12), our constructs are tailored for single app stacks. We don't support a stack that has, for example, a frontend web app and an API app. If we were to create two ASGs in the same stack, they'd both get incorrectly tagged as the same "app". That is, we don't support micro-services very well. This change moves the app string into an interface, this interface is then extended by any construct's props if they need to be app-aware. As "app" is not in `GuStack` and we want to continue adding the "app" tag to resources, we're having to call `Tags.of(this).add("App", props.app);` a few more times, maybe there's a better solution here that keeps things DRY? Lastly, this is quite a big diff - a lot of the changes are within test files. I've tried to make each commit standalone, so it might be easier to review commit by commit? BREAKING CHANGE: - `GuStack` no longer takes knows about an "app" - Constructors for `GuAutoScalingGroup`, `GuUserData`, `GuParameterStoreReadPolicy`, `GuGetDistributablePolicy` and `GuInstanceRole` now require `props` - Props for `GuLambdaFunction`, `GuDatabaseInstance`, `GuInstanceTypeParameter` and `GuAmiParameter` now take an "app" prop
- Loading branch information
Showing
31 changed files
with
276 additions
and
188 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
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,52 @@ | ||
import "@aws-cdk/assert/jest"; | ||
import { Topic } from "@aws-cdk/aws-sns"; | ||
import { Stack } from "@aws-cdk/core"; | ||
import { alphabeticalTags } from "../../../test/utils"; | ||
import { AppIdentity } from "./identity"; | ||
|
||
describe("AppIdentity.suffixText", () => { | ||
it("should title case the app before suffixing it", () => { | ||
const actual = AppIdentity.suffixText({ app: "myapp" }, "InstanceType"); | ||
const expected = "InstanceTypeMyapp"; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it("should work with title case input", () => { | ||
const actual = AppIdentity.suffixText({ app: "MyApp" }, "InstanceType"); | ||
const expected = "InstanceTypeMyApp"; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it("should work with uppercase input", () => { | ||
const actual = AppIdentity.suffixText({ app: "MYAPP" }, "InstanceType"); | ||
const expected = "InstanceTypeMYAPP"; | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it("should handle hyphens", () => { | ||
const actual = AppIdentity.suffixText({ app: "my-app" }, "InstanceType"); | ||
const expected = "InstanceTypeMy-app"; | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe("AppIdentity.taggedConstruct", () => { | ||
it("should apply a tag to a resource", () => { | ||
// not using any Gu constructs to purely test the impact of AppIdentity.taggedConstruct | ||
const stack = new Stack(); | ||
|
||
const snsTopic = new Topic(stack, "myTopic"); | ||
const appIdentity: AppIdentity = { app: "testing" }; | ||
|
||
AppIdentity.taggedConstruct(appIdentity, snsTopic); | ||
|
||
expect(stack).toHaveResource("AWS::SNS::Topic", { | ||
Tags: alphabeticalTags([ | ||
{ | ||
Key: "App", | ||
Value: "testing", | ||
}, | ||
]), | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.