stackql / stackql/stackql-deploy-rs
[FEATURE] `predelete` hook: run a statement or script before a resource's `delete`
まだ誰も着手していません。
- 主要言語
- Rust
- スター
- 1
- フォーク
- 0
- 平均マージ
- 12分
- マージ済み PR(30日)
- 4
説明
Problem
Some resources cannot be deleted until something else is done to them first, and that something is not expressible as a single statement in the resource's .iql file. The canonical case is an S3 bucket: DeleteBucket fails with 409 BucketNotEmpty (surfaced by stackql as no response body for operation = DeleteBucket) while the bucket holds objects, and emptying a bucket needs an object listing loop (and a version listing loop for versioned buckets). A Databricks workspace root bucket is never empty at teardown time because the control plane writes DBFS and log data into it.
Today the only options are:
skip_on_delete: trueon the bucket, which retains it (fine when the data should be kept, wrong when it should not),--on-failure ignore, which finishes the teardown but leaves the bucket behind, or- an out-of-band
aws s3 rm --recursivebefore runningteardown.
Other resources with the same shape: ECR repositories with images, Cognito user pools with a deletion protection flag, RDS instances with deletion protection, Key Vaults with soft delete, GitHub repositories with branch protection rules, or any resource where a dependent that is not managed by the stack has to be cleared first.
Proposal
A predelete hook that teardown runs for a resource after the exists check reports the resource present and before its delete statement. Two forms:
- A
/*+ predelete */anchor in the resource's.iqlfile for cases that are a single statement (for example flipping a deletion protection property with anUPDATE, or aDELETEon a dependent resource that the provider can address in one call). Rendered with the same context asdelete, includingthis.*fields captured by the exists check. - A
predeletescript in the manifest for cases that need a loop or an external tool, using the same contract astype: scriptresources (run withsh -c, exports optional):
- name: aws/s3/root_bucket
file: aws/s3/bucket.iql
predelete:
run: aws s3 rm s3://{{ root_bucket_name }} --recursive
props:
- name: bucket_name
value: "{{ root_bucket_name }}"
If both are present the anchor runs first, then the script.
Behaviour to pin down
- Ordering. exists check, then
predelete, thendelete, thencallback:delete, then the post-delete check (perpostdelete_retries/postdelete_retry_delay). When the delete is re-issued (thedeleteanchor'sretries),predeleteshould run again before each attempt, since the reason for the retry may be that more objects appeared. - Failure. A failing
predeleteis a failed delete: abort under--on-failure error, log and report the resource as not confirmed deleted under--on-failure ignore. Fatal errors abort in both modes. - Dry run. Render and log the anchor / script without executing, like
delete. - Not run when the resource does not exist, when the resource has
skip_on_delete: true, or when the delete is skipped because a query references an export that could not be collected. - Not run by
buildortest. - Idempotency is the author's responsibility, as with
scriptresources; document that apredeletemay run more than once per teardown. - The anchor form should support the usual options (
retries,retry_delay).
Related
- #56 / #57:
skip_on_delete,--on-failure ignoreand the end-of-run summary of unconfirmed deletes, which are the current workarounds. - The
tests/live_stacks/aws_ssm_onfailurelive stack already has an S3DeleteBucketfailure case; apredeletethat empties a bucket could be exercised there, or in a small dedicated S3 stack (an empty standard bucket is free).
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず teardown の削除フローと既存の type: script リソース契約を読み、次に既存の S3 DeleteBucket 失敗ケースについて tests/live_stacks/aws_ssm_onfailure を確認します。ここで説明されている順序、リトライ、失敗、dry-run、スキップ、冪等性の動作を定義してテストします。predelete アンカーとマニフェストスクリプトが build や test に影響を与えずに動作すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust, shell, yaml
- 領域
- cloud, devops, infrastructure
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100