Back to Terraform

Diagnose Slow Plans and Provider Failures Systematically

November 5, 2026 Wasil Zafar 26 min read

Measure bottlenecks before changing parallelism, graph structure or refresh behavior

Table of Contents

  1. Measure Initialization, Refresh, Planning and Apply Separately
  2. Use Logs as Sensitive Diagnostic Artifacts
  3. Inspect the Dependency Graph for Serialization
  4. Tune Parallelism Within Provider and API Limits
  5. Targeting and Skipped Refresh Are Exceptional Tools
  6. Write a Reproducible Provider Diagnostic

Measure Initialization, Refresh, Planning and Apply Separately

At 09:10 on a Monday, a plan that usually finishes in four minutes is still running thirteen minutes later. The root manages 1,800 resources across six providers, and someone suggests -parallelism=30. It is a reasonable guess and a bad first move, because "the plan is slow" does not name a phase. Terraform does four kinds of work, and only one is usually the culprit. These are composite numbers, not a benchmark.

Think of an airport departure: check-in, document check, security and boarding all add to the elapsed time. Adding security lanes cannot help if check-in has one desk.

Initialization loads the root module, installs providers and modules, reads the backend configuration and prepares the working directory. It is normally seconds; a cold plugin cache, slow registry, large module tree or distant backend can turn it into minutes. terraform init does not read managed objects, so a slow init is not a resource-count problem.

Refresh is the read pass. For every instance in state, Terraform asks the provider to read the remote object and return its current attributes. It scales with resource count and API latency, and is often the largest part of a slow plan: 1,800 instances means 1,800 provider calls, subject to pagination, retries and limits.

Planning compares configuration with refreshed state, evaluates expressions, resolves data sources where possible and asks providers to plan changes. It can be fast even for a large state unless reads are deferred, provider plan functions are slow or many values stay unknown.

Apply performs writes, waits for provider operations and persists state. Its failure modes are different: rate limits, eventual consistency, long-running creates and lock contention.

PhaseMain workRecordFrequent cause of a long phase
initProvider and module installation, backend setupSeconds, provider count, cache hitCold cache, registry latency, large module tree
RefreshOne read per managed instanceInstance count, API latency, retriesSerialized graph, throttling, slow reads
PlanDiff, expression evaluation, data reads, plan RPCsChange count, unknown values, deferred readsData-read deferral, provider plan calls
ApplyWrites, waits, state persistenceWrite count, retries, lock waitRate limits, eventual consistency, lock contention

Time each command as a separate process with wall-clock measurement. The refresh-only run estimates the read pass; the normal plan that follows still starts from the old state snapshot, because a plan does not persist refresh results. Treat the split as an estimate, cross-check it against the timestamps inside one run, and do not loop it: each repetition is another read pass. Time apply from a reviewed saved plan in a disposable environment.

# Terraform 1.17.1. Run from the root module; one process per command.
export TF_LOG=off
mkdir -p diagnostics
chmod 700 diagnostics

/usr/bin/time -p terraform init -input=false -no-color 2>&1 \
  | tee diagnostics/init.txt
/usr/bin/time -p terraform plan -refresh-only -input=false -no-color 2>&1 \
  | tee diagnostics/refresh-only.txt
/usr/bin/time -p terraform plan -input=false -no-color \
  -out=diagnostics/plan.tfplan 2>&1 | tee diagnostics/plan.txt
/usr/bin/time -p terraform apply diagnostics/plan.tfplan 2>&1 \
  | tee diagnostics/apply.txt

Count instances with terraform state list | wc -l and read the plan summary for changes. Provider timings come from log timestamps: the gap between a reading line and its completion is the call, and a long gap with no new resource line is often one slow request or a retry loop.

A rough floor for wall time is the longer of the critical path and total provider work divided by parallelism. If 1,800 reads average 300 ms and parallelism is 10, the work floor is about 54 seconds. A nine-minute refresh is not explained by that arithmetic, so look for serialization, retries or a much slower read.

Figure 1 separates the phases and the question each answers. Figure 2 places them on one wall-clock timeline and shows which boundary owns each measurement.

