Skip to content

Commit 078d94f

Browse files
committed
more tags
1 parent 0a3afa9 commit 078d94f

File tree

6 files changed

+86
-19
lines changed

6 files changed

+86
-19
lines changed

.github/scripts/fix_cdk.json.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# script used to set context key values in cdk.json pre deployment from environment variables
5+
6+
# helper function to set string values
7+
fix_string_key() {
8+
KEY_NAME=$1
9+
KEY_VALUE=$2
10+
if [ -z "${KEY_VALUE}" ]; then
11+
echo "${KEY_NAME} value is unset or set to the empty string"
12+
exit 1
13+
fi
14+
echo "Setting ${KEY_NAME}"
15+
jq \
16+
--arg key_value "${KEY_VALUE}" \
17+
--arg key_name "${KEY_NAME}" \
18+
'.context += {($key_name): $key_value}' .build/cdk.json > .build/cdk.new.json
19+
mv .build/cdk.new.json .build/cdk.json
20+
}
21+
22+
# helper function to set boolean and number values (without quotes)
23+
fix_boolean_number_key() {
24+
KEY_NAME=$1
25+
KEY_VALUE=$2
26+
if [ -z "${KEY_VALUE}" ]; then
27+
echo "${KEY_NAME} value is unset or set to the empty string"
28+
exit 1
29+
fi
30+
echo "Setting ${KEY_NAME}"
31+
jq \
32+
--argjson key_value "${KEY_VALUE}" \
33+
--arg key_name "${KEY_NAME}" \
34+
'.context += {($key_name): $key_value}' .build/cdk.json > .build/cdk.new.json
35+
mv .build/cdk.new.json .build/cdk.json
36+
}
37+
38+
CFN_DRIFT_DETECTION_GROUP="vpc-resources"
39+
if [[ "$STACK_NAME" =~ -pr-[0-9]+$ ]]; then
40+
CFN_DRIFT_DETECTION_GROUP="vpc-resources-pull-request"
41+
fi
42+
43+
# go through all the key values we need to set
44+
fix_string_key accountId "${ACCOUNT_ID}"
45+
fix_string_key stackName "${STACK_NAME}"
46+
fix_string_key versionNumber "${VERSION_NUMBER}"
47+
fix_string_key commitId "${COMMIT_ID}"
48+
fix_string_key cfnDriftDetectionGroup "${CFN_DRIFT_DETECTION_GROUP}"
49+
fix_boolean_number_key logRetentionInDays "${LOG_RETENTION_IN_DAYS}"

.github/workflows/cdk_release_code.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,14 @@ jobs:
8181
role-to-assume: ${{ secrets.CLOUD_FORMATION_DEPLOY_ROLE }}
8282
role-session-name: eps-vpc-resources-deployment
8383
output-credentials: true
84-
84+
8585
- name: fix cdk.json for deployment
8686
run: |
87-
jq \
88-
--arg VERSION_NUMBER "${{ inputs.VERSION_NUMBER }}" \
89-
--arg COMMIT_ID "${{ inputs.COMMIT_ID }}" \
90-
--arg logRetentionInDays "${{ inputs.LOG_RETENTION_IN_DAYS }}" \
91-
'.context += {
92-
"VERSION_NUMBER": $VERSION_NUMBER,
93-
"COMMIT_ID": $COMMIT_ID,
94-
"logRetentionInDays": $logRetentionInDays}' \
95-
.build/cdk.json > .build/cdk.new.json
96-
mv .build/cdk.new.json .build/cdk.json
87+
./.github/scripts/fix_cdk_json.sh
88+
env:
89+
VERSION_NUMBER: "${{ inputs.VERSION_NUMBER }}"
90+
COMMIT_ID: "${{ inputs.COMMIT_ID }}"
91+
LOG_RETENTION_IN_DAYS: "${{ inputs.LOG_RETENTION_IN_DAYS }}"
9792

