Write a target's OpenTofu state
Code Mode: praxis.devops.projects.environments.targets.state.create
HTTP: POST /devops/v1/projects/{project}/environments/{environment}/targets/{target}/state
Store a new OpenTofu state for one deploy target. OpenTofu calls this after every apply, passing the lock ID it holds as ID. Each accepted write also keeps an immutable version of that state (the latest 50 per target are kept), so a rollout’s state change can be audited. A state document is at most 1 MiB. A write whose serial is lower than the stored serial of the same lineage is a stale write and answers 409 STALE_SERIAL; re-run so OpenTofu reads the newer state first.
Signature
praxis.devops.projects.environments.targets.state.create(args:{path:{/** e.g. "dvp_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ project:string;/** e.g. "dve_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ environment:string;/** e.g. "services%2Fontology" */ target:string};query?:{/** e.g. "4c1f0a52-8f4e-9d6c-1b0e-5a7d3c2e9f10" */ ID?:string};body:{/** The state format version OpenTofu wrote. e.g. 4 */ version?:number;/** Increases with every state change; a write lower than the stored serial of the same lineage is refused as stale. e.g. 12 */ serial:number;/** Identifies one state history; it does not change across writes. e.g. "7b2c1e9a-3d4f-8a6b-5c7d-9e0f1a2b3c4d" */ lineage:string;[key:string]:unknown}}):Promise<unknown>;Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| project | path | string | yes | Identifies the project whose data you are reading, from the project list or create answer. |
| environment | path | string | yes | Identifies the DevOps environment (dve_…) whose deploy state you address, from the project’s environment list. |
| target | path | string | yes | The deploy target’s repository path, URL-encoded as one segment: services/ontology is written services%2Fontology. |
| ID | query | string | no | The ID of the lock this call holds, exactly as OpenTofu received it from the lock call. Required while a lock is held; a missing or different ID answers 409 LOCK_CONFLICT. |
Request body
| Required | Content types | Description |
|---|---|---|
| yes | application/json | The OpenTofu state document; its serial and lineage fields are required. |
Responses
| Status | Content types | Description |
|---|---|---|
| 200 | The state was stored and a version of it was kept. | |
| 400 | application/json | INVALID_PARAMS or INVALID_ARGUMENT means a field, query value or identifier violates the documented format or range — an unknown enum value, a pageSize outside 1..100, an unsupported filter or orderBy field, or an id with the wrong prefix. Correct the named input; nothing was read or written. |
| 401 | application/json | The API key is missing or invalid; send a valid Praxis API key in the Authorization header before retrying. |
| 404 | application/json | NOT_FOUND means the project or environment does not exist for this organization, or, on a read, that the target has no state yet. Nothing is revealed about another organization’s projects. OpenTofu reads a missing state as empty. |
| 409 | application/json | LOCK_CONFLICT means the state is locked by another holder or the ID names a lock that is not held; STALE_SERIAL means the write is older than the stored state of the same lineage. Nothing changed; re-run the deploy so OpenTofu takes the lock and reads the current state. |
| 413 | application/json | PAYLOAD_TOO_LARGE means the state document is over 1 MiB; split the target’s resources so each state stays smaller. Nothing was stored. |
| 500 | application/json | INTERNAL means the service could not complete the request; retry once, and if it repeats report the request id. A read is safe to repeat; a write that failed this way should be re-read before it is sent again. |