Commit Graph

32726 Commits

Author SHA1 Message Date
Christian Mesh
608129b910 Module eval caching
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-21 17:16:29 -04:00
Christian Mesh
e1d642ecb9 Tweak state sync logic
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-21 16:25:00 -04:00
Christian Mesh
ccdbb06c58 Experimental caching of computed values from state+changes
This adds a cache for resource values that is evicted by changes
to state or plan sync objects.  In theory the eviction is not needed,
but there are hints from tests that that assumption is not fully
correct.

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-21 15:51:51 -04:00
Christian Mesh
7d849791ab Remove m*n locking from resource evaluation and O(m * n * (m+n)) iteration
When given a resource m that depends on resource n, if for_each or count
were used in any significant way a massive lock contention was
encountered.

In pseudocode:
```
for mi in m {
  for ni in n {
    lock()
    for c in {m, n} {
      ...
    }
    unlock()
  }
}

// Iterations: m * n * (m+n)
// Locking: m * n
```

To:
```
for mi in m {
  lock()
  for c in {m, n} {
    ...
  }
  unlock()

  for ni in n {
    ...
  }
  for ni in n {
    ...
  }
}

// Iterations: m * (m+n+n+n)
// Locking: m
```

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-21 12:27:46 -04:00
Martin Atkins
6f0d3d3a07 Build with Go 1.24.3.
This minor release includes a security update that does not directly affect
OpenTofu, but we'll adopt the fix for future releases anyway since the
risk seems low and this will likely help quiet false positive reports from
security scanners moving forward.

