fix(ci): let the RDS unprotect step pass on a state that never created its instance - #486
Conversation
…d its instance A partially applied state whose apply failed on aws_db_instance.main stores outputs but no database_instance_identifier, and the script treated it as a pre-#1821 state and exited 1, so destroy-fargate-dev could never clean it up. When the identifier key is absent, read terraform state list: no aws_db_instance resource (any module path, exact type) means nothing to unprotect and exits 0; one present keeps the loud exit 1. A failing state list stays a failure. No identifier-prefix fallback. Closes #485
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour. 📝 WalkthroughWalkthroughThe script now checks Terraform state when ChangesRDS state handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The script can skip states that own no RDS instance without calling AWS, while retaining the error for an instance missing its identifier. No merge-blocking issue is identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
scripts/disable-owned-rds-deletion-protection.shnow exits 0 when a state has outputs but nodatabase_instance_identifierand noaws_db_instanceresource. Before this change it exited 1 on that state. This unblocksdestroy-fargate-dev.ymlon a partially applied stack.Why
Deploy run 37244250140 failed on
aws_db_instance.mainwithInsufficientDBInstanceCapacity. Thegithub-fargate-devstate kept the outputs of the resources that were created, but not the identifier, which depends on the instance. The script treated this state as a pre-#1821 state and told the operator to re-apply. No instance exists here, so nothing needs unprotecting, and re-applying fails again until AWS has capacity.Change
terraform -chdir="$STATE_DIR" state listand counts addresses ending in anaws_db_instanceresource (any module path, optional[index]). The match is on the exact type, soaws_db_instance_automated_backups_replication.xdoes not count.state listexits throughset -e. It is never read as "no instance". The count uses awk, so a matcher error is not mistaken for "no match".Tests
Added to
scripts/test-rds-deletion-protection-scope.sh. The terraform stub now dispatchesoutputandstate list.TF_STATE_LISTis read with?, so a case that reachesstate listwithout setting it fails.module.database.aws_db_instance.mainpresent: exit 1 with the remedy (the existing case, now given an explicit state list), plus an indexed rootaws_db_instance.main[0]casestate listfails: non-zero, no aws callsaws_db_instancedo not count as an instancePre-fix output (new suite run against the parent script):
(b) and (c) guard behaviour the parent already had, because the parent exits 1 on every absent key, so they cannot fail on the parent. Instead, I applied each of these mutations to the new script and confirmed the matching test fails:
state list || printf "": (c) fails/aws_db_instance/matcher: (d) failsVerification
bash scripts/test-rds-deletion-protection-scope.sh: passed 57, failed 0 (was 53)bash scripts/test-ecr-delete-selection.sh: passed 56, failed 0shellcheck -x scripts/disable-owned-rds-deletion-protection.sh: clean. The test file still has its three SC2016 info findings, the same ones it has on the parent, at lines this PR does not touch.Closes #485
🤖 Generated with claude-flow
Summary by CodeRabbit