Skip to content
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

Update: [AEA-4574] - Updates Stack and Resource Names #17

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/cdk_release_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ jobs:
- name: fix cdk.json for deployment
run: |
jq \
--arg serviceName "${{ inputs.SERVICE_NAME }}" \
--arg SERVICE_NAME "${{ inputs.SERVICE_NAME }}" \
--arg ENVIRONMENT "${{ inputs.TARGET_ENVIRONMENT }}" \
--arg VERSION_NUMBER "${{ inputs.VERSION_NUMBER }}" \
--arg COMMIT_ID "${{ inputs.COMMIT_ID }}" \
--argjson allowAutoDeleteObjects "${{ inputs.ALLOW_AUTO_DELETE_OBJECTS }}" \
'.context += {
"serviceName": $serviceName,
"SERVICE_NAME": $SERVICE_NAME,
"ENVIRONMENT": $ENVIRONMENT,
"VERSION_NUMBER": $VERSION_NUMBER,
"COMMIT_ID": $COMMIT_ID,
"allowAutoDeleteObjects": $allowAutoDeleteObjects
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
needs: [tag_release, package_code, get_commit_id]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: dev
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
needs: [tag_release, release_dev, package_code, get_commit_id]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: qa
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ jobs:
needs: [get_issue_number, package_code, get_commit_id, quality_checks]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources-pr-${{needs.get_issue_number.outputs.issue_number}}
TARGET_ENVIRONMENT: dev-pr
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: dev-pr-${{needs.get_issue_number.outputs.issue_number}}
VERSION_NUMBER: PR-${{ needs.get_issue_number.outputs.issue_number }}
COMMIT_ID: ${{ needs.get_commit_id.outputs.commit_id }}
CDK_APP_NAME: StorageResourcesApp
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
needs: [tag_release, package_code, get_commit_id]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: dev
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
needs: [tag_release, package_code, get_commit_id, release_dev]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: ref
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand All @@ -160,7 +160,7 @@ jobs:
needs: [tag_release, package_code, get_commit_id, release_dev]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: qa
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand All @@ -174,7 +174,7 @@ jobs:
needs: [tag_release, package_code, get_commit_id, release_qa]
uses: ./.github/workflows/cdk_release_code.yml
with:
SERVICE_NAME: storage-resources
SERVICE_NAME: eps-spine
TARGET_ENVIRONMENT: int
VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand All @@ -188,7 +188,7 @@ jobs:
# needs: [tag_release, package_code, get_commit_id, release_int]
# uses: ./.github/workflows/cdk_release_code.yml
# with:
# SERVICE_NAME: storage-resources
# SERVICE_NAME: eps-spine
# TARGET_ENVIRONMENT: prod
# VERSION_NUMBER: ${{needs.tag_release.outputs.version_tag}}
# COMMIT_ID: ${{needs.get_commit_id.outputs.commit_id}}
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ cdk-synth:
npx cdk synth \
--quiet \
--app "npx ts-node --prefer-ts-exts packages/cdk/bin/StorageResourcesApp.ts" \
--context SERVICE_NAME=undefined \
--context ENVIRONMENT=undefined \
--context VERSION_NUMBER=undefined \
--context COMMIT_ID=undefined

cdk-diff: guard-service_name
cdk-diff: guard-SERVICE_NAME guard-ENVIRONMENT
npx cdk diff \
--app "npx ts-node --prefer-ts-exts packages/cdk/bin/StorageResourcesApp.ts" \
--context serviceName=$$service_name \
--context SERVICE_NAME=$$SERVICE_NAME \
--context ENVIRONMENT=$$ENVIRONMENT \
--context VERSION_NUMBER=$$VERSION_NUMBER \
--context COMMIT_ID=$$COMMIT_ID

cdk-watch: guard-service_name
cdk-watch: guard-SERVICE_NAME guard-ENVIRONMENT
REQUIRE_APPROVAL="$${REQUIRE_APPROVAL:-any-change}" && \
VERSION_NUMBER="$${VERSION_NUMBER:-undefined}" && \
COMMIT_ID="$${COMMIT_ID:-undefined}" && \
Expand All @@ -87,6 +90,7 @@ cdk-watch: guard-service_name
--all \
--ci true \
--require-approval $${REQUIRE_APPROVAL} \
--context serviceName=$$service_name \
--context SERVICE_NAME=$$SERVICE_NAME \
--context ENVIRONMENT=$$ENVIRONMENT \
--context VERSION_NUMBER=$$VERSION_NUMBER \
--context COMMIT_ID=$$COMMIT_ID
9 changes: 6 additions & 3 deletions packages/cdk/bin/StorageResourcesApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const app = new App()
- logRetentionInDays
*/

const serviceName = app.node.tryGetContext("serviceName")
const serviceName = app.node.tryGetContext("SERVICE_NAME")
const environment = app.node.tryGetContext("ENVIRONMENT")
const stackPrefix = `nhse-${environment}-${serviceName}`

const version = app.node.tryGetContext("VERSION_NUMBER")
const commit = app.node.tryGetContext("COMMIT_ID")

Expand All @@ -19,10 +22,10 @@ Tags.of(app).add("version", version)
Tags.of(app).add("commit", commit)
Tags.of(app).add("cdkApp", "StorageResourcesApp")

