Skip to content

Commit 393e5c0

Browse files
authoredJan 9, 2025··
feat(appconfig): environment deletion protection (#32737)
### Issue # (if applicable) None ### Reason for this change AWS AppConfig environment supports [deletion protection](https://docs.aws.amazon.com/appconfig/latest/userguide/deletion-protection.html) and this feature is not configurable from AWS CDK. ### Description of changes - Add `DeletionProtectionCheck` enum - Add `deletionProtectionCheck` prop to `EnvironmentOption` There are two entities, `EnvironmentOptions` and `EnvironmentProps`, where `EnvironmentProps` is designed as an extension of `EnvironmentOptions` with the addition of an `application` prop. ```ts export interface EnvironmentProps extends EnvironmentOptions { /** * The application to be associated with the environment. */ readonly application: IApplication; } abstract class ApplicationBase extends cdk.Resource implements IApplication, IExtensible { public addEnvironment(id: string, options: EnvironmentOptions = {}): IEnvironment { return new Environment(this, id, { application: this, ...options, }); } ``` Therefore, the current argument addition has also been made to `EnvironmentOptions`. ### Describe any new or updated permissions being added None ### Description of how you validated changes Add both unit and integ test. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b670ba8 commit 393e5c0

File tree

13 files changed

+143
-75
lines changed

13 files changed

+143
-75
lines changed
 

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/appconfigenvironmentDefaultTestDeployAssert75BD28E7.assets.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/aws-appconfig-environment.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/aws-appconfig-environment.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"ApplicationId": {
127127
"Ref": "MyApplicationForEnv1F597ED9"
128128
},
129+
"DeletionProtectionCheck": "ACCOUNT_DEFAULT",
129130
"Description": "This is the environment for integ testing",
130131
"Monitors": [
131132
{

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/manifest.json

+2-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.js.snapshot/tree.json

+57-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-appconfig/test/integ.environment.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IntegTest } from '@aws-cdk/integ-tests-alpha';
22
import { App, Duration, PhysicalName, Stack } from 'aws-cdk-lib';
33
import { Alarm, ComparisonOperator, CompositeAlarm, Metric, TreatMissingData } from 'aws-cdk-lib/aws-cloudwatch';
44
import { Role, ServicePrincipal, Effect, PolicyStatement, PolicyDocument } from 'aws-cdk-lib/aws-iam';
5-
import { Application, ConfigurationContent, DeploymentStrategy, Environment, HostedConfiguration, Monitor, RolloutStrategy } from 'aws-cdk-lib/aws-appconfig';
5+
import { Application, ConfigurationContent, DeletionProtectionCheck, DeploymentStrategy, Environment, HostedConfiguration, Monitor, RolloutStrategy } from 'aws-cdk-lib/aws-appconfig';
66

77
const app = new App();
88

@@ -54,6 +54,7 @@ const compositeAlarm = new CompositeAlarm(stack, 'MyCompositeAlarm', {
5454
const env = new Environment(stack, 'MyEnvironment', {
5555
application: appForEnv,
5656
description: 'This is the environment for integ testing',
57+
deletionProtectionCheck: DeletionProtectionCheck.ACCOUNT_DEFAULT,
5758
monitors: [
5859
Monitor.fromCloudWatchAlarm(alarm),
5960
Monitor.fromCfnMonitorsProperty({

‎packages/aws-cdk-lib/aws-appconfig/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ const user = new iam.User(this, 'MyUser');
9696
env.grantReadConfig(user);
9797
```
9898

99+
### Deletion Protection Check
100+
101+
You can enable [deletion protection](https://docs.aws.amazon.com/appconfig/latest/userguide/deletion-protection.html) on the environment by setting the `deletionProtectionCheck` property.
102+
103+
- ACCOUNT_DEFAULT: The default setting, which uses account-level deletion protection. To configure account-level deletion protection, use the UpdateAccountSettings API.
104+
- APPLY: Instructs the deletion protection check to run, even if deletion protection is disabled at the account level. APPLY also forces the deletion protection check to run against resources created in the past hour, which are normally excluded from deletion protection checks.
105+
- BYPASS: Instructs AWS AppConfig to bypass the deletion protection check and delete an environment even if deletion protection would have otherwise prevented it.
106+
107+
```ts
108+
declare const application: appconfig.Application;
109+
declare const alarm: cloudwatch.Alarm;
110+
declare const compositeAlarm: cloudwatch.CompositeAlarm;
111+
112+
new appconfig.Environment(this, 'MyEnvironment', {
113+
application,
114+
deletionProtectionCheck: appconfig.DeletionProtectionCheck.APPLY,
115+
});
116+
```
99117

100118
## Deployment Strategy
101119

‎packages/aws-cdk-lib/aws-appconfig/lib/environment.ts

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IApplication } from './application';
44
import { IConfiguration } from './configuration';
55
import { ActionPoint, IEventDestination, ExtensionOptions, IExtension, IExtensible, ExtensibleBase } from './extension';
66
import { getHash } from './private/hash';
7+
import { DeletionProtectionCheck } from './util';
78
import * as cloudwatch from '../../aws-cloudwatch';
89
import * as iam from '../../aws-iam';
910
import { Resource, IResource, Stack, ArnFormat, PhysicalName, Names } from '../../core';
@@ -165,6 +166,13 @@ export interface EnvironmentOptions {
165166
* @default - No monitors.
166167
*/
167168
readonly monitors?: Monitor[];
169+
170+
/**
171+
* A property to prevent accidental deletion of active environments.
172+
*
173+
* @default undefined - AppConfig default is ACCOUNT_DEFAULT
174+
*/
175+
readonly deletionProtectionCheck?: DeletionProtectionCheck;
168176
}
169177

170178
/**
@@ -309,6 +317,7 @@ export class Environment extends EnvironmentBase {
309317
applicationId: this.applicationId,
310318
name: this.name,
311319
description: this.description,
320+
deletionProtectionCheck: props.deletionProtectionCheck,
312321
monitors: this.monitors?.map((monitor) => {
313322
return {
314323
alarmArn: monitor.alarmArn,

‎packages/aws-cdk-lib/aws-appconfig/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './deployment-strategy';
33
export * from './extension';
44
export * from './application';
55
export * from './configuration';
6+
export * from './util';
67

78
// AWS::AppConfig CloudFormation Resources:
89
export * from './appconfig.generated';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* The deletion protection check options.
3+
*/
4+
export enum DeletionProtectionCheck {
5+
/**
6+
* The default setting,
7+
* which uses account-level deletion protection. To configure account-level deletion protection, use the UpdateAccountSettings API.
8+
*/
9+
ACCOUNT_DEFAULT = 'ACCOUNT_DEFAULT',
10+
11+
/**
12+
* Instructs the deletion protection check to run,
13+
* even if deletion protection is disabled at the account level.
14+
*
15+
* APPLY also forces the deletion protection check to run against resources created in the past hour,
16+
* which are normally excluded from deletion protection checks.
17+
*/
18+
APPLY = 'APPLY',
19+
20+
/**
21+
* Instructs AWS AppConfig to bypass the deletion protection check and delete an environment or a configuration profile
22+
* even if deletion protection would have otherwise prevented it.
23+
*/
24+
BYPASS = 'BYPASS',
25+
}

‎packages/aws-cdk-lib/aws-appconfig/test/environment.test.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Template } from '../../assertions';
22
import { Alarm, CompositeAlarm, Metric } from '../../aws-cloudwatch';
33
import * as iam from '../../aws-iam';
44
import * as cdk from '../../core';
5-
import { Application, ConfigurationContent, Environment, HostedConfiguration, Monitor } from '../lib';
5+
import { Application, ConfigurationContent, DeletionProtectionCheck, Environment, HostedConfiguration, Monitor } from '../lib';
66

77
describe('environment', () => {
88
test('default environment', () => {
@@ -20,6 +20,27 @@ describe('environment', () => {
2020
});
2121
});
2222

23+
test.each([
24+
DeletionProtectionCheck.ACCOUNT_DEFAULT,
25+
DeletionProtectionCheck.APPLY,
26+
DeletionProtectionCheck.BYPASS,
27+
])('environment with deletion protection check', (deletionProtectionCheck) => {
28+
const stack = new cdk.Stack();
29+
const app = new Application(stack, 'MyAppConfig');
30+
new Environment(stack, 'MyEnvironment', {
31+
application: app,
32+
deletionProtectionCheck,
33+
});
34+
35+
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::Environment', {
36+
Name: 'MyEnvironment',
37+
ApplicationId: {
38+
Ref: 'MyAppConfigB4B63E75',
39+
},
40+
DeletionProtectionCheck: deletionProtectionCheck,
41+
});
42+
});
43+
2344
test('environment with name', () => {
2445
const stack = new cdk.Stack();
2546
const app = new Application(stack, 'MyAppConfig');

0 commit comments

Comments
 (0)
Please sign in to comment.