diff --git a/.changeset/tiny-steaks-jump.md b/.changeset/tiny-steaks-jump.md new file mode 100644 index 0000000000..b9671a3734 --- /dev/null +++ b/.changeset/tiny-steaks-jump.md @@ -0,0 +1,11 @@ +--- +"@guardian/cdk": major +--- + +BREAKING CHANGE: DevX Backups can no longer be enabled via the `withBackup` prop, which has been removed. + +Users should now opt-in/out of DevX Backups at the construct level (i.e. when defining an RDS instance, cluster or +DynamoDB table). + +We recommend using the `GuDatabaseInstance` or `GuDynamoTable` to help with this. If these constructs cannot be used, +resources can also be tagged like this: `Tags.of(myDatabase).add("devx-backup-enabled", "true")`. diff --git a/src/aspects/aws-backup.test.ts b/src/aspects/aws-backup.test.ts deleted file mode 100644 index 28fdcc538c..0000000000 --- a/src/aspects/aws-backup.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { App, Tags } from "aws-cdk-lib"; -import { Vpc } from "aws-cdk-lib/aws-ec2"; -import { DatabaseInstance, DatabaseInstanceEngine } from "aws-cdk-lib/aws-rds"; -import { GuStack } from "../constructs/core"; -import { GuTemplate } from "../utils/test"; - -describe("AwsBackupTag aspect", () => { - it("should add the 'devx-backup-enabled' tag as 'true' when backups are enabled", () => { - const app = new App(); - const stack = new GuStack(app, "Test", { stack: "test", stage: "TEST", withBackup: true }); - - const vpc = new Vpc(stack, "TestVpc"); - new DatabaseInstance(stack, "MyDatabase", { engine: DatabaseInstanceEngine.POSTGRES, vpc }); - - GuTemplate.fromStack(stack).hasGuTaggedResource("AWS::RDS::DBInstance", { - additionalTags: [ - { - Key: "devx-backup-enabled", - Value: "true", - }, - ], - }); - }); - - it("should allow the 'devx-backup-enabled' tag to be overridden", () => { - const app = new App(); - const stack = new GuStack(app, "Test", { - stack: "test", - stage: "TEST", - withBackup: true, // enable backups on all resources in this stack - }); - - const vpc = new Vpc(stack, "TestVpc"); - const database = new DatabaseInstance(stack, "MyDatabase", { engine: DatabaseInstanceEngine.POSTGRES, vpc }); - - // Disable backups on this one resource - Tags.of(database).add("devx-backup-enabled", "false"); - - GuTemplate.fromStack(stack).hasGuTaggedResource("AWS::RDS::DBInstance", { - additionalTags: [ - { - Key: "devx-backup-enabled", - Value: "false", - }, - ], - }); - }); -}); diff --git a/src/aspects/aws-backup.ts b/src/aspects/aws-backup.ts deleted file mode 100644 index 6785662438..0000000000 --- a/src/aspects/aws-backup.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { IAspect } from "aws-cdk-lib"; -import { CfnResource, TagManager } from "aws-cdk-lib"; -import type { IConstruct } from "constructs"; - -/** - * Applies the tags that enable backups for supported resources. - * - * @see https://github.com/guardian/aws-backup - */ -export class AwsBackupTag implements IAspect { - /** - * These resources are backed up by https://github.com/guardian/aws-backup. - */ - static resourceTypes: string[] = ["AWS::RDS::DBInstance", "AWS::DynamoDB::Table"]; - - public visit(node: IConstruct): void { - if (node instanceof CfnResource) { - const { cfnResourceType } = node; - - if (AwsBackupTag.resourceTypes.includes(cfnResourceType) && TagManager.isTaggable(node)) { - node.tags.setTag("devx-backup-enabled", "true"); - } - } - } -} diff --git a/src/constructs/core/stack.ts b/src/constructs/core/stack.ts index 865de13b93..0a553ca31f 100644 --- a/src/constructs/core/stack.ts +++ b/src/constructs/core/stack.ts @@ -2,7 +2,6 @@ import type { App, CfnElement, StackProps } from "aws-cdk-lib"; import { Annotations, Aspects, CfnParameter, LegacyStackSynthesizer, Stack, Tags } from "aws-cdk-lib"; import type { IConstruct } from "constructs"; import gitUrlParse from "git-url-parse"; -import { AwsBackupTag } from "../../aspects/aws-backup"; import { CfnIncludeReporter } from "../../aspects/cfn-include-reporter"; import { CfnParameterReporter } from "../../aspects/cfn-parameter-reporter"; import { Metadata } from "../../aspects/metadata"; @@ -46,15 +45,6 @@ export interface GuStackProps extends Omit { * please do not override this. */ withoutMetadata?: boolean; - - /** - * Set to enable all resources in the stack for backup provided by https://github.com/guardian/aws-backup. - * - * @default false - backups are not enabled - * - * @see https://github.com/guardian/aws-backup - */ - withBackup?: boolean; } /** @@ -125,14 +115,7 @@ export class GuStack extends Stack implements StackStageIdentity { // eslint-disable-next-line custom-rules/valid-constructors -- GuStack is the exception as it must take an App constructor(scope: App, id: string, props: GuStackProps) { - const { - cloudFormationStackName = process.env.GU_CFN_STACK_NAME, - stack, - stage, - app, - withoutTags, - withBackup = false, - } = props; + const { cloudFormationStackName = process.env.GU_CFN_STACK_NAME, stack, stage, app, withoutTags } = props; super(scope, id, { ...props, @@ -168,10 +151,6 @@ export class GuStack extends Stack implements StackStageIdentity { Aspects.of(this).add(new CfnIncludeReporter()); Aspects.of(this).add(new CfnParameterReporter()); - - if (withBackup) { - Aspects.of(this).add(new AwsBackupTag()); - } } /**