new StorageResourcesStack(app, "StorageResourcesStack", {
new StorageResourcesStack(app, {
env: {
region: "eu-west-2"
},
stackName: `${serviceName}`,
stackPrefix: stackPrefix,
version: version
})
10 changes: 6 additions & 4 deletions packages/cdk/nagSuppressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {NagPackSuppression, NagSuppressions} from "cdk-nag"
export const nagSuppressions = (stack: Stack) => {
safeAddNagSuppression(
stack,
"/StorageResourcesStack/DynamoDB/TableReadManagedPolicy/Resource",
"/DynamoDB/TableReadManagedPolicy/Resource",
[
{
id: "AwsSolutions-IAM5",
Expand All @@ -17,7 +17,7 @@ export const nagSuppressions = (stack: Stack) => {

safeAddNagSuppression(
stack,
"/StorageResourcesStack/DynamoDB/TableWriteManagedPolicy/Resource",
"/DynamoDB/TableWriteManagedPolicy/Resource",
[
{
id: "AwsSolutions-IAM5",
Expand All @@ -30,10 +30,12 @@ export const nagSuppressions = (stack: Stack) => {

const safeAddNagSuppression = (stack: Stack, path: string, suppressions: Array<NagPackSuppression>) => {
try {
NagSuppressions.addResourceSuppressionsByPath(stack, path, suppressions)
const stack_id = stack.node.id
const full_path = `/${stack_id}${path}`
NagSuppressions.addResourceSuppressionsByPath(stack, full_path, suppressions)

// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch(err){
console.log(`Could not find path ${path}`)
console.log(`Could not find path ${path} in stack ${stack.node.id}`)
}
}
8 changes: 4 additions & 4 deletions packages/cdk/resources/Dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {Duration, RemovalPolicy} from "aws-cdk-lib"
import {ATTRIBUTE_KEYS, AttributeNames} from "./attributes"

export interface DynamodbProps {
readonly stackName: string
readonly stackPrefix: string
readonly account: string
readonly region: string
readonly allowAutoDeleteObjects: boolean
Expand All @@ -41,8 +41,8 @@ export class Dynamodb extends Construct {
const DatastoreKmsKey = new Key(this, "DatastoreKmsKey", {
removalPolicy: RemovalPolicy.DESTROY,
pendingWindow: Duration.days(7),
alias: `alias/${props.stackName}-DatastoreKmsKey`,
description: `${props.stackName}-DatastoreKmsKey`,
alias: `alias/${props.stackPrefix}-DatastoreKmsKey`,
description: `${props.stackPrefix}-DatastoreKmsKey`,
enableKeyRotation: true
})

Expand All @@ -68,7 +68,7 @@ export class Dynamodb extends Construct {
const DatastoreTable = new TableV2(this, "DatastoreTable", {
partitionKey: ATTRIBUTE_KEYS.PRIMARY_KEY,
sortKey: ATTRIBUTE_KEYS.SORT_KEY,
tableName: `${props.stackName}-datastore`,
tableName: `${props.stackPrefix}`,
removalPolicy: props.allowAutoDeleteObjects ? RemovalPolicy.DESTROY: RemovalPolicy.RETAIN,
pointInTimeRecovery: true,
encryption: TableEncryptionV2.customerManagedKey(DatastoreKmsKey),
Expand Down
18 changes: 9 additions & 9 deletions packages/cdk/stacks/StorageResourcesStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {nagSuppressions} from "../nagSuppressions"
import {Dynamodb} from "../resources/Dynamodb"

export interface StorageResourcesStackProps extends StackProps{
readonly stackName: string
readonly stackPrefix: string
readonly version: string
}

Expand All @@ -18,8 +18,8 @@ export interface StorageResourcesStackProps extends StackProps{
*/

export class StorageResourcesStack extends Stack {
public constructor(scope: App, id: string, props: StorageResourcesStackProps){
super(scope, id, props)
public constructor(scope: App, props: StorageResourcesStackProps){
super(scope, props.stackPrefix, props)

// Context
/* context values passed as --context cli arguments are passed as strings so coerce them to expected types*/
Expand All @@ -29,7 +29,7 @@ export class StorageResourcesStack extends Stack {

// Resources
const dynamodb = new Dynamodb(this, "DynamoDB", {
stackName: props.stackName,
stackPrefix: props.stackPrefix,
account: this.account,
region: this.region,
allowAutoDeleteObjects: allowAutoDeleteObjects
Expand All @@ -40,23 +40,23 @@ export class StorageResourcesStack extends Stack {
//Exports
new CfnOutput(this, "tableWriteManagedPolicyArn", {
value: dynamodb.tableWriteManagedPolicy.managedPolicyArn,
exportName: `${props.stackName}:tableWriteManagedPolicy:Arn`
exportName: `${props.stackPrefix}:tableWriteManagedPolicy:Arn`
})
new CfnOutput(this, "tableReadManagedPolicyArn", {
value: dynamodb.tableReadManagedPolicy.managedPolicyArn,
exportName: `${props.stackName}:tableReadManagedPolicy:Arn`
exportName: `${props.stackPrefix}:tableReadManagedPolicy:Arn`
})
new CfnOutput(this, "usePrescriptionsTableKmsKeyPolicyArn", {
value: dynamodb.usePrescriptionsTableKmsKeyPolicy.managedPolicyArn,
exportName: `${props.stackName}:usePrescriptionsTableKmsKeyPolicy:Arn`
exportName: `${props.stackPrefix}:usePrescriptionsTableKmsKeyPolicy:Arn`
})
new CfnOutput(this, "DatastoreTableArn", {
value: dynamodb.DatastoreTable.tableArn,
exportName: `${props.stackName}:DatastoreTable:Arn`
exportName: `${props.stackPrefix}:DatastoreTable:Arn`
})
new CfnOutput(this, "DatastoreKmsKeyArn", {
value: dynamodb.DatastoreKmsKey.keyArn,
exportName: `${props.stackName}:DatastoreKmsKey:Arn`
exportName: `${props.stackPrefix}:DatastoreKmsKey:Arn`
})
nagSuppressions(this)
}
Expand Down
Loading