sdaf-state-management
Skill145 starsChanged 3 months agoMITView on GitHub
Inspect and repair SDAF Terraform state safely before any reviewed import/remove. Grounded in `docs/local/07-00-operations.md § Manage state safely`, `docs/local/troubleshooting.md § Terraform reports a state lock`, and `deploy/scripts/advanced_state_management.sh`. Use when a user says "advanced_state_management.sh", "terraform state list", "state import", "state rm", "repair SDAF state", "remote state disagrees with Azure", or "who owns this state lock". Do NOT use for teardown, reverse-order destroy, ARM fallback, or an unclassified failed run.
In this repository21 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- Webapp/.github/copilot-instructions.mdCopilot instructions
- code-reviewSkill
- sdaf-bom-selectionSkill
- sdaf-control-plane-bootstrapSkill
- sdaf-failure-triageSkill
- sdaf-ha-diagnosticsSkill
- sdaf-ha-topologySkill
- sdaf-media-acquisitionSkill
- sdaf-media-diagnosticsSkill
- sdaf-orientation-and-surfaceSkill
- sdaf-plan-and-test-semanticsSkill
- sdaf-quality-assuranceSkill
- sdaf-readiness-checkSkill
- sdaf-safe-removalSkill
- sdaf-sap-installationSkill
- sdaf-sap-systemSkill
- sdaf-sovereign-cloudSkill
- sdaf-workload-zoneSkill
- sdaf-workspace-and-tfvarsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 8 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
Do NOT trigger on: destroy / teardown / ARM fallback / reverse-order removal, remover.sh, remove_controlplane.sh, hosted removal wrappers, …
- Very specific: line 55
If the user is trying to delete resources or finish an incomplete teardown, route to sdaf-safe-removal.
- Distinctive: line 73
Before changing anything, confirm the checked-out script contract:
- Distinctive: line 106
Do not shorten, pattern-match, or guess a Terraform address or Azure resource ID.
- Very specific: line 108
Do not use state rm to bypass a replacement, to make an incomplete removal look clean, or as a substitute for a destroy plan.
- Distinctive: line 112
If the docs, script output, Azure resource lookup, and stored metadata do not line up cleanly, say docs are insufficient for a safe …
- Distinctive: line 116
After any reviewed import/remove:
- Distinctive: line 126
Never synthesize destructive state edits, generic unlock commands, or an undeclared hosted recovery wrapper.
- Very specific: line 128
Do not treat list as read-only.
- Distinctive: line 130
Do not run two execution models concurrently against the same state.
- Distinctive: line 131
Do not treat local backend metadata as the authoritative state record.
- Distinctive: line 134
Does not perform teardown, destroy, ARM fallback, or generic failed-run triage.
- Very specific: line 135
Does not invent a terraform force-unlock procedure or approve import/remove without backups and exact identifiers.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SDAF State Management
Action-loop skill. Canonical owner of the warning that
advanced_state_management.sh re-inits on every op. Uses only the reviewed
list / import / remove path documented in the repo and the checked-out
script's own --help; refuses to invent a generic unlock or teardown path.
When to invoke
Trigger on: advanced_state_management.sh, "terraform state list", "state import",
"state rm", "repair remote state", "backend metadata", "resources.lst", "state lock
owner", "remote tfstate disagrees with Azure".
Do NOT trigger on: destroy / teardown / ARM fallback / reverse-order removal,
remover.sh, remove_controlplane.sh, hosted removal wrappers, or a failed run
whose symptom is still ambiguous.
Preconditions
- The operator has an approved state operation (
docs/local/07-00-operations.md § Prepare an operational change). SAP_AUTOMATION_REPO_PATH,CONFIG_REPO_PATH, andARM_SUBSCRIPTION_IDare set, or the missing-export gate is fixed first.- The target root is known:
sap_deployer,sap_library,sap_landscape, orsap_system. - The parameter file, state subscription, storage account, and key identify the intended backend.
- For
importorremove, the exact Terraform address and Azure resource ID are known. If not, stop and inspect first.
Recipe
Step 1 — Confirm the boundary before touching state
- This skill owns reviewed state inspection and repair through
deploy/scripts/advanced_state_management.sh. sdaf-safe-removalowns Terraform destroy, reverse-order teardown, and removal through the documented SDAF operations.sdaf-failure-triageowns an ambiguous failed run before the operator has established whether the problem is readiness, deploy, removal, or state.
If the user is trying to delete resources or finish an incomplete teardown,
route to sdaf-safe-removal. Do not hide removal problems with state edits.
Step 2 — Reconcile backend identity and back up first
Walk the checklist in references/state-safety.md:
- Remote state is authoritative after control-plane bootstrap; local
.terraform/terraform.tfstateis backend metadata, not the source of truth. - Back up the target remote-state blob and local backend metadata before any reviewed state operation.
- Confirm the local metadata, the supplied subscription/storage account/key, and
any
.sap_deployment_automationmetadata all point at the same backend. The script can infer backend values when arguments are omitted; inspect before trusting. - Preserve lock details and prove no other workflow, pipeline, operator, or process still owns the blob.
Step 3 — Inspect first with the documented list path
Before changing anything, confirm the checked-out script contract:
"$SAP_AUTOMATION_REPO_PATH/deploy/scripts/advanced_state_management.sh" --helpThen start with the non-destructive intent from the documented list
example in docs/local/07-00-operations.md § Manage state safely:
cd "$CONFIG_REPO_PATH/WORKSPACES/SYSTEM/<SAP_SYSTEM>"
"$SAP_AUTOMATION_REPO_PATH/deploy/scripts/advanced_state_management.sh" \
--parameterfile "<SAP_SYSTEM>.tfvars" \
--type sap_system \
--operation list \
--subscription "<STATE_SUBSCRIPTION_ID>" \
--storage_account_name "<STATE_STORAGE_ACCOUNT>" \
--terraform_keyfile "<SAP_SYSTEM>.terraform.tfstate" \
--workload_zone_name "<WORKLOAD_ZONE>" \
--control_plane_name "<CONTROL_PLANE>"The script initializes the matching root module, writes resources.lst, and
only then lists resources. Treat any unexpected copy/migrate prompt as a stop
condition; reconcile the backend first and rerun only after review.
Step 4 — Treat import / remove as reviewed repairs, never discovery
state rmstops Terraform from managing a resource; it does not delete the Azure resource.- The script validates
--azure_resource_idwithaz resource show --idsbefore import. If that lookup fails, stop. importandremoveare only valid onceresources.lst, the Terraform address, and the Azure resource ID all match the reviewed target.- Do not shorten, pattern-match, or guess a Terraform address or Azure resource ID.
- Do not use
state rmto bypass a replacement, to make an incomplete removal look clean, or as a substitute for a destroy plan. Those are boundary violations: route tosdaf-failure-triageorsdaf-safe-removal.
If the docs, script output, Azure resource lookup, and stored metadata do not line up cleanly, say docs are insufficient for a safe reviewed edit and stop.
Step 5 — Re-list, retain evidence, then hand off
After any reviewed import/remove:
- rerun
--operation listto confirm the new association; - retain the command, output, state account, container, and blob names; and
- hand back to the owning stage skill for a fresh plan, or to
sdaf-safe-removalif the next reviewed step is an actual teardown.
Hard rules
- Documented behaviour only (D19). If the docs and checked-out script are silent, stop.
- Never synthesize destructive state edits, generic unlock commands, or an undeclared hosted recovery wrapper.
- Do not treat
listas read-only; initialization can still migrate or upgrade backend/provider state. - Do not run two execution models concurrently against the same state.
- Do not treat local backend metadata as the authoritative state record.
What this skill does NOT do
- Does not perform teardown, destroy, ARM fallback, or generic failed-run triage.
- Does not invent a
terraform force-unlockprocedure or approve import/remove without backups and exact identifiers.
See also
sdaf-safe-removal,sdaf-failure-triage,sdaf-control-plane-bootstrap,sdaf-workload-zone,sdaf-sap-system.docs/local/07-00-operations.md,docs/local/troubleshooting.md, andreferences/state-safety.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

