285 Commits

Author SHA1 Message Date
Christian Mesh
feebfb6ab0 Fix serialization error in tofu apply when using cloud.State (#3611)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Co-authored-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-12-19 06:58:20 -05:00
Christian Mesh
4907623433 go.mod: Update "go-tfe" library to latest release (#3413)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-10-22 11:33:35 -07:00
Martin Atkins
e74bf2d0a1 go.mod: Use the new "tool" directive
Previously the Go toolchain had no explicit support for "tools" and so we
used the typical Go community workaround of adding "tools.go" files (two,
for some reason) that existed only to trick the Go toolchain into
considering the tools as dependencies we could track in go.mod.

Go 1.24 introduced explicit support for tracking tools as part of go.mod,
and the ability to run those using "go tool" instead of "go run", and so
this commit switches us over to using that strategy for everything we were
previously managing in tools.go.

There are some intentional exceptions here:

- The protobuf-compile script can't use "go tool" or "go run" because the
  tools in question are run only indirectly through protoc. However, we
  do still use the "tool" directive in go.mod to tell the Go toolchain that
  we depend on those tools, so that it'll track which versions we are
  currently using as part of go.mod.
- Our golangci-lint Makefile target uses "go run" to run a specific
  version of golangci-lint. We _intentionally_ don't consider that tool
  to be a direct dependency of OpenTofu because it has a lot of indirect
  dependencies that would pollute our go.mod file. Therefore that continues
  to use "go run" after this commit.
- Both of our tools.go files previously referred to
  github.com/nishanths/exhaustive , but nothing actually appears to be
  using that tool in the current OpenTofu tree, so it's no longer a
  dependency after this commit.

All of the dependencies we have _only_ for tools are now classified as
"indirect" in the go.mod file. This is the default behavior of the Go
toolchain and appears to be motivated by making it clearer that these
modules do not contribute anything to the runtime behavior of OpenTofu.
This also corrected a historical oddity in our go.mod where for some reason
the "indirect" dependencies had been split across two different "require"
directives; they are now all grouped together in a single directive.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-10 07:06:56 -03:00
Christian Mesh
9583256ca1 Remove all calls to DeepCopy in resource instance write codepath (#3110)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-02 07:24:53 -04:00
Martin Atkins
67a5cd0911 statemgr+remote: context.Context parameters
This extends statemgr.Persistent, statemgr.Locker and remote.Client to
all expect context.Context parameters, and then updates all of the existing
implementations of those interfaces to support them.

All of the calls to statemgr.Persistent and statemgr.Locker methods outside
of tests are consistently context.TODO() for now, because the caller
landscape of these interfaces has some complications:

1. statemgr.Locker is also used by the clistate package for its state
   implementation that was derived from statemgr.Filesystem's predecessor,
   even though what clistate manages is not actually "state" in the sense
   of package statemgr. The callers of that are not yet ready to provide
   real contexts.

   In a future commit we'll either need to plumb context through to all of
   the clistate callers, or continue the effort to separate statemgr from
   clistate by introducing a clistate-specific "locker" API for it
   to use instead.

2. We call statemgr.Persistent and statemgr.Locker methods in situations
   where the active context might have already been cancelled, and so we'll
   need to make sure to ignore cancellation when calling those.

   This is mainly limited to PersistState and Unlock, since both need to
   be able to complete after a cancellation, but there are various
   codepaths that perform a Lock, Refresh, Persist, Unlock sequence and so
   it isn't yet clear where is the best place to enforce the invariant that
   Persist and Unlock must not be called with a cancelable context. We'll
   deal with that more in subsequent commits.

Within the various state manager and remote client implementations the
contexts _are_ wired together as best as possible with how these subsystems
are already laid out, and so once we deal with the problems above and make
callers provide suitable contexts they should be able to reach all of the
leaf API clients that might want to generate OpenTelemetry traces.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-07-10 08:11:39 -07:00
Martin Atkins
ddf126b267 statemgr: Compile-time assertions of interface implementations
This just adds a few previously-missing assertions so that future changes
to these interfaces will correctly identify all of the implementations that
need to be updated.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-07-10 08:11:39 -07:00
Larry Bordowitz
ed6699f8c9 refactor: add err checks (#2896)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-06-17 20:18:53 +04:00
Martin Atkins
d2bef1fd47 Adopt OpenTofu's own "svchost" module
Previously we were using a third-party library, but that doesn't have any
support for passing context.Context through its API and so isn't suitable
for our goals of adding OpenTelemetry tracing for all outgoing network
requests.

We now have our own fork that is updated to use context.Context. It also
has a slightly reduced scope no longer including various details that
are tightly-coupled to our cliconfig mechanism and so better placed in the
main OpenTofu codebase so we can evolve it in future without making
lockstep library releases.

The "registry-address" library also uses svchost and uses some of its types
in its public API, so this also incorporates v2 of that library that is
updated to use our own svchost module.

Unfortunately this commit is a mix of mechanical updates to the new
libraries and some new code dealing with the functionality that is removed
in our fork of svchost. The new code is primarily in the "svcauthconfig"
package, which is similar in purpose "ociauthconfig" but for OpenTofu's
own auth mechanism instead of the OCI Distribution protocol's auth
mechanism.

This includes some additional plumbing of context.Context where it was
possible to do so without broad changes to files that would not otherwise
have been included in this commit, but there are a few leftover spots that
are context.TODO() which we'll address separately in later commits.

This removes the temporary workaround from d079da6e9e, since we are now
able to plumb the OpenTelemetry span tree all the way to the service
discovery requests.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-12 09:37:59 -07:00
Larry Bordowitz
9b6a8fae60 refactor: implement all simple static checks (#2895)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-06-10 15:48:43 -04:00
James Humphries
dd8acbb113 Added otel tracing to show command (#2734)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-22 15:10:23 +01:00
Martin Atkins
b3ab138799 backend: Backend.DeleteWorkspace takes context.Context
This adds a new context.Context argument to the Backend.DeleteWorkspace
method, updates all of the implementations to match, and then updates all
of the callers to pass in a context.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 14:14:34 -07:00
Martin Atkins
601e84ee71 backend: Backend.StateMgr takes context.Context
This adds a new context.Context argument to the Backend.StateMgr method,
updates all of the implementations to match, and then updates all of the
callers to pass in a context.

A small number of callers don't yet have context plumbed to them so those
use context.TODO() as a placeholder for now, so we can more easily find
and fix them in later commits once we have contexts more thoroughly
plumbed.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 14:14:34 -07:00
Martin Atkins
b9573139ab backend: Backend.Workspaces takes context.Context
This adds a new context.Context argument to the Backend.Workspaces method,
updates all of the implementations to match, and then updates all of the
callers to pass in a context.

A small number of callers don't yet have context plumbed to them so those
use context.TODO() as a placeholder for now, so we can more easily find
and fix them in later commits once we have contexts more thoroughly
plumbed.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 14:14:34 -07:00
Martin Atkins
2922059ff3 backend: Backend.Configure takes context.Context
This adds a new context.Context argument to the Backend.Configure method,
updates all of the implementations to match, and then updates all of the
callers to pass in a context.

A small number of callers don't yet have context plumbed to them so those
use context.TODO() as a placeholder for now, so we can more easily find
and fix them in later commits once we have contexts more thoroughly
plumbed.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 14:14:34 -07:00
Martin Atkins
45e3a7bcf4 various: Remove context.TODO() usage from all tests
When context.Context was new, APIs using it arrived sporadically and so
the Go team introduced context.TODO() as an explicit way to say "I need a
context but I don't yet have a useful one to provide".

It took quite a while for there to be an established pattern for contexts
in tests, but now there is finally testing.T.Context which returns a
context that gets cancelled once the test is complete, and so that's a good
parent context to use for all contexts belonging to a test case.

This commit therefore mechanically replaces every use of context.TODO in
our test cases throughout the codebase with a call to t.Context instead.
There were a small number of tests that were using a mixture of
context.TODO and context.Background as placeholders and so those are also
updated to use t.Context consistently. There are probably still some
remaining uses of context.Background in our tests, but we'll save those
for another day.

As of this commit there are still various uses of context.TODO left in
_non-test_ code, but we need to take more care in how we update those so
those are intentionally excluded here.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 10:33:03 -07:00
Martin Atkins
f976391a42 cloud: Fix errcheck lint failure in some tests
(The "cloud" package seems to have started as a copy-paste of
backend/remote, so one of these fixes also needs to be made in there, but
it's identical.)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-07 10:33:03 -07:00
James Humphries
6d3aed0e8f [OpenTelemetry] Add module init tracing (#2711)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-01 14:15:03 +01:00
Oleksandr Levchenkov
82d71e50e8 add deprecation warnings support for terraform_remote_state (#2679)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-04-25 12:26:28 +03:00
Martin Atkins
1b9b5cea79 Use modern helpers from Go's testing.T API (#2692)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-23 07:48:41 -04:00
Christian Mesh
b2bf39802a Implement the first part of RFC 20250303-linter-policy (#2577)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-03-10 13:16:27 -04:00
Martin Atkins
620b449533 Prepare for upgrade to golangci-lint v1.64.5
In a future commit we will adopt golangci-lint v1.64.5, which now triggers
lint warnings for some code that was previously not detected. This commit
is the smallest change to address those differences.

Unfortunately the "cloud" package and the "remote" backend both rely on
non-idiomatic error message formatting because they emit the returned error
message text directly into the UI, so to avoid changing the UI output but
also avoid significant refactoring this just adds nolint comments to those
for now. A future commit might address this by reworking things so that
the UI takes care of its own presentation concerns instead of relying on
the main implementation to directly generate UI-appropriate error strings.

This also completely disables the exportloopref linter, because that was
for a loop scoping hazard that was already addressed by a language change
in Go 1.22. This linter is therefore completely removed in newer versions
of golangci-lint and would thus generate an error if left enabled after
upgrading.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-02-26 11:33:43 -08:00
Mikel Olasagasti Uranga
66765bdab3 Fix: Ensure constant format strings in fmt and printf calls
Go 1.24 introduces stricter checks for format string validation.
This commit fixes instances where non-constant format strings were
used in calls to functions like `fmt.Errorf`, `fmt.Printf`, and similar.

Changes include:
- Replacing dynamically constructed strings passed as format strings
with constant format strings.
- Refactoring `fmt.Sprintf` calls to ensure the format string matches
the number of arguments provided.
- Simplifying redundant formatting and ensuring compliance with Go
1.24's stricter `vet` tool checks.

This update ensures compatibility with Go 1.24 and prevents potential
runtime errors caused by misinterpreted dynamic format strings.

Resolves #2389

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-02-26 11:33:43 -08:00
James Humphries
c1f1008723 Replace mock module with go.uber.org/mock (#1673)
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Signed-off-by: James Humphries <james@james-humphries.co.uk>
Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
2025-01-10 08:29:20 -05:00
Martin Atkins
ad32bde2ae Temporarily disable the complexity-related lint rules
We're intending to gradually improve all of the existing functions that
fail these checks as a separate project from other work, because fixing
for these particular lint rules tends to be too invasive to be safe or
sensible to combine with other work.

Therefore we'll temporarily disable these lints from the main lint run
and add a separate .golangci-complexity.yml that we can use to track our
progress towards eliminating those lint failures without continuing to
litter the code with nolint comments in the meantime.

This also removes all of the existing nolint comments for these linters so
that we can start fresh and review each one as part of our improvement
project.

We'll re-enable these linters (and remove .golangci-complexity.yml) once
each example has either been rewritten to pass the checks or we've
concluded that further decomposition would hurt readability and so added
"nolint" comments back in so we can review whether our lint rules are too
strict once we've got a bunch of examples to consider together.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-03 10:41:05 -05:00
Martin Atkins
9cadb097ba tofu: Context.Validate now takes a context.Context
This continues our ongoing effort to get a coherent chain of
context.Context all the way from "package main" to all of our calls to
external components.

Context.Validate doesn't yet do anything with its new context, but we'll
plumb this deeper in future.

Since the local backend's implementation of backend.Local.LocalRun calls
Validate on the given configuration before returning, it this also extends
that interface method to take a context, and so the various commands that
directly create "local runs" (rather than going through the backend
operation API) now all pass in a context derived from the one created
in "package main".

All of the _test.go file updates here are purely mechanical additions of
the extra argument. No test is materially modified by this change, which
is intentional to get some assurance that isn't a breaking change.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2024-11-19 10:15:21 -08:00
Arel Rabinowitz
3d4bf29c56 Add exclude flag support (#1900)
Signed-off-by: RLRabinowitz <rlrabinowitz2@gmail.com>
2024-11-05 10:16:00 -05:00
Nathan Baulch
ea558d9d4b Fix typos (#1905)
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-08-29 13:20:33 -04:00
Ronny Orot
23d69e2351 Cloud Backend - Fix logic that forces TF_WORKSPACE to be equal to a tag name (#1930)
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
2024-08-22 10:55:50 +03:00
Emre Duzgun
b93acf96a9 Fix more tests on Windows (#1824)
Signed-off-by: eduzgun <emreduz00@gmail.com>
2024-07-17 10:41:12 -04:00
Denis O
864aa9d1d6 Error handling fixes (#1816)
Signed-off-by: Denis O <denis.o@linux.com>
2024-07-15 11:58:43 +02:00
Christian Mesh
8f8e0aa4aa Static Evaluation Base, Module Sources, Backend Config (#1718)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Christian Mesh <cristianmesh1@gmail.com>
Co-authored-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2024-06-24 09:13:07 -04:00
1garo
d869923103 Review and order locked struct fields (#1493)
Signed-off-by: 1garo <alevardai427@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-04-25 10:25:13 -04:00
Oleksandr Levchenkov
739a66a86c fix panic when encryption enabled for remote and cloud backends (#1431)
Signed-off-by: ollevche <ollevche@gmail.com>
2024-03-25 20:42:18 +02:00
Christian Mesh
5ab6167bbf Initial wiring of encryption through the command package (#1316)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-07 08:55:57 -05:00
Christian Mesh
2f5dcd5c0a Integrate Encryption into State Backends (#1288)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-04 09:25:14 -05:00
namgyalangmo
cb2e9119aa Update copyright notice (#1232)
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
2024-02-08 09:48:59 +00:00
Dmitry Kisler
7d73f2bbe6 Refactor tests to follow a safer way of setting envvars (#1215)
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
2024-01-31 11:25:02 +01:00
Christian Mesh
54d2130473 Find additional places where terraform should be replaced with tofu (#1001)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-13 07:18:43 -05:00
Christian Mesh
25a6f51732 898 consolidate and remove tfe addr [part 2] (#998)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-12 11:22:39 -05:00
Christian Mesh
35ca1aeed8 Add gate for TFE tests that use the network (#997)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-12 09:58:13 -05:00
Christian Mesh
abd324ea7c Revert "Fixes #898: Replace hashicorp and terraform references" (#995) 2023-12-11 15:10:03 -05:00
Janos
15bef1428a Fixes #898: Replace hashicorp and terraform references (#973)
Signed-off-by: Janos Bonic <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-08 08:03:09 -05:00
Dmitry Kisler
c5170df91a Fix workspaces configuration using environment varariable TF_WORKSPACE (#867)
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
2023-11-16 18:43:47 +01:00
Thiago Padilha
25b52ba736 Update go-tfe to 1.36.0 (#844)
Signed-off-by: Thiago Padilha <thiago@padilha.cc>
2023-11-09 15:40:58 +01:00
James Humphries
9c24b6183a Revert PRs that introduced propogating contexts (#835)
Co-authored-by: Dmitry Kisler <admin@dkisler.com>
2023-11-08 21:09:14 +00:00
Igor Savchenko
572d8d95d1 Update user-agent from go-tfe to opentofu where go-tfe is used (#807) 2023-11-02 12:11:13 +01:00
Marcin Wyszynski
772ac1fc35 Pass context to all statemgr.Locker operations (#789)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-25 14:22:11 +02:00
Marcin Wyszynski
275dd116f9 Pass context to all remote.Client operations (#786)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-25 12:37:58 +02:00
Marcin Wyszynski
da1ba56b41 Make backend.Workspaces accept a context (#784)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-24 19:59:28 +02:00
Marcin Wyszynski
925db6dbc5 Make backend.DeleteWorkspace accept a context (#782)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-24 16:55:03 +02:00