Measure Initialization, Refresh, Planning and Apply Separately
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Plan takes 13m30s
1,800 resources, 6 providers"] --> B["1. init
install, backend, modules"] B --> C["2. refresh
one read per managed instance"] C --> D["3. plan
diff, data reads, plan RPCs"] D --> E["4. apply
writes, waits, state"] B --> B1["Record: seconds, cache hit,
provider and module count"] C --> C1["Record: instance count,
API latency, retries"] D --> D1["Record: changes, unknowns,
deferred reads"] E --> E1["Record: writes, waits,
retries, lock wait"] B1 --> F{"Which phase
owns the time?"} C1 --> F D1 --> F E1 --> F F -->|"init"| G["Warm cache or mirror"] F -->|"refresh"| H["Remove broad edges,
check API limits"] F -->|"plan"| I["Fix data deferral,
provider plan calls"] F -->|"apply"| J["Backoff, waiters,
serialize writers"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class A,F primary; class B,C,D,E secondary; class B1,C1,D1,E1 warn; class G,H,I,J ok;

Figure 2 is the evidence view: a single elapsed time decomposed into phases, with the Core, provider-plugin and remote-API boundaries called out. The point is not the exact numbers; it is that the bar has segments and the segments have owners.

One elapsed time, four phases, three boundaries A wall-clock timeline shows init at 95 seconds, refresh at 9 minutes 5 seconds, plan at 40 seconds and apply at 2 minutes 10 seconds. Refresh dominates. Three boundary bands show what Terraform Core, the provider plugin and the remote API each own, and a footer lists the context to record with the timing. One elapsed time, four phases, three boundaries 13m30s wall clock · 1,800 resources · 6 providers · widths schematic Measured as separate commands init 95 s refresh 9m05s plan 40 s apply 2m10s registry + backend 1,800 reads diff + data writes + waits Which boundary owns the delay? Terraform Core Builds the graph, evaluates expressions, diffs state against configuration. Provider plugin Serializes RPC calls, retries, backoff and provider plan functions. Remote API Latency, quotas, throttling and eventual consistency of the service. Record: command, exit code, CLI and provider versions, state serial, resource count, log timestamps. A duration without those conditions is not comparable to another run.

Once the phase is known, the next question is what the provider actually did. That is a log question, and logs are dangerous.

Use Logs as Sensitive Diagnostic Artifacts

A trace log is a transcript

Transcripts contain more than the error. Depending on the provider and level, TF_LOG output can include HTTP bodies, headers, tokens, state attributes, resource identifiers, file paths, user data and the values Terraform was comparing. The file that explains a timeout can also contain a credential.

Terraform layers the detail, and each control narrows the blast radius. TF_LOG sets the global level; the Core and provider controls split it; the path control decides whether the transcript survives the terminal.

ControlSetsUse it when
TF_LOGGlobal level: TRACE, DEBUG, INFO, WARN, ERROR or offOne pass, before you know which layer is slow
TF_LOG_CORECore onlyScheduling, graph or expression questions, without provider noise
TF_LOG_PROVIDERProvider plugins onlyRPC and retry questions, without a 500 MB Core trace
TF_LOG_PATHA file instead of stderr; requires TF_LOGThe run must outlive the terminal
TF_LOG=JSONTrace-level JSONNever parse it; the format is not a stable interface

Location is the first control. Write the log under diagnostics/, add that directory to .gitignore, restrict permissions and keep it out of shared temporary directories. A log in the repository root is one broad commit from publication. In CI, use the ephemeral workspace and upload only a redacted excerpt.

Redaction is the second control. Replace account IDs, subscription IDs, project IDs, ARNs, resource names, IPs, hostnames, email addresses and token-shaped strings with consistent placeholders such as ACCOUNT_A and SUBNET_A. Keep the resource type, error code, timestamp and duration: that is the diagnostic signal. Redact before the file leaves the machine, and have a second reader check the excerpt.

Deleting the file does not revoke the credential

Retention is the third control. Delete the trace when the investigation closes. If it must be retained, encrypt it, restrict access, set a short expiry and record why it exists. TF_LOG_PATH appends across runs, so one file can accumulate days of activity. If a live credential appears, rotate it; deleting the file does not revoke it, and crash.log deserves the same handling.

