用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill terraform-refactoring命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | terraform-refactoring |
| description | >- Use when this capability is needed. |
Turns architecture changes into reviewable, incremental plans. Pair with terraform-core for
syntax of moved/import and terraform-state for CLI surgery fallback.
Communicate renames to Terraform without state mv:
moved {
from = aws_lambda_function.imu
to = module.compute.aws_lambda_function.imu
}
Order matters in complex chains; combine with PR notes explaining blast radius.
Stop managing something but leave it running:
removed {
from = aws_s3_bucket.legacy_tmp
lifecycle {
destroy = false
}
}
Document who owns lifecycle going forward - otherwise you accumulate orphans nobody understands.
Bring existing resources into code with review:
import {
to = aws_kinesis_stream.imu_ingest
id = "arn:aws:kinesis:us-east-1:111111111111:stream/prod-imu-ingest"
}
resource "aws_kinesis_stream" "imu_ingest" {
name = "prod-imu-ingest"
stream_mode_details {
stream_mode = "ON_DEMAND"
}
}
Validate import ID format per resource docs - typos cause confusing partial imports.
moved blocks mapping old addresses to module.foo.*.terraform plan should show no-op; if not, fix addresses before apply.Usually harder - watch for_each key changes. Sometimes migrate in two phases: create parallel resources, cut traffic, destroy old (expensive). Prefer feature flags in applications to tolerate duplicate infra briefly.
Terraform considers resource name changes as destroy/create. Use moved or state mv to keep
identity.
lifecycle { create_before_destroy = true } where supported.Force replacement when tangential resources change (e.g., launch template version) - see terraform-core.
plan -refresh-only to align state with actual.state rm.For risky PRs, include Risk, Rollback, Customer impact, Monitoring - even infra-only changes deserve this to align SRE.
Terraform lacks auto rollbacks - keep previous git tag and plan.bin artifact for supervised
terraform apply of older revision when safe.
Avoid mixing provider major bumps with big refactors - separate PRs reduce unknowns when plans explode.
Run terraform test with mocks + integration plan in staging workspace with copied state (where
permitted).
Targeting masks missing dependencies - acceptable temporarily, not as a lifestyle.
Refactor one axis per PR: names OR module split OR provider bump - not all three simultaneously.
Add temporary dashboards measuring error rates; if Terraform swap correlates with spikes, pause and rollback per playbook.
Some refactors need aws_db_instance snapshot before replace - Terraform orchestrates snapshot
identifier attributes where supported; otherwise use runbook-managed snapshots.
Before apply, terraform state pull to timestamped object - store encrypted.
If apply fails mid-way, do not immediately re-apply - read error, check partial resources, consult
terraform plan for remainder; sometimes refresh needed.
When multiple squads touch shared modules, freeze interface changes during critical business windows (Black Friday, quarter close).
Update architecture diagrams in the same PR as refactors - reviewers catch mistaken moved targets
faster with visuals.
Mystery errors → terraform-troubleshooting. Secrets handling → terraform-secrets.
If you must change map keys, use temporary moved chains or accept one-time recreation - plan cost with
owners.
Compute expression outcomes (merge of tags) in console to predict plan noise before editing dozens
of files.
Refactors that replace SKUs (RI commitments) need finance ack - Terraform changes have dollar sequelae.
Delete dead variables/outputs after migration completes; dead API surfaces confuse module users.
Track remaining FIXME moved blocks in backlog; temporary scaffolding ossify into permanent risk.
Disciplined refactors feel slow - fast merges that skip planning cause weekend outages that cost more than patience ever would.
moved/import with comments.When refactors touch compliance controls, attach plan files (sanitized) to change tickets - auditors prefer deterministic evidence over oral summaries.
Run terraform graph | dot -Tsvg for large systems sparingly - visualizations help explain why certain
resources must move together; archive SVGs in design docs for onboarding.
Sometimes module split requires two-phase delivery: deploy new remote state outputs before switching consumers - coordinate PR merges across repos with a shared checklist.
If refactor needs ETL (S3 object rewrite, Dynamo scans), assign explicit DBA/data engineer owners; Terraform provisions buckets, scripts run elsewhere - blur causes half-migrated datasets.
Streaming systems (Kinesis/Pub/Sub) may need schema registry updates separate from Terraform - note dependencies in PR body so consumers deploy coordinated releases.
When renaming resources risks billingAllocation tags shifting, notify FinOps before apply - they may need to remap chargeback rules.
After refactor, verify CloudWatch log groups / alarms still reference correct ARNs - grep for old log group names in dashboards JSON.
Occasionally destroy/create is cheaper/safer than clever moved gymnastics (ephemeral caches).
Document customer impact windows honestly.
Refactoring is risk management dressed as code shuffling - treat it with the seriousness of a prod deploy, because it is one.
If using Terraform Cloud, queue refactors behind feature work when using same workspace - serialized runs avoid conflicting state versions; communicate queue expectations in Slack.
Refactors tested locally with local backend may behave differently on remote exec due to env
vars - mirror CI variables in .envrc or documented shells.
Set CODEOWNERS paths for moved/import heavy directories so platform seniors always review - junior
edits to migration blocks are high risk.
Run tflint --fix cautiously - auto-fix altering comments or ordering can obscure subtle diffs; prefer
explicit human formatting commits.
After refactor, terraform plan should be calmer (fewer tangled replaces). Track plan line
count metrics over weeks - spikes warrant retros.
For uncertain migrations, clone workspace with copied state subset (where safe) to rehearse; destroy canary after - some orgs forbid state copying; respect policy.
Temporary var.enable_legacy_resource booleans help gradual migration - delete toggles once stable to
avoid permanent complexity.
Store Architecture Decision Records beside code referencing WHY moved blocks exist - future teams won’t
reverse refactors safely without rationale.
Pair senior+junior on first refactor PR after onboarding - reading moves is easier with narration.
If refactor causes incident, capture signals that plans underplayed risk - improve checklists, not individuals.
Pre-commit hook blocking terraform destroy without ALLOW_DESTROY=1 env var prevents accidents
during local experimentation - trivial to bypass intentionally, but stops muscle-memory mistakes.
Multi-week refactors need executive summaries monthly - translate technical milestones into business risk reduction language.
Validate dashboards, on-call playbooks, and customer status pages reference new resource names - human docs lag Terraform easily.
When splitting modules, publish temporary duplicate outputs (legacy_alb_dns, alb_dns) until
downstream stacks cut over - communicate deprecation timelines in Slack #infra-announce.
Terragrunt dependency outputs may reorder applies - verify mock_outputs during refactor windows - see
terraform-terragrunt.
Before merging, grep -R 'aws_lambda_function.imu' -n to catch lingering documentation snippets
pointing to old addresses - confuses operators during incidents.
If plan time doubles due to expanded graphs, consider splitting stacks rather than micro-optimizing expressions - time is money in CI.
When expecting destroys, copy plan JSON to spreadsheet highlighting each destroy with owner sign-off - no mass “LGTM” on thousand-line destroys.
Give sample CloudWatch queries / traces showing successful behavior post-refactor - evidence calms nervous partners faster than Terraform alone.
Some datasets cannot be destroyed - prevent_destroy alone insufficient; legal may require retaining
specific buckets - note holds in module README to block naive destroys.
Sleep on gigantic refactors; fresh eyes catch missing moved blocks better than caffeinated 2 AM
eyes - schedule reviews with timezone diversity when feasible.
Celebrate successful refactors briefly - teams that only spotlight outages under-invest in incremental hygiene; a quick kudos message reinforces discipline.
Archive plan JSON line counts before/after refactors - even if imperfect, trending downward signals simpler systems worth sustaining.
Capture Terraform CLI and provider versions in those archives - forensics without version context misattributes regressions to the wrong commit.
Source: eclosion-labs/terraform-cursor-plugin — distributed by TomeVault.