Skip to content

Commit

Permalink
feat: add a new optional property tableDeletionProtection (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanfreitag committed Jul 27, 2023
1 parent 4c93afe commit 4fe3df6
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 53 deletions.
22 changes: 20 additions & 2 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/terraformStateBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ export class TerraformStateBackend extends Construct {

this.table = new dynamodb.Table(this, 'table', {
tableName: props.tableName,
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
deletionProtection: props.tableDeletionProtection ?? false,
partitionKey: {
name: 'LockID',
type: dynamodb.AttributeType.STRING,
},
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
pointInTimeRecovery: true,
removalPolicy: RemovalPolicy.DESTROY,
});
Expand Down
20 changes: 20 additions & 0 deletions src/terraformStateBackendProperties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
export interface TerraformStateBackendProperties{
/**
* The name of the bucket to create.
*
* @type {string}
* @memberof TerraformStateBackendProperties
*/
readonly bucketName: string;
/**
* The name of the DynamoDB table to create.
*
* @type {string}
* @memberof TerraformStateBackendProperties
*/
readonly tableName: string;

/**
* Whether to protect the created DynamoDB table from being accidentally deleted.
* @default false
* @type {boolean}
* @memberof TerraformStateBackendProperties
*/
readonly tableDeletionProtection?: boolean;
}
9 changes: 9 additions & 0 deletions test/terraformStateBackend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ describe('DynamoDB Configuration', () => {
new TerraformStateBackend(stack, 'backend', {
bucketName: '',
tableName: '',
tableDeletionProtection: true,
});
});

Expand All @@ -245,6 +246,14 @@ describe('DynamoDB Configuration', () => {
);
});

test('Non-default value for deletion protection', () => {
assertions.Template.fromStack(stack).hasResourceProperties(
'AWS::DynamoDB::Table',
{
DeletionProtectionEnabled: true,
},
);
});
test('[DynamoDB.2] DynamoDB tables should have point-in-time recovery enabled', () => {
assertions.Template.fromStack(stack).hasResourceProperties(
'AWS::DynamoDB::Table',
Expand Down
100 changes: 50 additions & 50 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4fe3df6

Please sign in to comment.