This also includes various non-security bugfixes which may improve
OpenTofu's reliability.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-19 13:24:46 -07:00
Christian Mesh
566ab35b93 Remove Target Release PR template field (#2821)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-19 10:26:47 -04:00
Christian Mesh
d4ec388980 Bump version for 1.10.0-beta1 (#2822)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
v1.10.0-beta1
2025-05-19 13:45:45 +01:00
Martin Atkins
d1f0999aed command/views/json: Diagnostic context for single-symbol traversals (#2815)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-19 07:25:58 -04:00
Martin Atkins
99a0c6eb6f Automatically translate dependency lock file entries when switching from OpenTofu's predecessor (#2791)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-19 07:25:14 -04:00
Martin Atkins
e4fec9c6ca tfplugin5+tfplugin5: Adopt the latest protocol versions (#2817)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-19 07:00:49 -04:00
Christian Mesh
d130175ed1 Fix iteration issue in transform_destroy (#2809)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-19 07:00:34 -04:00
Martin Atkins
5ad92ad158 go.mod: go get github.com/zclconf/go-cty@v1.16.3 (#2816)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-19 07:00:17 -04:00
Martin Atkins
3be9841232 package main: Prevent disco.Disco generating OTel traces
The disco.Disco API isn't yet set up to pass through context.Context, and
so if we give it a HTTP client that has the OpenTelemetry instrumentation
on it then any HTTP request causes an orphan trace span disconnected from
the main trace, which causes annoying noise in some trace viewers.

As a temporary solution so we can ship v1.10 soon without making large
changes to the svchost library, we'll prevent the HTTP client constructor
function from detecting that tracing is enabled by passing it
context.TODO() instead of the actual context. This would not be acceptable
in the long run but is safe for this temporary workaround because currently
httpclient.New doesn't use the given context for anything except detecting
whether tracing is enabled.

We will address this in a more complete way during the v1.11 development
period by modernizing svchost to take context.Context arguments on all
functions that can potentially make external requests.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-16 09:12:28 -07:00
Patrick Decat
9ac06d3c8b docs: relocate sentence about .terraformignore to proper section (#2812)
Signed-off-by: Patrick Decat <pdecat@gmail.com>
2025-05-16 13:54:30 +03:00
Christian Mesh
6c14802e20 Allow nodeExpandCheck to influence node pruning (#2593)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
2025-05-15 14:12:48 -04:00
Christian Mesh
d513bad8af Better error message when provider config is not found for iteration (#2806)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-15 12:07:30 -04:00
Christian Mesh
aaed9f83e4 Fix linting in internal/command (#2798)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-15 07:39:11 -04:00
Andrei Ciobanu
8396d0459c Add github workflow to run govoulncheck on all branches with supported OpenTofu versions (#2636)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-05-14 18:26:22 +03:00
Andrei Ciobanu
2ef59e2299 Add note about the diff dependency on the fmt command (#2801)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-05-14 15:33:59 +03:00
Christian Mesh
24a13dd090 Fix potential loss of local state (#2799)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-14 06:43:36 -04:00
Martin Atkins
65a0f7a656 registry+getproviders: Registry client policy centralized in main
The primary reason for this change is that registry.NewClient was
originally imposing its own decision about service discovery request
policy on every other user of the shared disco.Disco object by modifying
it directly.

We have been moving towards using a dependency inversion style where
package main is responsible for deciding how everything should be
configured based on global CLI arguments, environment variables, and the
CLI configuration, and so this commit moves to using that model for the
HTTP clients used by the module and provider registry client code.

This also makes explicit what was previously hidden away: that all service
discovery requests are made using the same HTTP client policy as for
requests to module registries, even if the service being discovered is not
a registry. This doesn't seem to have been the intention of the code as
previously written, but was still its ultimate effect: there is only one
disco.Disco object shared across all discovery callers and so changing its
configuration in any way changes it for everyone.

This initial rework is certainly not perfect: these components were not
originally designed to work in this way and there are lots of existing
test cases relying on them working the old way, and so this is a compromise
to get the behavior we now need (using consistent HTTP client settings
across all callers) without disrupting too much existing code.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-12 10:50:17 -07:00
Christian Mesh
3334ed5e1c Fix lint issues in internal/communicator (#2779)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: James Humphries <james@james-humphries.co.uk>
Co-authored-by: James Humphries <james@james-humphries.co.uk>
2025-05-12 13:39:43 -04:00
baa-ableton
85bfb19577 Fix #2584: Accept null value for version if module source is local (#2660)
Signed-off-by: Babur Ayanlar <babur.ayanlar@ableton.com>
Signed-off-by: baa-ableton <110462357+baa-ableton@users.noreply.github.com>
2025-05-12 09:33:53 -04:00
Christian Mesh
00db253a04 Fix lint issues in internal/configs (#2780)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-12 07:38:52 -04:00
Christian Mesh
ff7ba7a95f Fix lint issues in internal/tofu (#2790)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-12 07:28:35 -04:00
Christian Mesh
e84d9e10b7 Fix lint issues in internal/getproviders (#2784)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 14:09:36 -07:00
Christian Mesh
13c1ca768b Fix lint issues in ./internal/encryption (#2782)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 14:06:42 -07:00
Christian Mesh
240e3dc79b Fix lint issues in internal/genconfig (#2783)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 14:00:08 -07:00
Christian Mesh
dafd1798b7 Fix lint issues in internal/providercache (#2788)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:59:39 -07:00
Christian Mesh
8ee707b3e6 Fix lint issues in internal/lang (#2786)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:53:34 -07:00
Christian Mesh
d0756f17ec Fix lint issues in internal/states (#2789)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:48:08 -07:00
Christian Mesh
e4cf5c4c48 Address linting in internal/builtin (#2778)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:47:24 -07:00
Christian Mesh
281526bbca plugin: Remove unused UIOutput (#2787)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:46:19 -07:00
Christian Mesh
9e42d938a6 Fix lint issues in internal/copy (#2781)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 13:45:01 -07:00
Christian Mesh
5fdf66c943 Address linting issues in addrs package (#2777)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 14:50:37 -04:00
Christian Mesh
ae542df787 Tune .golangci.yml and fix small lint
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-09 14:14:53 -04:00
Tyler Auerbeck
c84716d37b Bump version of golangci-lint action as it appears older version may not work with v2
Signed-off-by: Tyler Auerbeck <tylerauerbeck@users.noreply.github.com>
2025-05-09 14:14:53 -04:00
Tyler Auerbeck
59fcdcd2b8 Update makefile, github workflow to use golangci-lint v2
Signed-off-by: Tyler Auerbeck <tylerauerbeck@users.noreply.github.com>
2025-05-09 14:14:53 -04:00
Tyler Auerbeck
ca72604301 Update golangci-lint to v2
Signed-off-by: Tyler Auerbeck <tylerauerbeck@users.noreply.github.com>
2025-05-09 14:14:53 -04:00
Andrei Ciobanu
8305bfb2ef Rename the CLI arg for deprecation outputs/variables (#2774)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-05-09 14:01:32 +03:00
Martin Atkins
47875921a1 httpclient: Add OTel tracing automatically when needed (#2772)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-09 10:16:38 +01:00
Christian Mesh
11694a6ac0 Alternate approach to linking and locking the global cache (#2708)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 15:26:46 -04:00
Martin Atkins
06762cb402 tofu: EvalContext.ProviderSchema takes context.Context
As part of our continuing effort to plumb context.Context everywhere we
might want to generate tracing spans, this is a first tentative step to
retrofitting the EvalContext interface.

This is a _huge_ interface, so a single commit updating all of the methods
would be too much to deal with. Instead, we'll start small and focus only
on the provider schema lookup because at this point that's the one
remaining part of the core language runtime that makes
potentially-expensive external requests but isn't yet able to generate
tracing spans, and so currently the time spent on this gets misattributed
to whichever caller is unfortunate enough to ask for the schema first and
thus becomes responsible for populating the schema cache.

The callers of this method are not yet plumbed for context themselves, so
a subsequent commit will replace these new context.TODO() calls with
something more useful.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 09:56:36 -07:00
Martin Atkins
8d24f68f16 tofu: EvalContext reciever symbol now named "c"
We're moving away from using "ctx" to refer to a variable of any type
other than context.Context, to match with the modern Go idiom. Our current
conventions would normally call for an EvalContext variable to be called
evalCtx, but we also tend not to use such long names for reciever symbols
and instead use a one or two letter initialism from nouns in the type
name, and so in this case we'll adopt just "c" which also happens to match
the naming convention used on the other implementation of this type,
MockEvalContext.

In future commits we'll start adding "ctx context.Context" arguments to
many of the methods of this type, so the motivation here is to just get
these conflicting symbols out of the way in one ugly-but-boring commit
so that this systematic change is separate from any other changes.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 09:56:36 -07:00
Martin Atkins
080805dd5d tofu: Resolve a context.TODO() usages in plan and apply graph construction
Earlier work made GraphBuilder.Build take a context, but we had a missing
link in the context-passing chain due to the plan and apply graph
construction being factored out into a separate unexported function.

This commit just adds the remaining few steps of plumbing so that a useful
upstream context can reach all of the graph builders, so that it'd be
okay for downstream code to generate trace spans in future.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 07:16:09 -07:00
Martin Atkins
75c7834ca6 tofu: GraphTransformer.Transform takes context.Context
Most of our transformers are pure compute and so don't really have a strong
need to generate trace spans under our current focus of only exposing
user-facing concepts and external requests in our traces, but unfortunately
some of them indirectly depend on provider schema, which in turn means that
they can potentially be unlucky enough to be the trigger for making all
of the provider requests needed to fill the schema cache and therefore
would end up with provider request spans being reported beneath them.

As usual with these interface updates, this initial change focuses only
on changing the interface and updating its direct callers and implementers
to match, without any further refactoring or attempts to plumb contexts
to or from other functions that don't have them yet. That means there are
a few new context.TODO() calls here that we'll tidy up in a later commit
that hopefully won't involve all of the noise that is caused by changing
an interface API.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 07:16:09 -07:00
Martin Atkins
3baaaf8929 tofu: Remove unused VertexTransformer
This, along with its supporting interface GraphVertexTransformer, were not
used by any code except their own tests, but we hadn't previously noticed
that because (like many symbols in this package, unfortunately) they had
exported names despite being implementation details.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 07:16:09 -07:00
Martin Atkins
8202ceec49 tofu: Internal schema lookup functions require context.Context
In preparation for propagating cross-cutting concerns like tracing spans
to the plugin calls we make to load schemas, this adds context.Context
parameters to the schema lookup functions.

Unfortunately we call these from many different locations inside the
package today, and not all of them yet have a suitable parent context to
pass in, and so those locations currently use context.TODO() placeholders
to make it easier for us to track those down and improve them in subsequent
commits.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 07:13:19 -07:00
Martin Atkins
b035145456 core: tofu.Context.Schemas takes a context.Context
As part of our ongoing work to plumb cross-cutting concerns like tracing
spans into the core language runtime, here we change the exported API
of the context.Schemas method to take a context.Context, and trivially
update all of the callers to pass in a suitable context.

Earlier work on this means that we don't have fix up too many call stack
levels before we already have a suitable context.Context value to use.

The Schemas method doesn't yet make any use of its new context.Context, but
that will follow in subsequent PRs.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 07:13:19 -07:00
Andrei Ciobanu
22dc9b2137 Add new CLI arg to control what warnings should be shown for deprecated outputs/variables (#2705)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-05-08 17:01:40 +03:00