Skip to content

feat(dynamodb): implement deletion_protection_enabled#380

Merged
vieiralucas merged 2 commits intomainfrom
worktree-tfacc-ddb-deletion-protection
Apr 14, 2026
Merged

feat(dynamodb): implement deletion_protection_enabled#380
vieiralucas merged 2 commits intomainfrom
worktree-tfacc-ddb-deletion-protection

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 14, 2026

Summary

Batch 11 — first batch driving the DynamoDB tfacc deny-list down. Implements `deletion_protection_enabled`.

Real AWS DynamoDB lets you mark a table as deletion-protected via `CreateTable` and `UpdateTable`, and rejects `DeleteTable` while the flag is set with `ResourceInUseException`. fakecloud was ignoring the attribute entirely — DescribeTable returned nothing, so Terraform's `aws_dynamodb_table` provider saw drift on every refresh and the upstream `TestAccDynamoDBTable_deletion_protection` test failed.

  • `DynamoTable` state struct gains `deletion_protection_enabled`
  • `CreateTable` parses `DeletionProtectionEnabled` from the request
  • `UpdateTable` can toggle it
  • `DescribeTable` always returns it
  • `DeleteTable` refuses with `ResourceInUseException` while it's enabled

Removes `TestAccDynamoDBTable_deletion_protection` from the tfacc deny-list. First entry to be driven from the deny-list to zero — the harness is now closing its own gaps.

Test plan

  • New e2e test `dynamodb_deletion_protection_blocks_delete_table` covers the full lifecycle (create → describe → delete denied → update → delete allowed) — passes
  • `cargo test -p fakecloud-dynamodb` clean (93 unit tests)
  • `cargo clippy -p fakecloud-dynamodb -p fakecloud-tfacc -p fakecloud-e2e -p fakecloud-cloudformation --all-targets -- -D warnings` clean
  • Upstream locally: `TestAccDynamoDBTable_deletion_protection` passes (~14s)
  • CI `tfacc dynamodb` green with the wider allow-list
  • Other tfacc jobs still green
  • Cubic clean

Summary by cubic

Add DynamoDB table deletion protection and enforce it on delete to match AWS behavior. DescribeTable now returns the flag to prevent Terraform drift; CloudFormation now honors DeletionProtectionEnabled.

  • New Features

    • Support DeletionProtectionEnabled on CreateTable, UpdateTable, and DescribeTable.
    • Reject DeleteTable with ResourceInUseException when protection is enabled.
    • Persist deletion_protection_enabled in DynamoTable (default false); add an e2e lifecycle test and enable TestAccDynamoDBTable_deletion_protection in tfacc.
  • Bug Fixes

    • Validate non-empty KeySchema on CreateTable and return ValidationException.
    • CloudFormation: honor DeletionProtectionEnabled for AWS::DynamoDB::Table (accepts bool or string) instead of defaulting to false.

Written for commit 17e2e43. Summary will update on new commits.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-cloudformation/src/resource_provisioner.rs">

<violation number="1" location="crates/fakecloud-cloudformation/src/resource_provisioner.rs:696">
P2: CloudFormation table creation ignores the `DeletionProtectionEnabled` property by hardcoding `deletion_protection_enabled` to `false`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-cloudformation/src/resource_provisioner.rs Outdated
Real AWS DynamoDB lets you mark a table as deletion-protected via
CreateTable and UpdateTable, and rejects DeleteTable while the flag
is set with ResourceInUseException. fakecloud was ignoring the
attribute entirely — DescribeTable returned nothing, so Terraform's
`aws_dynamodb_table` provider saw drift on every refresh, and the
upstream `TestAccDynamoDBTable_deletion_protection` test failed.

- DynamoTable state struct gains `deletion_protection_enabled`
- CreateTable parses `DeletionProtectionEnabled` from the request
- UpdateTable can toggle it
- DescribeTable always returns it
- DeleteTable refuses with ResourceInUseException while it's enabled

New e2e test dynamodb_deletion_protection_blocks_delete_table covers
the full lifecycle: create-protected → describe → delete (denied) →
update-clear → delete (allowed).

Removes `TestAccDynamoDBTable_deletion_protection` from the tfacc
deny-list. First entry to be driven from the deny-list to zero.
@vieiralucas vieiralucas force-pushed the worktree-tfacc-ddb-deletion-protection branch from 769e7a7 to 0207bb0 Compare April 14, 2026 17:40
…::Table

Cubic flagged that the CFN provisioner was hardcoding
deletion_protection_enabled=false when creating a DynamoDB table,
ignoring the property if the template specified it. Now reads the
property from the resource's CloudFormation properties (accepting
both bool and string-typed values, since CFN templates often use
strings).
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-cloudformation/src/resource_provisioner.rs">

<violation number="1" location="crates/fakecloud-cloudformation/src/resource_provisioner.rs:700">
P1: `DeletionProtectionEnabled` is persisted on create but not enforced on delete in this provisioner, so protected tables can still be deleted via the CloudFormation path.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

stream_records: Arc::new(RwLock::new(Vec::new())),
sse_type: None,
sse_kms_key_arn: None,
deletion_protection_enabled,
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: DeletionProtectionEnabled is persisted on create but not enforced on delete in this provisioner, so protected tables can still be deleted via the CloudFormation path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/fakecloud-cloudformation/src/resource_provisioner.rs, line 700:

<comment>`DeletionProtectionEnabled` is persisted on create but not enforced on delete in this provisioner, so protected tables can still be deleted via the CloudFormation path.</comment>

<file context>
@@ -692,8 +697,7 @@ impl ResourceProvisioner {
             sse_kms_key_arn: None,
-
-            deletion_protection_enabled: false,
+            deletion_protection_enabled,
         };
 
</file context>
Fix with Cubic

@vieiralucas vieiralucas merged commit 241228f into main Apr 14, 2026
35 checks passed
@vieiralucas vieiralucas deleted the worktree-tfacc-ddb-deletion-protection branch April 14, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant