Skip to content

Commit

Permalink
Merge pull request #233 from guardian/aa-tag-name
Browse files Browse the repository at this point in the history
refactor!: follow aws tag name convention of `org:something`
  • Loading branch information
akash1810 authored Feb 5, 2021
2 parents b7afa65 + 1ff1da8 commit 86bf433
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/constants/__mocks__/library-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export const LibraryInfo = {
};

export const TrackingTag = {
Key: "X-Gu-CDK-Version",
Key: "gu:cdk:version",
Value: LibraryInfo.VERSION,
};
2 changes: 1 addition & 1 deletion src/constants/library-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const LibraryInfo = {
};

export const TrackingTag = {
Key: "X-Gu-CDK-Version",
Key: "gu:cdk:version",
Value: LibraryInfo.VERSION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -55,10 +59,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -97,6 +97,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -109,10 +113,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
6 changes: 3 additions & 3 deletions src/constructs/core/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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";
import { alphabeticalTags, simpleGuStackForTesting } from "../../../test/utils";
import type { SynthedStack } from "../../../test/utils";
import { Stage, Stages } from "../../constants";
import { TrackingTag } from "../../constants/library-info";
Expand Down Expand Up @@ -38,7 +38,7 @@ describe("The GuStack construct", () => {
});

expect(stack).toHaveResource("AWS::IAM::Role", {
Tags: [
Tags: alphabeticalTags([
{
Key: "App",
Value: "MyApp",
Expand All @@ -56,7 +56,7 @@ describe("The GuStack construct", () => {
},
},
TrackingTag,
],
]),
});
});

Expand Down
5 changes: 5 additions & 0 deletions src/constructs/core/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ export class GuStack extends Stack {

/**
* A helper function to add a tag to all resources in a stack.
*
* Note: tags will be listed in alphabetical order during synthesis.
*
* @param key the tag name
* @param value the value of the tag
* @param applyToLaunchedInstances whether or not to apply the tag to instances launched in an ASG.
* @protected
*/
protected addTag(key: string, value: string, applyToLaunchedInstances: boolean = true): void {
// TODO add validation for `key` and `value`
// see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html
Tags.of(this).add(key, value, { applyToLaunchedInstances });
}

Expand Down
8 changes: 4 additions & 4 deletions src/constructs/iam/policies/__snapshots__/ses.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -104,10 +108,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
24 changes: 12 additions & 12 deletions src/constructs/iam/roles/__snapshots__/instance-role.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -145,10 +149,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -396,6 +396,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -408,10 +412,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -612,6 +612,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -624,10 +628,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down
72 changes: 36 additions & 36 deletions src/constructs/lambda/__snapshots__/lambda.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -109,10 +113,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
"Timeout": 30,
},
Expand Down Expand Up @@ -151,6 +151,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -163,10 +167,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -230,6 +230,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -242,10 +246,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::ApiGateway::RestApi",
Expand Down Expand Up @@ -418,6 +418,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -430,15 +434,11 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapi2Deployment4ECB937340ba28821c4d87686bb600192997b7b2": Object {
"lambdaapi2Deployment4ECB93739afe50d503afeac32f7e1b1edd2caf70": Object {
"DependsOn": Array [
"lambdaapi2proxyANY3F8E1D36",
"lambdaapi2proxyE68FDFBC",
Expand All @@ -455,7 +455,7 @@ Object {
"lambdaapi2DeploymentStageprodCC9E3016": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapi2Deployment4ECB937340ba28821c4d87686bb600192997b7b2",
"Ref": "lambdaapi2Deployment4ECB93739afe50d503afeac32f7e1b1edd2caf70",
},
"RestApiId": Object {
"Ref": "lambdaapi239350ECC",
Expand All @@ -466,6 +466,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -478,10 +482,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::ApiGateway::Stage",
Expand Down Expand Up @@ -763,6 +763,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -775,10 +779,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::ApiGateway::RestApi",
Expand Down Expand Up @@ -816,6 +816,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -828,15 +832,11 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::IAM::Role",
},
"lambdaapiDeployment8E95B58515e203156872c143be11756a3c89fbba": Object {
"lambdaapiDeployment8E95B5854a7d40530a7080bd25491376ccd199af": Object {
"DependsOn": Array [
"lambdaapiproxyANYA94E968A",
"lambdaapiproxyB573C729",
Expand All @@ -853,7 +853,7 @@ Object {
"lambdaapiDeploymentStageprod9598BC2F": Object {
"Properties": Object {
"DeploymentId": Object {
"Ref": "lambdaapiDeployment8E95B58515e203156872c143be11756a3c89fbba",
"Ref": "lambdaapiDeployment8E95B5854a7d40530a7080bd25491376ccd199af",
},
"RestApiId": Object {
"Ref": "lambdaapiC1812993",
Expand All @@ -864,6 +864,10 @@ Object {
"Key": "App",
"Value": "testing",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
},
Object {
"Key": "Stack",
"Value": Object {
Expand All @@ -876,10 +880,6 @@ Object {
"Ref": "Stage",
},
},
Object {
"Key": "X-Gu-CDK-Version",
"Value": "TEST",
},
],
},
"Type": "AWS::ApiGateway::Stage",
Expand Down
Loading

0 comments on commit 86bf433

Please sign in to comment.