Provider logging is not uniform. Some providers log HTTP at DEBUG, others need trace level, and redaction varies. Assume the least: set TF_LOG_PROVIDER=DEBUG with Core at INFO, reproduce one command, and widen only if the error is still opaque.

The commands below collect the evidence set: counts, graph files and one logged pass. The logged pass writes to diagnostics/tf-trace.log with owner-only permissions.

# Terraform 1.17.1, hashicorp/local 2.9.1. Run from the root module.
# Uses diagnostics/plan.tfplan from the timing pass above.
export TF_LOG=off
mkdir -p diagnostics
chmod 700 diagnostics

# Count managed instances and planned changes.
terraform state list | wc -l
terraform show -json diagnostics/plan.tfplan \
  | jq '[.resource_changes[]] | length'

# Graph: default ordering, plan graph, and cycle check.
terraform graph > diagnostics/graph.dot
terraform graph -type=plan > diagnostics/graph-plan.dot
terraform graph -draw-cycles -type=plan > diagnostics/graph-cycles.dot
command -v dot >/dev/null && dot -Tsvg diagnostics/graph-plan.dot \
  > diagnostics/graph-plan.svg
# Other graphs: -type=plan-destroy, -type=plan-refresh-only,
# and -plan=diagnostics/plan.tfplan for the apply graph.

# One logged pass. Keep the trace out of Git and delete it when done.
export TF_LOG=TRACE
export TF_LOG_CORE=INFO
export TF_LOG_PROVIDER=DEBUG
export TF_LOG_PATH="$PWD/diagnostics/tf-trace.log"
terraform plan -input=false -no-color \
  > diagnostics/logged-plan.txt 2>&1
chmod 600 diagnostics/tf-trace.log

Each timed command is a separate process, so the numbers include CLI startup and provider handshake. The logged pass runs one normal plan so the trace includes refresh and plan RPCs; it is a diagnostic run, not a plan to apply. If the trace is still large, narrow Core with TF_LOG_CORE=INFO rather than dropping the provider reads.

Figure 3 shows the branch that matters most: a log with a credential is not a log to redact later, it is an incident to contain.

