Skip to content

refactor(sdk): separate OpenTofu execution from deployment orchestration - #12863

Merged
cv merged 6 commits into
NVIDIA:v1from
bowenzhu21:refactor/deployment-opentofu-module
Oct 9, 2026
Merged

cv merged 6 commits into
NVIDIA:v1from
bowenzhu21:refactor/deployment-opentofu-module

Conversation

@bowenzhu21

@bowenzhu21 bowenzhu21 commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

OpenTofu configuration, command execution, saved plans, and credential environments move from deployment/mod.rs into deployment/opentofu.rs, and teardown now initializes through that module. mod.rs keeps the public deployment API and the lifecycle. The moved code changes only in visibility.

Fixes #12531.

Failure

deployment/mod.rs mixed the public API and the plan, apply, and teardown lifecycle with about 210 lines that run OpenTofu. Those lines write main.tf.json and providers.tfrc, refuse foreign configuration, choose each command's environment, save plans, and resolve credentials. Teardown also repeated initialize inline.

Changes

  • deployment/opentofu.rs holds the Deployment methods initialize, prepare, tofu, saved_plan, and provider_environment, and the functions command_environment, gateway_environment, and credential_environment. pub(super) gives them the same reach they had as private items of deployment, so the lifecycle in mod.rs, export, the runtime stage, and Helm recovery call them unchanged.
  • mod.rs keeps the API types, run, state_bindings, sandbox_observations, the destroy entry points, and the plan-validation helpers. It shrinks from 704 to 496 lines.
  • Teardown calls initialize instead of prepare followed by tofu init -upgrade. Both run the same command with the schema environment under the tofu.init label.
  • docs/state.md links the new module for main.tf.json and providers.tfrc.

Evidence

  • The move is mechanical. With whitespace ignored, each moved function matches the original. The one exception is prepare's signature, which rustfmt wraps once pub(super) is added. git diff --color-moved shows the rest as moved lines.
  • Two characterization tests come first and pass before and after the move. Foreign .tf, .tf.json, .tofu, and .tofu.json files in the state directory are refused without replacing main.tf.json. providers.tfrc keeps the spaces of a bundle path and uses forward slashes; this pins the generated text, not OpenTofu's parsing of it. Each test fails when the behavior it covers is removed from prepare.
  • Credential isolation keeps its existing tests: schema_commands_do_not_require_inference_credentials, gateway_observation_resolves_only_gateway_credentials, the two credential_references_cannot_override_* tests, and the Kubernetes environment tests.
  • Correction to the premise: discovery no longer runs OpenTofu. feat(onboarding): read the target with the plan's own queries and reads #12579 deleted discovery_session.rs, which held the second provider-mirror writer and the only init -backend=false. prepare is the only mirror writer outside test harnesses, so neither the sharing step nor the discovery criteria leave anything to change.
  • cargo ci passes on Linux ARM64 (1293 tests, 109 lifecycle tests) and macOS ARM64 (1260 tests, 109 lifecycle tests). cargo ci live-docker passes all 10 Docker live tests on Linux. fern check and the docs:: and fern:: tests pass.

Not in this PR

  • state_bindings stays in mod.rs. It chooses the root or runtime graph before reading state and reaches OpenTofu only through initialize and the state store.
  • export.rs and Helm recovery call crate::process::run directly for plan -refresh-only, show -json, and state mv. Routing them through tofu would resolve the full credential environment and add -json, progress, and timing, which changes behavior.

Signed-off-by: Bowen Zhu [email protected]

Cover the provider mirror path for a bundle directory with spaces and the refusal of foreign OpenTofu configuration before moving this code.

Signed-off-by: Bowen Zhu <[email protected]>
Move OpenTofu configuration, command execution, saved plans, and credential environments from deployment/mod.rs into deployment/opentofu.rs. The moved code changes only in visibility.

Signed-off-by: Bowen Zhu <[email protected]>
Teardown repeated initialize inline: it prepared the configuration and ran init -upgrade with the schema environment under the same timing label.

Signed-off-by: Bowen Zhu <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cv
cv enabled auto-merge (squash) October 9, 2026 10:01
@cv
cv merged commit 5b80704 into NVIDIA:v1 Oct 9, 2026
25 checks passed
@cv cv added the v1 NemoClaw v1 branch label Oct 12, 2026
@wscurran wscurran added area: architecture Architecture, design debt, major refactors, or maintainability refactor PR restructures code without intended behavior change security area: security Security controls, permissions, secrets, or hardening and removed security labels Oct 28, 2026
@cv cv added this to the Roadmap: GTC DC 2026 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: architecture Architecture, design debt, major refactors, or maintainability area: security Security controls, permissions, secrets, or hardening refactor PR restructures code without intended behavior change v1 NemoClaw v1 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants