Justify a New Provider Before Writing One
A provider is a lifecycle adapter, not an API client. Terraform does not call your service. It asks a plugin to plan, apply, refresh, import, and destroy one remote object, and it keeps asking for as long as the object exists. That distinction decides whether a provider is justified.
The default answer is no. Most requests describe a one-shot action: rotate a credential, seed a bucket, call a provisioning endpoint. A provider adds a state machine, a schema contract, a release process, and a support rota. If Terraform does not need to own the object's lifecycle, a module plus an external job is cheaper and more honest.
Borrow before building. If a vendor or community provider covers the object, pin it, test the behaviours you depend on, and contribute the missing attribute upstream. A fork is still a provider you maintain, but at least you inherit the schema, import path, and acceptance tests.
| Option | What it owns | Choose it when | Recurring cost |
|---|---|---|---|
| Existing provider | The full lifecycle | A vendor or community provider already covers the object | Version pinning, upgrade tests, upstream gaps |
| Module plus API call | Policy and composition | The API call is one-shot or follows an apply | No drift detection, separate runner |
| External job | Delivery, retries, progress and logs | The work is a batch, migration or approval chain | A second state machine to operate |
| Direct API integration | Nothing in Terraform | Bootstrap, break-glass or a pre-Terraform step | No plan, no state, no destroy |
| Custom provider | The full lifecycle | The API is a system of record with a durable object | Schema, tests and releases for years |
The decision turns on ownership, not on language. A module owns policy and composition; it cannot see drift in an object it did not create. An external job owns retries, progress, and logs; Terraform hands off after apply. Direct API integration owns nothing in Terraform: no plan, no state, no destroy. A custom provider is the only option that gives Terraform a durable address for a remote object.
The provider boundary is narrow. Three things cross it: desired values in, refreshed values out, and diagnostics in both directions. Authentication, rate limits, and the meaning of a 409 stay on the API side. When a provider starts hiding API semantics, the boundary has leaked.
CRUD fit is a design constraint. If the API exposes only "run task" and "fetch logs", there is no object to refresh. A provider can wrap a task resource, but if the task cannot be read back, every plan becomes a create and drift is invisible. Prefer an external job.
Blast radius matters. A provider credential can usually change every object the API exposes. Give it a scoped token, and keep the provider in a workspace that owns only those objects. A module can be reviewed per call; a provider is installed once and used everywhere.
The recurring cost is compatibility. The schema is a public interface: renaming an attribute or changing its type breaks configurations and stored state. State upgrades, acceptance tests, protocol updates, dependency bumps, and release signing continue after the first demo. A small provider with one resource still carries the whole lifecycle.
The second resource is where the estimate breaks. A one-resource provider looks like a week of work. The second resource reuses the client, not the schema: it needs its own import rules, not-found behaviour, plan modifiers, and tests. Budget the tenth resource, not the first, because that is where shared conventions either exist or are reinvented.
Versions here are pinned, not approximate. The Terraform CLI is 1.17.1, released 28 October 2026. The Plugin Framework is v1.19.0, the version pinned by HashiCorp's scaffolding provider when checked on 6 November 2026. The API and schema shapes below are framework concepts, not a promise about a specific vendor.
%%{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["API object needs
a Terraform lifecycle"] --> B{"Existing provider
covers it?"}
B -->|"yes"| C["Pin, test,
contribute upstream"]
B -->|"no"| D{"Durable object
with CRUD?"}
D -->|"no"| E["Module plus
external job"]
D -->|"yes"| F{"System of record
for several teams?"}
F -->|"no"| G["Module plus
API call"]
F -->|"yes"| H{"Staff schema,
tests and releases?"}
H -->|"no"| I["Upstream or
managed integration"]
H -->|"yes"| J["Custom provider"]
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,H primary;
class B,D,F secondary;
class C,J ok;
class E,G,I warn;
The decision is a sequence of exits, not a score. Each "no" is a cheaper implementation. The last box is the only one that commits you to schema and state compatibility.
Draw the boundary before the resource. The plugin translates between Terraform's typed values and the API's JSON. It does not become the system of record, and it does not make an unsafe API safe.
A provider passes the test only when five answers are yes. The object has a durable identity; the API supports read and update; several teams need the same lifecycle; no usable provider exists; and you can staff compatibility work. Four out of five is a module and a job.
Map API Identity and CRUD to a Terraform Resource
Terraform's identity is the state address; the API's identity is the id. The address is stable because it comes from configuration. The id is stable because the API guarantees it. Read needs the id; import needs a way to derive it; update and delete need it too. If the API has no stable id, stop and fix that first.
Create must leave a readable object. A 201 with a body is easy. A 202 with a job id is not: poll until the object is readable, then set every computed attribute. If Create returns success and the state write fails, Terraform reports an error but the object exists; an idempotency key or a deterministic name is the only safe retry.
| Terraform operation | Framework method | API call | State result | On failure |
|---|---|---|---|---|
| Create | Create | POST | Set id and computed values | Error; orphan risk without an idempotency key |
| Refresh | Read | GET | Overwrite every owned attribute | 404 removes the resource from state |
| Update | Update | PATCH or PUT | Set the new state | 404 errors; 409 needs a diagnostic |
| Delete | Delete | DELETE | Remove the resource from state | 404 is success |
| Import | ImportState then Read | GET | Write the id, then refresh | Bad id shape returns a diagnostic |
Read is the contract that makes drift visible. Read takes prior state, calls the API, and overwrites every attribute it owns. It runs during plan, apply, and refresh, and again after import. If Read ignores a field, Terraform cannot detect a remote change; if Read invents a value, the next plan will fight the API.
A 404 during polling is not always a deletion. Right after create, a read can return 404 while the object propagates. Distinguish "not found yet" from "deleted" with a bounded poll and the creation time; after the deadline, surface the last status and request id instead of guessing.
Update gets three inputs, not one. The framework passes prior state, configuration, and the plan. Use prior state for values the API does not return, the plan for the desired change, and configuration to distinguish an unset optional value from a computed one. Sending the whole plan blindly overwrites fields the user did not manage.
Not-found is three different answers. During Read, a 404 means the object is gone: remove it from state so the plan can recreate it. During Delete, a 404 means the desired end state already holds: succeed. During Update, a 404 means the planned change cannot be applied: return an error, because silently recreating would lose the object's identity.
Import is not adoption. Import writes the id into state and then calls Read; the configuration still has to match the refreshed object. For a single id, ImportStatePassthroughID is enough. For a composite key, parse it, set each attribute, and return a diagnostic when the shape is wrong. Import tests catch the parser you forgot.
Retries belong at the HTTP boundary. Retry connection resets, 429, and 5xx on idempotent calls; honour Retry-After; cap the total wait with the request context. Do not retry a non-idempotent POST unless the API accepts an idempotency key. Eventual consistency is not an error: poll with backoff until the object is readable or the deadline expires.
Idempotence is an API property, not a provider trick. If the API has no idempotency key, use a deterministic name or a caller-supplied token, and make Read the source of truth. A provider that retries a create without one will produce duplicates that no later plan can explain.
%%{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["Create
plan values known"] --> B["POST /widgets"]
B -->|"201"| C["Set id and
computed fields"]
B -->|"409"| C1["Conflict:
idempotency or fail"]
C --> D["Read
GET /widgets/{id}"]
D -->|"200"| E["Refresh all
state attributes"]
D -->|"404"| F["RemoveResource
drop from state"]
E --> G["Update
PATCH /widgets/{id}"]
G -->|"200"| H["Set new state"]
G -->|"404"| I["Error: object gone
recreate or import"]
H --> J["Delete
DELETE /widgets/{id}"]
J -->|"204 or 404"| K["Remove from state"]
F --> K
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,C,E primary;
class B,D,G secondary;
class H,J,K ok;
class C1,I danger;
class F warn;
The failure branches are the design. Every arrow that returns a 404 or 409 needs a state decision. The happy path is short; the branches are what acceptance tests must exercise.
A round-trip is the smallest proof. Create, read, plan with no changes, update one mutable field, destroy, and import the next object. If any step produces a diff or an orphan, fix that before adding a second resource.
Distinguish a provider bug from an API bug before changing code. A diagnostic is a claim about ownership. Reproduce the API call outside Terraform, capture the request id, and compare it with the provider's log. The symptom usually points at the layer that owns the evidence.
| Symptom | Likely owner | Evidence to collect |
|---|---|---|
| A plan diffs every run on an unchanged object | Provider Read | Refresh-only plan, the API GET, and the stored attribute |
| 401 or 403 on every call | API or credentials | Token scope, request id, and the same call with curl |
| 404 immediately after Create | API consistency or provider polling | Create response, first GET timing, retry log |
| 409 on Update | API concurrency or versioning | ETag, request body, API changelog |
| Provider produced inconsistent result after apply | Provider | Planned value versus applied state for each computed field |
| State decode error after an upgrade | Provider upgrader | Stored schema version, prior state JSON, upgrader map |
| 429 storms | API quota or provider retry | Retry-After header, concurrency, token quota |
The table is a routing rule, not a blame exercise. If the API returns the wrong value, the provider should report it, not compensate silently. If the provider ignores the value, the fix is in Read. If Terraform reports an inconsistent result after apply, the plan and the applied state disagree, which is a provider defect.
Log the boundary, not the secret. Provider logs should include method, path, status, request id, and retry count. They should never include tokens, full response bodies, or sensitive attribute values.
Distinguish Null, Unknown, Computed and Sensitive Schema Values
Four value states, four different promises. Null, unknown, known, and sensitive are not interchangeable. Null says absence is intended; unknown says the provider will answer later; known says the value is concrete; sensitive says the value is real but must be masked in output.
Null is a decision. An optional attribute left out of configuration is null. The provider may apply a default, omit the field, or send an explicit null, but it should do so deliberately. Converting null to zero inside Create hides the difference between "unset" and "set to zero" from every later plan.
Unknown is a delay. A computed attribute with no value yet is unknown, and Terraform renders it as (known after apply). Reading an unknown as an empty string is the classic bug: the plan records a value the API never agreed to, and apply returns an inconsistent result. Check IsUnknown() before reading.
Computed is a permission, not a value state. Computed means the provider may set the attribute. Optional plus computed means configuration may set it, and the provider fills it when configuration is null. Required plus computed is not a valid combination; Terraform needs to know who owns the value.
Defaults are known at plan time. A static default resolves an optional null to a concrete value before the plan is shown. Use it for provider-side constants, not for values that depend on the API. A remote default belongs in Read, where it becomes a real refreshed value.
UseStateForUnknown is for stable computed values. It copies prior state into the plan when the new value is unknown, which removes noise for identifiers and creation timestamps. It is wrong for a field the API can change, because it hides drift until the next refresh.
Sensitive is a display policy. It masks the value in CLI output and some logs, but the value remains in state. Encrypt the backend, restrict state access, and avoid putting the value in a diagnostic. Marking a whole resource sensitive is a blunt instrument; mark the attributes that carry the secret.
Write-only is stronger than sensitive. A write-only argument accepts an ephemeral value and is not persisted in the plan or state; Terraform 1.11 and later support it. Use it for a bootstrap secret, and make Read ignore the value rather than planning a permanent diff for something the API will never return.
Validators reject bad configuration before any API call. Type validators handle length, pattern, and allowed values. Cross-field rules belong in ValidateConfig or ModifyPlan, where both values are available. Attach the diagnostic to the attribute path so the error points at the field, not at the resource.
Plan modifiers must be narrow and predictable. RequiresReplace marks an immutable attribute, and RequiresReplaceIfConfigured does the same only when the practitioner set it. The state-copying modifier stabilises a computed value without hiding remote drift. A plan modifier that calls the API makes planning slow and non-deterministic; read the API in Read, not in plan.
ModifyPlan is for relationships, not for fetching. Use it when one attribute's value changes the meaning of another, or when a replacement decision depends on a combination. Do not use it to hide a diff that the schema should express.
| Mechanism | Runs | Question it answers | Misuse |
|---|---|---|---|
| Validators | Before plan, on configuration | Is this value legal? | Calling the API to check a name |
| Defaults | During plan, when optional is null | What known value should replace absence? | Fetching a remote default |
| Plan modifiers | During plan, per attribute | Is the value known, or must it replace? | Hiding a diff the schema can express |
| ModifyPlan | During plan, per resource | Do fields interact or require a warning? | Reading remote state to decide |
| CRUD | Apply and refresh | What is true remotely? | Enforcing policy in Create |
The plan is a promise about the next state. If it marks a value known that apply cannot produce, the provider will fail with an inconsistent result. If it marks a value unknown that could be known, the plan is merely noisy. Correctness first, then noise.
Diagnostics should name the field and the next action. A good error says which attribute failed, what value was received, what was expected, and whether the caller should fix configuration or credentials. A bad error says "API error" and leaves the operator to guess.
Sensitive values still need a redaction test. Search the plan output, the apply output, and the provider log for the secret. If it appears once, the attribute is not the only leak.
Treat State Schema Changes as Migrations
State is a persisted API contract. Terraform stores the resource's attributes and a schema version. The version is an integer, not the provider's semantic version. Any change to the stored shape needs a new integer and an upgrader from every version that might still exist.
Version 0 is a version. A first release can stay at 0. The first shape change bumps the schema to 1 and adds an upgrader keyed by 0. Reusing a version number after release is how a workspace silently decodes old data into the wrong fields.
The schema version is per resource, not per provider. Two resources in the same release can sit at different versions, and each needs its own upgrader map. A provider upgrade can therefore migrate one resource while leaving another untouched; test them independently.
Upgraders go directly to the current version. The framework does not chain intermediate steps. If state can be at 0 or 1 and the current version is 2, write two independent upgraders: 0 to 2 and 1 to 2. A 0-to-1 function plus a 1-to-2 function will not run as a sequence.
PriorSchema is the old shape, exactly. Declare the old attribute names and types, read into an old model, build the new model, and set the response state. The framework does not copy fields for you, and it does not guess. Every field in the new schema must be populated or deliberately left null.
Renames are the easy case; type changes are not. A rename maps one field to another and preserves the id. A string-to-integer change needs parsing and a diagnostic for bad data. A flat-to-nested change needs a new object value. Removing a configurable field needs a major provider release because configurations may still reference it.
| Change | Prior schema | Upgrade action | Test |
|---|---|---|---|
Rename name to display_name | Old key with the old type | Copy the value, leave the old key out | Old fixture plans with no replacement |
Change port from string to number | String attribute | Parse and attach a diagnostic on bad data | Valid and invalid fixtures |
Group flat fields into network | Flat attributes | Build the nested object and set it | Plan is a no-op |
Remove legacy_flag | Boolean attribute | Drop it and document a major release | Configuration no longer references it |
Add computed url | No attribute | Set null, then let Read fill it | Post-upgrade plan is explained |
Test with real old state. A unit test of the transform function is useful, but it does not prove Terraform can decode the stored shape. Keep a sanitized state fixture from the previous provider version, push it into a scratch workspace, run a plan with the new binary, and assert that the result is a no-op or a documented in-place update. A replacement is a failed migration unless you intended it.
Plan the compatibility window. Old workspaces can lie dormant for months. Keep every upgrader until you have evidence that no state at that version exists, and document the oldest supported version. Deleting an upgrader is a breaking change even if the current schema looks clean.
The first plan after an upgrade is the acceptance test. Read the diff: no changes means the mapping preserved semantics; an in-place update means the upgrader filled a new field and Read will reconcile it; a replacement means identity or a computed value was lost. Record which one you expect before you run it.
A state upgrade is a data migration, not a schema edit. It has an input shape, a transform, an output shape, and a test. Treat it like a database migration: versioned, reversible in review, and never edited after release.
Keep the old schema in the repository. The prior schema is code, not documentation. If it lives only in a wiki, the next maintainer cannot write the upgrader.
Ship with Acceptance Tests and a Distribution Plan
Acceptance tests are the only proof Terraform can own the object. Unit tests with a fake client prove that Go compiles and branches run. They do not prove that Terraform can create, refresh, diff, import, and destroy the object.
Test the lifecycle, not the handler. One test case should create, read, update, import, and destroy, with CheckDestroy proving the object is gone. An import step with verification enabled proves the id is sufficient and the refresh is complete.
The test server wraps the real provider. Use ProtoV6ProviderFactories for protocol 6, matching the server in the provider's main package. A protocol mismatch is a test failure, not a Terraform feature gap.
Acceptance tests run real Terraform. Set TF_ACC=1, point at a dedicated account or a recorded API, and give the suite a timeout. The tests are skipped by default so a normal test run does not create infrastructure. Cleanup must survive a failed step, which means a sweeper or an explicit destroy path, not only a happy-path CheckDestroy.
| Test | Proves | Catches |
|---|---|---|
| Create and Read | The object exists and state matches it | A missing computed value |
| Update | In-place changes and replacements are correct | A wrong plan modifier |
| Import | The id is sufficient and Read is complete | A broken import parser |
| Destroy and CheckDestroy | Cleanup works | An orphaned object |
| Refresh drift | Read notices a remote change | Stale state |
| Upgrade fixture | Old state decodes into the new shape | A missing upgrader |
Isolation is part of the test design. Generate a unique prefix per run, tag every object with it, and delete by tag in the sweeper. Use a separate account or project; a shared sandbox turns one failed destroy into everyone's quota problem. Serialise tests that share a quota, and budget for eventual consistency.
CI has three layers. Pull requests run unit tests, static checks, schema validation, and a compile of every target. Nightly runs acceptance tests against the sandbox. Release runs the full matrix plus state-upgrade fixtures. Running acceptance tests on every pull request against production is how a provider gets a reputation.
Package for a mirror, not just for a registry. Build one zip per OS and architecture, write a SHA256SUMS file, and sign it if a registry will verify it. A private filesystem or network mirror needs the same layout Terraform expects from a registry. The lock file pins the checksums that clients verify.
A private mirror is a directory with a registry layout. Run terraform providers mirror from a configuration that pins the provider, add every target platform, and point a filesystem_mirror block at the result. The lock file still pins the checksums, so a mirror that serves different bytes fails during init.
Build artifacts follow the registry convention. The zip name carries the provider, version, OS, and architecture; the checksum file and signature sit beside it. A private registry also needs the manifest, while a filesystem mirror consumes the unpacked tree.
Pin exact versions for an air-gapped install. A floating constraint lets a client resolve a version the mirror does not carry, and the failure appears at the worst time. Publish the version, the checksum, and the compatibility note together.
A version is a promise. The provider's semantic version covers configuration compatibility; the schema version covers stored data. A patch release fixes behaviour without changing either. A minor release may add optional attributes and state upgraders. A major release may remove or rename configuration. Document the support window for Terraform and for the API.
Distribution is an operating model. Decide who can publish, how a CVE is handled, which Terraform versions are tested, and how deprecations are announced. The README, the registry page, and the changelog are part of the product. A provider that cannot be installed from a mirror in an air-gapped environment is not finished.
Docs are generated from the schema. The documentation generator reads the provider and produces the resource pages, so descriptions and examples stay close to the code. Add an example for every resource and every import form; the examples are also the acceptance-test configurations.
A provider without docs is a private API. The resource page should state the import id format, the immutable fields, the defaults, and the API permissions required. Put a runnable example beside each resource, and treat a documentation change as a test change.
Support is a versioned interface. Publish which Terraform versions and which API versions each release supports, and keep a deprecation window for attributes. A user who cannot tell whether an upgrade is safe will pin an old release forever, which turns a security fix into a migration project.
Specify a toy provider
Status: executable against a local stub. The lab uses a stub API on localhost, so no cloud account is needed. Versions are Terraform 1.17.1 and Plugin Framework v1.19.0.
Prerequisites. Go 1.25 or later, Terraform 1.17.1, curl, and a stub that stores widgets in memory. The stub must support create, get, patch and delete, and return 404 for a missing id.
Setup. Create the tree:
labs/cdd11/
├── main.go
├── internal/provider/widget_resource.go
├── internal/client/client.go
├── examples/widget/main.tf
└── stub/main.go
Build and install. Build the provider and place it in the filesystem mirror layout:
go build -o terraform-provider-toy_v0.1.0 .
MIRROR="$HOME/.terraform.d/plugins/example.com/example/toy/0.1.0/$(go env GOOS)_$(go env GOARCH)"
mkdir -p "$MIRROR"
cp terraform-provider-toy_v0.1.0 "$MIRROR/"
Point Terraform at the mirror. The include pattern sends only the toy provider to the mirror; everything else stays direct:
provider_installation {
filesystem_mirror {
path = "/Users/you/.terraform.d/plugins"
include = ["example.com/*/*"]
}
direct {
exclude = ["example.com/*/*"]
}
}
Set TF_CLI_CONFIG_FILE to this file, then run init. This is the same layout a production mirror serves, minus the host and access control.
Configuration. The resource has one mutable field and one immutable field:
terraform {
required_providers {
toy = {
source = "example.com/example/toy"
version = "0.1.0"
}
}
}
resource "toy_widget" "demo" {
display_name = "first"
region = "eu-west-1"
}
Prove the round-trip. Run the first apply and then plan again:
export TF_CLI_CONFIG_FILE=./dev.tfrc
terraform init
terraform apply -auto-approve
terraform plan -detailed-exitcode
terraform state show toy_widget.demo
The apply should record an id and all computed fields. The second command should exit 0, which means the plan is empty.
Prove a plan diff. Change the display name, plan, then change the region, plan. The first should be an in-place update; the second should be a replacement because the region is immutable. Read the plan symbols rather than expecting a fixed line count.
Prove import. Remove the object from state, import it by id, and plan again:
terraform state rm toy_widget.demo
terraform import toy_widget.demo wdg_REPLACE_ME
terraform plan -detailed-exitcode
The plan should be empty if the configuration matches the object. A lingering diff means Read does not populate every attribute.
Prove not-found. Delete the object through the stub API while leaving the stub running, then plan. Read should receive 404, remove the resource from state, and the plan should propose a create. An error instead of a create means the not-found branch is wrong.
| Step | Expected observation | What it proves |
|---|---|---|
| Apply | An id and computed values are stored | Create and Read agree |
| Plan after apply | Exit code 0, no diff | State matches the API |
| Change a mutable field | In-place update | Update path and plan modifier |
| Change an immutable field | Replacement | Immutability is declared |
| State remove, then import | Exit code 0 | Import and Read are complete |
| Delete remotely, then plan | Resource removed, create proposed | 404 handling |
| Destroy | Object gone, state empty | Delete and cleanup |
Failure checks. A plan that always diffs, an import that produces a diff, a destroy that leaves the object, or a 404 that crashes the provider each means the round-trip is not proven.
Cleanup. Run destroy, stop the stub, remove the plugin directory, and delete the development override. If the stub persists to disk, remove its data file.
Evidence to keep. The two plan exit codes, the state output with the id, the stub request log with method and status, and a sanitized old-state fixture if you also test an upgrade.