Use Logs as Sensitive Diagnostic Artifacts
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["A provider error or a slow call"] --> B{"Need more detail?"}
    B -->|"core scheduling"| C["TF_LOG_CORE=DEBUG"]
    B -->|"provider RPC"| D["TF_LOG_PROVIDER=DEBUG"]
    C --> E["TF_LOG_PATH=diagnostics/tf-trace.log"]
    D --> E
    E --> F["Run one command
with -no-color"] F --> G{"Log contains credentials
or state values?"} G -->|"yes"| H["Quarantine the file
rotate any live credential"] G -->|"no"| I["Replace account IDs, ARNs,
IPs and names"] H --> J["Delete after rotation
do not attach"] I --> K["Keep a short excerpt
with timestamps and a TTL"] K --> L["Attach to a minimal
reproduction"] J --> M["Record the incident only"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class B,G primary; class A,C,D,E,F secondary; class I,K,L ok; class H,J danger; class M warn;

The safe sequence is reproduce, capture, inspect, redact, excerpt, delete. The unsafe sequence is reproduce, attach, hope.

Inspect the Dependency Graph for Serialization

Terraform's graph is a claim about what can run at the same time. Nodes are resources, data sources and provider configurations; edges are dependencies. Terraform walks the graph depth-first and starts a node when its dependencies finish, up to the parallelism limit. A wide graph uses the limit; a narrow chain uses one worker no matter how high it is.

terraform graph prints DOT. The default is a simplified resource-and-data ordering graph; the type flags select a different operation, and cycle highlighting requires a real graph type. The evidence widget above writes the plan graph and renders it.

Read for four shapes. Each one names a different cause and a different first move.

ShapeWhat it meansFirst move
Long chainEvery edge is a wait; one worker does the workRemove an unnecessary dependency or pass the value
Dense cluster around one moduleBroad module-level edgesReplace the module argument with an output reference
Data node fed by a managed resourceThe read is deferred to applyRemove the dependency or split the root
Provider node with hundreds of outgoing edgesProvider configuration is a serial gateConfigure once before resources proceed

depends_on is the usual source. It exists for dependencies Terraform cannot see, such as an IAM policy that must propagate before a role is used. At resource level it adds one edge. At module level it is broad: every resource in the module depends on every resource in the target, even when one output is consumed.

Pass the value, not the module

A reference creates the edge you need; a module-level argument creates all of them. Use subnet_id = module.network.subnet_id instead of depends_on = [module.network]. If the only reason for the edge is one value, pass the value.

Data-read deferral is subtler. A data source normally reads during refresh or plan. If it depends on a resource that is not yet created, or has an explicit depends_on, Terraform cannot read it until apply. Its result is unknown, every expression that uses it becomes unknown, and apply must read before continuing. The plan looks fast because the read moved; apply looks slow because it landed there. Remove the dependency when the data reads pre-existing infrastructure, or split the root when the data belongs to another lifecycle.

Broad module edges also slow destroy. Dependents must go before dependencies, so a parallel teardown becomes a queue. The same edge can hide a missing output contract. If the only reason for the edge is one value, pass the value.

Figure 4 shows a graph where module-level depends_on edges and a deferred data read turn a wide configuration into a four-stage chain.

Diagnosing a slow dependency path
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    A["Root module"] --> B["module.network"]
    B -->|"module-level depends_on"| C["module.cluster"]
    C -->|"module-level depends_on"| D["module.services"]
    D --> E["data.aws_subnets.shared
read deferred to apply"] E --> F["aws_lb.app"] F --> G["aws_instance.app[0..9]"] B --> H["Genuine reference:
subnet_id"] H --> F I["Unnecessary edge:
all services wait for all network"] -.-> C G --> J["Apply: 10 reads then 10 writes"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class D primary; class A,B,C,E,F,G secondary; class H ok; class I warn; class J warn;

After removing an edge, re-run the graph and the plan, and compare the node count, edge count and wall time. A graph that looks simpler but plans more changes is not an improvement.

Tune Parallelism Within Provider and API Limits

Parallelism is a ceiling, not a goal. Terraform's default is 10 concurrent graph nodes for plan, apply and destroy; -parallelism=n changes it. The docs call this advanced because the graph is only one of four limits.

Throughput. The provider and API process a certain number of calls per second. If the graph has 40 independent reads and the API handles 20 concurrent calls, raising parallelism from 10 to 20 may help; raising it to 40 usually does not, because the extra workers wait in the same queue. The limit may be per account, region, resource type or connection, and it changes with the time of day.

A lower parallelism can be faster

A throttled API makes extra workers wait in the same queue. Providers retry with backoff, so the symptom is a plan longer than the arithmetic suggests, not a failure. Adding workers increases pressure and retry volume. If the limit is a quota, the fix is a quota increase or a smaller blast radius, not a flag.

Eventual consistency. A create can return before the object is readable. The next read may see a 404 or a stale value. More concurrency increases in-flight objects and the chance that a read races a write. Terraform cannot fix this with parallelism; the provider needs a waiter or the configuration needs a real dependency. A sleep is a guess, not synchronization.

Lock contention. State locking allows one writer per state. A plan takes a lock, an apply holds it longer, and a second CI job waits or fails. The symptom is a pause before resource work, not a slow graph. -lock-timeout controls the wait; -lock=false removes protection and is not a performance fix. If waits are common, serialize the pipeline or split the state.

Measure before changing the number. Pick a baseline, change one variable, run three times, take the median and record provider errors alongside duration. Keep the same CLI, provider, state serial, variables and time window. Change one thing: remove a broad edge, split a root, warm the cache or adjust parallelism. If the median does not improve, roll back; the rollback is part of the experiment.

Segmentation is the durable lever. Splitting a root by ownership or lifecycle reduces the resources refreshed in one plan, the blast radius and the teams waiting on one lock. A module split inside the same root does not reduce the graph; it only organizes code. If 1,800 resources are refreshed every time, the answer may be three roots of 600, not 30 workers on 1,800.

Order the levers from cheapest to most structural. Measure the phase, remove unnecessary edges and deferred reads, split the root if the lifecycle allows, warm or mirror the cache, and only then adjust parallelism. Record the old value and the restore command beside every change.

Targeting and Skipped Refresh Are Exceptional Tools

-target and -refresh=false are borrowings against correctness. They can be right in an incident and are wrong as the default for a slow plan.

Targeting is recovery, not routine operation. -target=ADDRESS limits planning to the selected instances and their dependencies. Terraform's docs call it exceptional, for recovery or working around limitations. Unselected resources are not refreshed or planned, so drift outside the target is invisible and a later full plan can reveal changes the targeted apply never considered. Targeting also pulls in dependencies, enlarging the selected set. Follow with a full plan and record why the target was necessary.

Skipped refresh trades accuracy for speed. -refresh=false compares configuration with the last known state, not reality. It can be faster and wrong: an external change, deleted resource, rotated attribute or provider default will not appear. Applying it can fail, overwrite a change or create a duplicate. It is not drift detection, and it is dangerous during a provider upgrade, when refresh may migrate schema state. Use it only when the API is unavailable, with a named owner accepting the risk and a full plan once the API returns.

Selective refresh has a narrower blind spot. -minimal-refresh, added in Terraform 1.17.0, refreshes only instances Terraform plans to change; unchanged resources keep prior state. It cuts API calls on large, stable configurations but still ignores external changes elsewhere. It cannot combine with skipped refresh or refresh-only mode, should not be used during provider upgrades, and does not exist before 1.17, so a runbook that depends on it needs a version gate.

Refresh-only is a reconciliation mode, not a speed setting. -refresh-only plans to update state and outputs to match remote objects. It is legitimate after an intentional console change and costs a full refresh. It does not change configuration.

Figure 5 contrasts the shortcut path with the segmented path. The shortcut produces a fast plan and a later surprise; the segmented path produces a smaller, repeatable plan with a known owner.

Fast but blind versus segmented and reviewable The left path uses target or refresh=false, producing a quick narrow plan from a stale snapshot, incomplete evidence and eventually hidden drift or an apply surprise. The right path splits roots by ownership and lifecycle, runs a full refresh per root, measures the full graph and produces a reviewable change with a rollback. A shortcut needs an owner, reason, expiry and follow-up full plan. Fast but blind versus segmented and reviewable Both paths can start with the same slow plan Shortcut: fast but blind -target or -refresh=false Narrow plan from a stale snapshot Fast, incomplete evidence Hidden drift or apply surprise Segmented: slower to set up Split by ownership and lifecycle Full refresh per root Measured plan, full graph Reviewable change plus rollback A shortcut needs an owner, a reason, an expiry and a follow-up full plan.

Every exceptional flag needs four things: an owner, a reason, an expiry and a follow-up full plan. If the flag becomes routine, the team has made a design decision without admitting it. The durable alternatives are smaller roots, narrower dependencies and a provider cache, not a permanently targeted pipeline.

Write a Reproducible Provider Diagnostic

A provider diagnostic is a sanitized package that lets someone reproduce the behavior without your account, state or credentials, not a transcript dump. The structure: summary and impact, environment, minimal configuration, steps, expected versus actual, evidence, workaround and rollback.

Start with versions, not adjectives. terraform version -json gives the CLI, platform and provider selections; .terraform.lock.hcl gives exact provider versions and hashes. Record backend type, workspace, region, module source references and the date. "Latest" is not a version; "Terraform 1.17" and "AWS provider 6.x" cannot be reproduced six weeks later.

Then reduce. Remove every resource not needed to trigger the behavior. Keep the failing resource and the smallest dependency chain; use synthetic names and, where possible, a provider that needs no credentials. For a provider problem, one resource with the smallest valid arguments is enough. For Core, terraform_data or the local provider may reproduce it without a cloud account. The minimal configuration is also the test: if removing a module makes the behavior disappear, the module edge was part of the cause.

State expected and actual in the same units. "Expected: no changes in under 60 seconds. Actual: 9m12s, exit code 0, 1,802 reads, 37 retry lines." Include the command and timestamp; a screenshot is not a substitute.

Sanitize consistently. Replace account IDs, subscription IDs, ARNs, IPs and names with placeholders such as ACCOUNT_A and RESOURCE_A; use documentation ranges for IPs. Keep resource types, counts, error codes, durations and graph shape. Remove state, plans and full traces; crop the log to 20 or 30 lines around the failure, keep timestamps, scan for token patterns and have a second person read it.

Triage by signal. A provider RPC returning 429, 5xx, a throttling error or a malformed response is usually provider or API. A graph cycle, panic or Core inconsistency is usually Terraform. A 401 or 403 is environment. An unknown value that should be known is configuration or dependency. The category decides where the report goes and which version to test next.

Package the evidence, not the estate. The report should contain a versions file, timings, a graph file, a plan summary and a short trace excerpt — never state, a saved plan or the raw trace. Search both issue trackers for the error text before opening a new report.

The lab below is a mechanics exercise, not a benchmark. It uses the local provider so it costs nothing; the timings will be too fast to show API saturation, but the graph, the phase split and the evidence package are the same.

Lab

Investigate a slow plan

Execution status: design-only. This is a mechanics exercise with the local provider; no cloud account is used and no timing here is a provider benchmark.

Prerequisites. Terraform 1.17.1, hashicorp/local 2.9.1 and jq; Graphviz is optional. Use a POSIX shell and allow about 45 minutes. Record your own versions if they differ.

Setup.

  • Create a diagnostics-lab/ root with a versions file pinning Terraform 1.17.1 and the local provider 2.9.1.
  • Add a main.tf with 40 local_file resources, driven by for_each = toset([for i in range(40) : format("item-%02d", i)]).
  • Give each file filename = "${path.module}/${each.key}.txt" and content = each.key.
  • Keep the first run free of modules and data sources.
  1. Run terraform init and record the wall time, the provider count and whether the plugin cache was warm.
  2. Run terraform apply -auto-approve; confirm with terraform state list | wc -l that 40 instances exist and with ls *.txt | wc -l that 40 files exist.
  3. Run terraform plan -refresh-only, terraform plan, and terraform plan -refresh=false three times each. Record the median for each. Expect fast runs because the local provider has no network latency; the exercise is the shape of the evidence, not the size of the numbers.
  4. Run terraform graph -type=plan > graph-plan.dot and count edges with grep -c -- '->' graph-plan.dot. Identify the longest path. With 40 independent files, the graph should be wide and shallow.
  5. Add a terraform_data chain of ten instances, each depending on the previous one. Re-run the graph and the plan. Expect more edges and a longer wall time, though the resource count barely changes.
  6. In a copy, wrap the 40 files in module.storage, then call a second module module.app with depends_on = [module.storage]. Compare edge counts, then replace the module-level argument with an output reference from module.storage and compare again.
  7. Run the 40-file plan with -parallelism=1, -parallelism=5 and -parallelism=10. Record the medians. The local provider is too fast to show API saturation; treat this as a scheduling check, not a throughput result.
  8. Write diagnostics.md: versions, resource count, the three timings, the graph edge counts, the one change you would propose, and the exact rollback command. Add a short trace-excerpt.log from a TF_LOG=TRACE run with placeholders, or state that no log was needed.

Expected observation. 40 addresses and 40 files, a wide graph for the independent resources, a visibly longer path after the chain is added, and a smaller edge count after the broad module dependency becomes an output reference. The timing table proves method, not provider performance.

Failure checks. A plan that still proposes 40 creates after apply means the state or backend is wrong. An empty graph means the command ran outside the root. A trace file that grows across runs means TF_LOG_PATH was left set. A -refresh=false plan that differs from the normal plan is drift, not a speed result.

Cost dimensions. Zero cloud spend; a few megabytes of local files and logs; 30 to 45 minutes. If you substitute a cloud provider, add the smallest resources and a cleanup check.

Cleanup. Destroy the lab, remove the diagnostics directories, unset the four TF_LOG variables, and confirm with git status --short that no state, plan or trace remains.

A good diagnostic ends with a causal sentence: "The refresh pass is slow because module-level depends_on serializes 600 reads behind one network module; removing the broad edge and splitting the services root reduced the median refresh from 9m05s to 2m40s." That sentence has a measurement, a mechanism, a change and a rollback; a flag change alone does not.

Next in the Series

In Recover from Partial Applies, Lost State and Emergency Changes, we'll explore Restore trustworthy ownership and service behavior using evidence instead of an assumed rollback button.