Skip to content

Commit

Permalink
Add X-Gu-CDK-Version tag to GuStack
Browse files Browse the repository at this point in the history
We can use this to track which stacks have been created using the library, and with which version.

The absence of this tag suggests the stack hasn't been created with the cdk library.
  • Loading branch information
akash1810 committed Feb 3, 2021
1 parent 6434fc5 commit dfb64d8
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/constants/library-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { version } from "../../package.json";

export const LibraryInfo = {
VERSION: version,
};

export const TrackingTag = {
Key: "X-Gu-CDK-Version",
Value: LibraryInfo.VERSION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -105,6 +109,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
6 changes: 4 additions & 2 deletions src/constructs/core/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import "@aws-cdk/assert/jest";
import { SynthUtils } from "@aws-cdk/assert";
import { Role, ServicePrincipal } from "@aws-cdk/aws-iam";
import { App } from "@aws-cdk/core";
import { simpleGuStackForTesting } from "../../../test/utils/simple-gu-stack";
import type { SynthedStack } from "../../../test/utils/synthed-stack";
import { simpleGuStackForTesting } from "../../../test/utils";
import type { SynthedStack } from "../../../test/utils";
import { Stage, Stages } from "../../constants";
import { TrackingTag } from "../../constants/library-info";
import { GuStack } from "./stack";

describe("The GuStack construct", () => {
Expand Down Expand Up @@ -54,6 +55,7 @@ describe("The GuStack construct", () => {
Ref: "Stage",
},
},
TrackingTag,
],
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/constructs/core/stack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { App, StackProps } from "@aws-cdk/core";
import { Stack, Tags } from "@aws-cdk/core";
import { TrackingTag } from "../../constants/library-info";
import { GuStackParameter, GuStageParameter } from "./parameters";

export interface GuStackProps extends StackProps {
Expand Down Expand Up @@ -42,6 +43,8 @@ export class GuStack extends Stack {
this._stack = new GuStackParameter(this);
this._app = props.app;

this.addTag(TrackingTag.Key, TrackingTag.Value);

this.addTag("Stack", this.stack);
this.addTag("Stage", this.stage);
this.addTag("App", props.app);
Expand Down
4 changes: 4 additions & 0 deletions src/constructs/iam/policies/__snapshots__/ses.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
12 changes: 12 additions & 0 deletions src/constructs/iam/roles/__snapshots__/instance-role.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -404,6 +408,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -616,6 +624,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
40 changes: 36 additions & 4 deletions src/constructs/lambda/__snapshots__/lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -159,6 +163,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -234,6 +242,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::ApiGateway::RestApi",
Expand Down Expand Up @@ -418,11 +430,15 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapi2Deployment4ECB93738ba48d7cb88b4c2b9ec5c442ee1c99e9": Object {
"lambdaapi2Deployment4ECB937324608a148e4c74ee74e20f580623b2d9": Object {
"DependsOn": Array [
"lambdaapi2proxyANY3F8E1D36",
"lambdaapi2proxyE68FDFBC",
Expand All @@ -439,7 +455,7 @@ Object {
"lambdaapi2DeploymentStageprodCC9E3016": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapi2Deployment4ECB93738ba48d7cb88b4c2b9ec5c442ee1c99e9",
"Ref": "lambdaapi2Deployment4ECB937324608a148e4c74ee74e20f580623b2d9",
},
"RestApiId": Object {
"Ref": "lambdaapi239350ECC",
Expand All @@ -462,6 +478,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::ApiGateway::Stage",
Expand Down Expand Up @@ -755,6 +775,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::ApiGateway::RestApi",
Expand Down Expand Up @@ -804,11 +828,15 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapiDeployment8E95B5854e05b687211f19a449136200fabf5846": Object {
"lambdaapiDeployment8E95B585b22be554088fbcc2c63fc037a54e995d": Object {
"DependsOn": Array [
"lambdaapiproxyANYA94E968A",
"lambdaapiproxyB573C729",
Expand All @@ -825,7 +853,7 @@ Object {
"lambdaapiDeploymentStageprod9598BC2F": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapiDeployment8E95B5854e05b687211f19a449136200fabf5846",
"Ref": "lambdaapiDeployment8E95B585b22be554088fbcc2c63fc037a54e995d",
},
"RestApiId": Object {
"Ref": "lambdaapiC1812993",
Expand All @@ -848,6 +876,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::ApiGateway::Stage",
Expand Down
6 changes: 4 additions & 2 deletions src/constructs/rds/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { SynthUtils } from "@aws-cdk/assert/lib/synth-utils";
import { Vpc } from "@aws-cdk/aws-ec2";
import { DatabaseInstanceEngine, ParameterGroup, PostgresEngineVersion } from "@aws-cdk/aws-rds";
import { Stack } from "@aws-cdk/core";
import { simpleGuStackForTesting } from "../../../test/utils/simple-gu-stack";
import type { SynthedStack } from "../../../test/utils/synthed-stack";
import { simpleGuStackForTesting } from "../../../test/utils";
import type { SynthedStack } from "../../../test/utils";
import { TrackingTag } from "../../constants/library-info";
import { GuDatabaseInstance } from "./instance";

describe("The GuDatabaseInstance class", () => {
Expand Down Expand Up @@ -100,6 +101,7 @@ describe("The GuDatabaseInstance class", () => {
Ref: "Stage",
},
},
TrackingTag,
],
});
});
Expand Down
8 changes: 8 additions & 0 deletions src/patterns/__snapshots__/scheduled-lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -156,6 +160,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
12 changes: 12 additions & 0 deletions src/patterns/__snapshots__/sns-lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::SNS::Topic",
Expand Down Expand Up @@ -89,6 +93,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -205,6 +213,10 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "0.31.0",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"inlineSources": true,
"experimentalDecorators": true,
"typeRoots": ["./node_modules/@types"],
"outDir": "lib"
"outDir": "lib",
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "test", "src/**/*.test.ts", "src/**/__snapshots__/**"]
Expand Down

0 comments on commit dfb64d8

Please sign in to comment.