Commit Graph

900 Commits

Author SHA1 Message Date
krishna sindhur
6a385c3cbc Read state refactor (#3706)
Signed-off-by: KrishnaSindhur <krishna.sindhur@harness.io>
Signed-off-by: krishna sindhur <krishna.sindhur@harness.io>
2026-03-19 17:03:16 +02:00
Martin Atkins
551579f5eb configs: New-style core version constraints, etc
Previously we interpreted a "required_version" argument in a "terraform"
block as if it were specifying an OpenTofu version constraint, when in
reality most modules use this to represent a version constraint for
OpenTofu's predecessor instead.

The primary effect of this commit is to introduce a new top-level block
type called "language" which describes language and implementation
compatibility metadata in a way that intentionally differs from what's used
by OpenTofu's predecessor.

This also causes OpenTofu to ignore the required_version argument unless
it appears in an OpenTofu-specific file with a ".tofu" suffix, and makes
OpenTofu completely ignore the language edition and experimental feature
opt-in options from OpenTofu's predecessor on the assumption that those
could continue to evolve independently of changes in OpenTofu.

We retain support for using required_versions in .tofu files as a bridge
solution for modules that need to remain compatible with OpenTofu versions
prior to v1.12. Module authors should keep following the strategy of
having both a versions.tf and a versions.tofu file for now, and wait until
the OpenTofu v1.11 series is end-of-life before adopting the new "language"
block type.

I also took this opportunity to simplify how we handle these parts of the
configuration, since the OpenTofu project has no immediate plans to use
either multiple language editions or language experiments and so for now
we can reduce our handling of those language features to just enough that
we'd return reasonable error messages if today's OpenTofu is exposed to
a module that was written for a newer version of OpenTofu that extends
these language features. The cross-cutting plumbing for representing the
active experiments for a module is still present so that we can reactivate
it later if we need to, but for now that set will always be empty.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2026-03-18 09:09:50 -07:00
Martin Atkins
a800d250e5 command: "go fix" on various files we've changed recently anyway
We don't typically just broadly run automatic rewriting tools like "go fix"
across our codebase because that tends to cause annoying and unnecessary
merge conflicts when we're backporting to earlier release branches.

But all of the files in this commit were changed in some non-trivial way
already during the OpenTofu v1.11 development period anyway, and so the
likelyhood we'd be able to successfully backport from them is reduced and
therefore this seems like a good opportunity to do some focused
modernization using "go fix".

My rules for what to include or not are admittedly quite "vibes-based", but
the general idea was:

 - Focusing on files under the "command" directory only, because that's
   already been an area of intentional refactoring during this development
   period.
 - If the existing diff in a file is already significantly larger than
   the changes the fixer proposed to make, or if the fixer is proposing
   to change a line that was already changed in this development period.
 - More willing to include "_test.go" files than non-test files, even if
   they hadn't changed as much already, just because backports from test
   files for bug fixes tend to be entirely new test cases more than they
   are modifications to existing test cases, and so the risk of conflicts
   is lower there.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2026-03-17 15:25:30 -07:00
Andrei Ciobanu
f805983ed4 Fix the simple-provider schema for data-source (#3884)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-16 15:25:55 +02:00
Andrei Ciobanu
a673617189 Refactor state rm command to use View instead of Ui and to use the arguments package (#3849)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-10 17:54:01 +02:00
Andrei Ciobanu
fc9c19eb9a Refactor state replace-provider command to use View instead of Ui and to use the arguments package (#3844)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-10 17:01:58 +02:00
Andrei Ciobanu
2ed9550790 Refactor state push command to use View instead of Ui and to use the arguments package (#3842)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-09 13:00:30 +02:00
Andrei Ciobanu
aeb3bfe452 Refactor state pull command to use View instead of Ui and to use the arguments package (#3837)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-09 12:25:18 +02:00
Andrei Ciobanu
315d028767 Refactor state mv command to use View instead of Ui and to use the arguments package (#3835)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-06 15:22:52 +02:00
Andrei Ciobanu
db00cb2f3b Refactor import command to use View instead of Ui and to use the arguments package (#3772)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-06 15:11:57 +02:00
Andrei Ciobanu
f9f8b1a258 Use the arguments already configured ViewOptions (#3836)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 15:33:15 +02:00
Andrei Ciobanu
5fcfb23eb5 Refactor fmt command to use View instead of Ui and to use the arguments package (#3805)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 14:47:37 +02:00
Andrei Ciobanu
383d6b3595 Refactor version command to use View instead of Ui and to use the arguments package (#3806)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 14:47:29 +02:00
Andrei Ciobanu
b992aa6582 Refactor taint && untaint commands to use View instead of Ui and to use the arguments package (#3818)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 09:50:36 +02:00
Andrei Ciobanu
9b389f7b1a Refactor providers lock command to use View instead of Ui and to use the arguments package (#3812)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 09:49:36 +02:00
Andrei Ciobanu
b3a6820bdf Refactor providers command to use View instead of Ui and to use the arguments package (#3811)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-05 09:49:15 +02:00
Andrei Ciobanu
7338f5748b Refactor graph command to use View instead of Ui and to use the arguments package (#3802)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-04 15:21:37 +02:00
Andrei Ciobanu
c98d5e22c7 Refactor providers mirror command to use View instead of Ui and to use the arguments package (#3813)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-04 15:20:39 +02:00
Andrei Ciobanu
1201c49010 Refactor unlock command to use View instead of Ui and to use the arguments package (#3823)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-04 15:20:19 +02:00
Andrei Ciobanu
6cd6a7e320 Refactor state list command to use View instead of Ui and to use the arguments package (#3828)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-04 15:20:06 +02:00
Andrei Ciobanu
0ffecc7a14 Refactor all workspace commands to use View instead of Ui (#3770)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-03 12:44:56 +02:00
Andrei Ciobanu
d701eecf47 Refactor console command to use View instead of Ui (#3764)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-03-02 18:58:11 +02:00
Andrei Ciobanu
b25f956321 Add -lock and -lock-timeout flags to the console command (#3800)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-25 17:36:19 +02:00
Christian Mesh
ef97fd2b51 Introduce plugin library and managers (#3652)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2026-02-24 08:51:48 -05:00
Andrei Ciobanu
9d1fe0fdd7 Refactor get command to use View instead of Ui (#3752)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-24 10:07:28 +02:00
Andrei Ciobanu
09fa061581 Refactor logout command to use View instead of Ui (#3761)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-24 10:05:54 +02:00
Andrei Ciobanu
a59b4843a0 Refactor login command to use View instead of Ui (#3757)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-17 00:29:59 +02:00
Andrei Ciobanu
5603b8a27c Refactor init command to use View instead of Ui (#3749)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-11 16:29:31 +02:00
Andrei Ciobanu
da0f45bf69 Move all implementation of flag.Value in one package (#3725)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-10 16:26:09 +02:00
Andrei Ciobanu
25d652dece -chdir unification with the workdir logic. Removal of workdir proxy methods from Meta (#3713)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-10 15:31:06 +02:00
Christian Mesh
08ba66ab6e Move new engine integration point into tofu.Context (#3718)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2026-02-03 09:07:54 -05:00
Christian Mesh
6280691025 Support dual output streams in most commands (#3606)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Diógenes Fernandes <diofeher@gmail.com>
2026-01-20 14:08:10 -05:00
Denis O
9dbb5fcb9c Error checking simplifications (#3694)
Signed-off-by: Denis O <denis.o@linux.com>
2026-01-20 09:27:14 +00:00
yy
4a86a1233c fix: typos in comments (#3691)
Signed-off-by: Yohei Yamamoto <yhymmt123@gmail.com>
2026-01-19 13:46:12 +00:00
Martin Atkins
f4d4a21925 command: Enable experimental runtime in BackendForLocalPlan
We previously added a check like this to the Meta.Backend method, but we
use Meta.BackendForLocalPlan instead when we're applying a saved plan, so
we need to make sure the setting gets propagated here too or else the
experimental codepath cannot be entered by the "tofu apply" command.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2026-01-16 09:50:36 -08:00
Andrei Ciobanu
6d2c5b2100 Render write-only attributes after rendered all of the other attributes (#3667)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-01-16 09:46:54 +02:00
James Humphries
16f6b2d119 Handle ignoring computed fields in ignore_changes blocks for testing (#3646)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2026-01-08 10:51:40 +00:00
James Humphries
56b63795af Fix Http Backend failing to unlock state on Ctrl+C during apply (#3637)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2026-01-05 07:27:10 -05:00
Christian Mesh
a3fe39ff33 Remove global schema cache and clean up tofu schema/contextPlugins (#3589)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-12-17 09:49:39 -05:00
Ilia Gogotchuri
1eacb9a046 Retaining resources during destruction - New flag -suppress-forget-errors (#3588)
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
2025-12-16 15:41:03 +04:00
Christian Mesh
0256de5c4d Consolidate provider resource mocking and overrides (#3547)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-12-15 08:52:10 -05:00
Ilia Gogotchuri
ce5944085f Retaining resource during destruction - action and reason marshalling extension (#3569)
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
2025-12-12 15:16:54 +04:00
Ilia Gogotchuri
fd19a3763f Retain resource instances with a new lifecycle argument - destroy (#3409)
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
Co-authored-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-12-04 18:49:57 +04:00
Christian Mesh
5e7397b8a3 Parallelize provider installation (#2729)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-12-01 11:55:53 -05:00
Christian Mesh
607d74c882 Defer provider checksum and parallelize schema fetching (#2730)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-12-01 11:28:52 -05:00
Andrei Ciobanu
4d16e6f28c Remove unused deprecation flags (#3528)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-11-26 16:28:16 +02:00
Martin Atkins
ff5f45520d backend/local: Opt-in to experimental plan/apply/refresh functions
To facilitate early development and testing of the new language runtime
we're introducing a temporary mechanism to opt in to using the new codepaths
based on an environment variable. This environment variable is effective
only for experiment-enabled builds of OpenTofu, and so it will be
completely ignored by official releases of OpenTofu.

This commit just deals with the "wiring" of this new mechanism, without
actually connecting it with the new language runtime yet. The goal here
is to disturb existing codepaths as little as possible to minimize both
the risk of making this change and the burden this causes for ongoing
maintenance unrelated to work on the new language runtime.

This strategy of switching at the local backend layer means that we will
have some duplicated logic in the experimental functions compared to the
non-experimental functions, which is an intentional tradeoff to allow us
to isolate what we're doing so we don't churn existing code while we're
still in this early exploration phase. In a later phase of the language
runtime project we may pivot to a different approach which switches at
a deeper point in the call stack, but for now we're keeping this broad
to give us flexibility.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-21 09:20:59 -08:00
Christian Mesh
95d75b3436 Fix import validation with resource reference (unknown value) (#3513)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-11-19 09:58:35 -05:00
Martin Atkins
6c46636af4 Mention in logs and version output when FIPS-140-3 mode is enabled
Unfortunately the Go team has unilaterally decided that all programs built
with Go 1.24 and later always allow enabling FIPS-140-3 mode -- both in
its "on" and "only" configurations -- regardless of whether the authors
of that software intend to support running in that restricted mode, or
whether they are even testing their application in that configuration.

We have not yet made a final decision on how and whether we intend to
support this mode in our official builds, but we _do_ know that OpenTofu
cannot currently function correctly with this mode enabled because it
relies on standard library features and external libraries that are not
available in that case.

Therefore in the meantime we'll mention explicitly in both the internal
logs and in the "tofu version" output if we appear to be running in that
mode, meaning that if someone tries to use it and finds that it doesn't
work properly then if they open a GitHub issue and share those two
artifacts (as requested by our bug report template) then we can know that
we might need to turn on the special mode in order to reproduce the
reported problem, rather than wasting time trying to reproduce it in the
standard mode.

We do still need to make a final decision about what we want to do with
this in the long run, but this is intended as an short-term compromise
that allows folks to experiment with this unsupported mode if they wish
while hopefully making it clearer that in the mean time we may
deprioritize fixing problems that only occur when this unusual mode is
enabled.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-17 07:40:11 -05:00
Martin Atkins
e389a7f2fa website: Warn about "tofu output -raw" in a terminal
By design the "-raw" option to "tofu output" writes the literal output
value directly to stdout without any quoting or escaping, and so it's
risky to use it with an output value that could be controlled by an
attacker when stdout is a terminal.

This risk is inherent in the purpose of this option and is part of the
reason why this is not the default behavior (OpenTofu returns a quoted
representation of an output string by default) so here we just make that
risk explicit in the documentation, in the hope that operators will use
this operation mindfully.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-10 09:49:35 -08:00