9893
- name: Show diff
9994
run: |

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,31 @@ cdk-deploy:
7272
--all \
7373
--ci true \
7474
--require-approval $${REQUIRE_APPROVAL} \
75+
--context accountId=$$ACCOUNT_ID \
7576
--context VERSION_NUMBER=$$VERSION_NUMBER \
7677
--context COMMIT_ID=$$COMMIT_ID \
78+
--context stackName=$$stack_name \
7779
--context logRetentionInDays=30
7880

7981
cdk-synth:
8082
npx cdk synth \
8183
--quiet \
8284
--app "npx ts-node --prefer-ts-exts packages/cdk/bin/VpcResourcesApp.ts" \
83-
--context VERSION_NUMBER=undefined \
84-
--context COMMIT_ID=undefined \
85-
--context logRetentionInDays=30
86-
85+
--context accountId=undefined \
86+
--context commitId=undefined \
87+
--context logRetentionInDays=30 \
88+
--context stackName=vpc-resources \
89+
--context versionNumber=undefined \
90+
--context commitId=undefined
8791
cdk-diff:
8892
npx cdk diff \
8993
--app "npx ts-node --prefer-ts-exts packages/cdk/bin/VpcResourcesApp.ts" \
9094
--context serviceName=$$service_name \
95+
--context accountId=$$ACCOUNT_ID \
9196
--context VERSION_NUMBER=$$VERSION_NUMBER \
9297
--context COMMIT_ID=$$COMMIT_ID \
93-
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS
98+
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS \
99+
--context stackName=$$stack_name
94100

95101
cdk-watch:
96102
REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \
@@ -102,6 +108,8 @@ cdk-watch:
102108
--all \
103109
--ci true \
104110
--require-approval $${REQUIRE_APPROVAL} \
111+
--context accountId=$$ACCOUNT_ID \
112+
--context stackName=$$stack_name \
105113
--context VERSION_NUMBER=$$VERSION_NUMBER \
106114
--context COMMIT_ID=$$COMMIT_ID \
107115
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS

cdk.context.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"acknowledged-issue-numbers": [
3+
34892,
4+
34892
5+
]
6+
}

cdk.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
7171
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
7272
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
73-
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false
73+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
74+
"cfnDriftDetectionGroup": "dummy_group"
7475
}
7576
}

packages/cdk/bin/VpcResourcesApp.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@ const app = new App()
99
- logRetentionInDays
1010
*/
1111

12-
const version = app.node.tryGetContext("VERSION_NUMBER")
13-
const commit = app.node.tryGetContext("COMMIT_ID")
12+
const accountId = app.node.tryGetContext("accountId")
13+
const stackName = app.node.tryGetContext("stackName")
14+
const version = app.node.tryGetContext("versionNumber")
15+
const commit = app.node.tryGetContext("commitId")
16+
const cfnDriftDetectionGroup = app.node.tryGetContext("cfnDriftDetectionGroup")
17+
1418
/* when getAz's is called behind the scenes it only returns the first 2 when the stack is account/region agnostic.
1519
Allow AZ's to be passed as context otherwise explicitly use the 3 in eu-west-2. */
1620
const availabilityZones = app.node.tryGetContext("AVAILABILITY_ZONES") || ["eu-west-2a", "eu-west-2b", "eu-west-2c"]
1721

1822
// add cdk-nag to everything
1923
Aspects.of(app).add(new AwsSolutionsChecks({verbose: true}))
2024

25+
Tags.of(app).add("accountId", accountId)
26+
Tags.of(app).add("stackName", stackName)
2127
Tags.of(app).add("version", version)
2228
Tags.of(app).add("commit", commit)
2329
Tags.of(app).add("cdkApp", "VpcResourcesApp")
30+
Tags.of(app).add("repo", "eps-vpc-resources")
31+
Tags.of(app).add("cfnDriftDetectionGroup", cfnDriftDetectionGroup)
2432

2533
const VpcResources = new VpcResourcesStack(app, "VpcResourcesStack", {
2634
env: {

0 commit comments

Comments
 (0)