418 Commits

Author SHA1 Message Date
Andrei Ciobanu
e8d1bb6882 Small tweaks on the guidelines and the scripts for testing the azure backend (#3603)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-12-18 08:58:33 +02: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
ffc9c4d556 Split out provider schemas vs instances in new engine (#3530)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-12-01 13:09:58 -05:00
Martin Atkins
09815665de backend/local: Scaffolding for new runtime can use providers
This is some minimal glue to help the new runtime use the providers that
were gathered up by the existing logic in the "command" package.

This is cheating a little because this is relying on "tofu init" still
using the old approach just enough to find out which providers are needed
and get them installed, but our current focus is on the main plan and
apply phases and so it's convenient to be able to leave that part untouched
for now and return to improve it later, once we have more of the
fundamentals in place.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-21 09:20:59 -08:00
Martin Atkins
102449c9ec backend/local: Use experimental runtime for planning, when enabled
This is a relatively uninteresting milestone where it's possible to load
and plan a root module that contains nothing except local values and
output values.

The module loader currently supports only local sources and the plugin
APIs just immediately return errors, so configurations more complicated
than that are likely to just fail immediately with one or more errors.
We'll gradually improve on this in later commits.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-21 09:20:59 -08:00
Martin Atkins
367244a8f9 local/backend: Stub dependency fetchers for new runtime glue
None of these actually work yet, but this satisfies the new-style config
loader enough for it to return a real error instead of immediately
panicking.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-21 09:20:59 -08:00
Martin Atkins
ae60da8e7c backend/local: Initial sketch of new-engine planning
This doesn't actually work yet. It's just to sketch out a minimal overall
sequence of steps to make this behave somewhat like the main implementation
of "tofu plan", and then we'll make it work better in subsequent commits.

The main omission as of this commit is that we don't yet pass module,
provider, and provisioner dependency access objects in the EvalContext,
and so config loading immediately fails trying to request the root module
from a nil object.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-11-21 09:20:59 -08: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
aleksandarss
730a60826c backend/tests: use workspace argument in testLocksInWorkspace (#3405)
Signed-off-by: aleksandarss <aleksandar-sasa.calic@hotmail.com>
2025-10-24 16:11:01 -04:00
Larry Bordowitz
8b99bac328 go.mod: upgrade tencent libraries (#3412)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-10-22 16:51:52 +01:00
Diogenes Fernandes
13f2a9fcec refactor: use TF_AZURE_TEST_CLIENT_* variables instead of default ones
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-22 11:44:39 -03:00
Diogenes Fernandes
8b4fcce514 test: allowing environment variables on azure acceptance tests
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-22 11:44:39 -03:00
Diogenes Fernandes
6a2bb41f9a test: avoid panics
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-22 11:44:39 -03:00
Martin Atkins
3426be27ef go.mod: go get k8s.io/client-go@v0.34.1
This also updates the other three k8s.io/* modules that we use, as
prerequisites for the upgrade.

The indirect dependency landscape for these modules has changed quite a lot
since the versions we were previously using, and so we have some new
indirect dependencies here. I quickly reviewed each of them and confirmed
that they seem to be under suitable licenses.

The k8s.io/utils/pointer package has been deprecated in favor of
k8s.io/utils/ptr, so this also updates our two callers of that to avoid
calling into deprecated functions.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-21 06:54:13 -07:00
Andrei Ciobanu
943c54079a go.mod: go get cloud.google.com/go/storage@v1.57.0 (#3385)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-10-17 18:16:53 +03:00
Martin Atkins
cc5d324098 go.mod: go get go.uber.org/mock@v0.6.0
This is just a routine upgrade. We use this dependency only in our tests,
so this upgrade does not risk changing OpenTofu's behavior. There do not
seem to be any concerning changes upstream.

There are some systematic changes to the shape of the generated mock code,
with the results also included in this commit.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-13 08:18:06 -07:00
Martin Atkins
cbfc28472d go.mod: Upgrade various golang.org/x/* dependencies
The Go team uses automation to generate unnecessary version bumps across
all of these that make it impossible to upgrade them individually because
they all mutually depend on the latest versions of each other, so
unfortunately we have to accept the risk of updating all of these at once
in order to update any one of them.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-10 08:23:54 -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
Larry Bordowitz
bcbfebce3d Implement the Azure Key Provider
This uses the same auth package as the newly-rewritten Azure State
Backend, so many of the properties and environment variables are the
same. I have put this through both the compliance test as well as built
the binary and run some end-to-end tests, and found that it
appropriately uses the Azure key as expected.

Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-09-29 06:19:02 -04:00
Diógenes Fernandes
4c7122ba19 fix internal/backend/local tests by closing file handle properly (#3284)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-22 11:24:42 -03:00
Andrei Ciobanu
cf971eb3b6 Rework the way ephemeral variables are used when given on tofu apply command (#3192)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-22 09:31:19 +03:00
Diógenes Fernandes
2d5ea98257 skip timeout lock tests on windows (#3288)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-17 16:56:19 -03:00
Larry Bordowitz
0090e8a18c Add new configuration to AzureRM Backend (#3251)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-09-15 19:22:17 +01:00
Martin Atkins
5fa35c5601 backend+command: Alias names for backend types
This introduces the concept of "backend aliases", which are alternative
names that can be used to refer to a given backend.

Each backend type has one canonical name and zero or more alias names. The
"backend" block in the root module can specify either a canonical backend
type or an alias, but internally OpenTofu will always track the backend
type using its canonical name.

In particular, the following are all true when the configuration specifies
an alias instead of a canonical backend type:
- The "tofu init" output includes a brief extra message saying which
  backend type OpenTofu actually used, because that is the name that we'd
  prioritize in our documentation and so an operator can use the canonical
  type to find the relevant docs when needed.
- The .terraform/terraform.tfstate file that tracks the working directory's
  currently-initialized backend settings always uses the canonical backend
  type, and so it's possible to freely switch between aliases and canonical
  without "tofu init" thinking that a state migration might be needed.
- Plan files similarly use the canonical backend type to track which
  backend was active when the plan was created, which doesn't have any
  significant user-facing purpose, but is consistent with the previous
  point since the settings in the plan file effectively substitute for
  the .terraform/terraform.tfstate file when applying a saved plan.
- The terraform_remote_state data source in the provider
  terraform.io/builtin/terraform accepts both canonical and alias in its
  backend type argument, treating both as equivalent for the purpose of
  fetching the state snapshot for the configured workspace.

The primary motivation for this new facility is to allow the planned
"oracle_oci" backend to have an alias "oci" to allow writing configurations
that are cross-compatible with HashiCorp Terraform, since that software
has chosen to have unqualified OCI mean Oracle's system, whereas OpenTofu
has previously established that unqualified OCI means "Open Container
Initiative" in our ecosystem.

In particular, this design makes it possible in principle to bring an
existing Terraform configuration specifying backend "oci" over to OpenTofu
without modifications, and then to optionally switch it to specifying
backend "oracle-oci" at a later time without a spurious prompt to migrate
state snapshots to the same physical location where they are already
stored.

This commit doesn't actually introduce any aliases and therefore doesn't
have any tests for the new mechanism because our backend system uses a
global table that isn't friendly to mocking for testing purposes. I've
tested this manually using a placeholder alias to have confidence that it
works, and I expect that a subsequent commit introducing the new
"oracle_oci" backend will also introduce its "oci" alias and will include
tests that cover use of the alias and migration from the alias to the
canonical name and vice-versa.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-11 11:33:53 -07:00
Christian Mesh
c8b58e949b Address review comments
Co-authored-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Andrei Ciobanu
013097b631 Ephemeral variables (#3108)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Larry Bordowitz
63e8845ad9 Refactor the azurerm backend (#3034)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-09-03 11:06:11 -04:00
Diógenes Fernandes
35a3100cfe Fix http test server errors on TestBackendConfig_Authentication by removing usage of os.Clearenv (#3221)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-02 16:15:30 -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
Diógenes Fernandes
b969c73ee8 fix: filepath.Separator was used to parse URLs (#3220)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-02 07:35:17 -03:00
Diógenes Fernandes
018bbc5089 fix windows tests at internal/backend/local (#3198)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-08-28 12:18:42 -03:00
Christian Mesh
928533f1fe Reduce calls to state DeepCopy() by half during apply (#3011)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-08-26 14:36:01 -04:00
Mikhail Dronov
dfe6c6d514 Fix internal/backend TestRead_PathNoPermission on Windows (#3117)
Signed-off-by: Mikhail Dronov <twtrp@proton.me>
2025-08-21 15:50:27 -03:00
Andrei Ciobanu
48c55a4bfe Add logging for dynamodb client in s3 backend (#3103)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-08-20 11:28:02 +03:00
Aaron George
e802c63f58 Add tag options for S3 state backend objects (#3038)
Signed-off-by: Aaron George <aarongeorge1994+github@gmail.com>
Co-authored-by: Andrei Ciobanu <andreic9203@gmail.com>
2025-08-07 10:39:19 +03:00
Christian Mesh
2aa3af37a2 Reduce calls to ListKey in azure backend (#3083)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-07-31 08:39:07 -04:00
Christian Mesh
f311f013fc Fix azure backend tests (#3084)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-07-31 07:43:28 -04:00
Christian Mesh
be433be96f Support for static variables used with encrypted plans (#1998)
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-07-28 12:11:43 -04:00
Martin Atkins
868dc2f01b hcl2shim: Split out legacy subset
Due to some past confusion about the purpose of this package, it has grown
to include a confusing mix of currently-viable code and legacy support
code from the move to HCL 2. This has in turn caused confusion about which
parts of this package _should_ be used for new code.

To help clarify that distinction we'll move the legacy support code into
a package under the "legacy" directory, which is also where most of its
callers live.

There are unfortunately still some callers to these outside of the legacy
tree, but the vast majority are either old tests written before HCL 2
adoption or helper code used only by those tests. The one dubious exception
is the use in ResourceInstanceObjectSrc.Decode, which makes a best effort
to shim flatmap as a concession to the fact that not all state-loading
codepaths are able to run the provider state upgrade function that would
normally be responsible for the flatmap-to-JSON conversion, which is
explained in a new comment inline.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-07-10 08:13:25 -07: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
Andrei Ciobanu
a183f8ac6d Adjust one of the tests to ensure that the customer managed sse is configured correctly for the request to get the lock file (#2978)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-06-30 11:26:47 -04:00
Andrei Ciobanu
482042e3f1 Unify encryption calls s3 backend (#2976)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-06-30 17:19:43 +03:00
Andrei Ciobanu
0e8d32e556 Add encryption headers for the s3 native locking file (#2975)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-06-30 16:51:12 +03:00
Martin Atkins
0afbaae42d backend/s3: Use APNInfo instead of UserAgent (#2955)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-25 09:15:40 -04: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
Larry Bordowitz
839392d52c refactor: remove unused func in s3 backend (#2879)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-06-10 10:28:17 -04:00
Larry Bordowitz
afa7787859 refactor: fix deprecated Google Cloud KMS lib (#2897)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-06-10 10:24:16 -04:00