Commit Graph

98 Commits

Author SHA1 Message Date
Jarrett Duskey
ecd4dc5c61
Add count of forgotten resources to plan and apply outputs. (#2010)
Signed-off-by: Jarrett Duskey <jarrett@duskey.io>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-02-24 14:53:32 -05:00
Martin Atkins
9a86d86f4d tofu: Some benchmarks for situations with many instances
Although we don't promise that OpenTofu will work well with more than a
few hundred resource instances in a particular configuration, we know that
some people do use it that way and they sometimes find and share
opportunities for improving performance due to those opportunities being
easier to spot at large scale.

These two benchmarks aim to help us measure improvements that affect the
pure overhead of the core language runtime, without any real provider calls
and without the CLI layer's contributions, so that we can more easily
compare before and after of changes when we're either trying to understand
a reported performance regression or we're trying out potential performance
improvements.

As noted in the comments inline, the presence of these benchmarks is not
intended to represent a commitment to support using OpenTofu outside of its
design assumptions, but they will hopefully help us continue our current
best-effort approach to reducing overhead where we can do so without risk
to existing functionality, increasing maintenance overhead, or making it
harder to introduce new features over time.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-02-19 08:15:29 -08:00
Martin Atkins
30fcff72d8 tofu+configload: Test utilities take testing.TB
A lot of our testing utilities were written before the introduction of the
testing.TB interface that represents what *testing.T and *testing.B have
in common, and those that weren't have followed precedent from those that
were in directly expecting *testing.T.

Using testing.TB instead makes these helpers usable from both normal tests
and testing benchmark functions, since they only use methods that are
available in both contexts.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-02-19 08:15:29 -08:00
Andrei Ciobanu
dfe2876931
Add a new warning when a provider cannot be downloaded and it was requested by an implicit usage (#2479)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Co-authored-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-02-12 18:40:54 +02:00
Oleksandr Levchenkov
5ff40ae505
refactor sensitive marks usage (#2503)
Signed-off-by: ollevche <ollevche@gmail.com>
2025-02-11 19:02:21 +02:00
Ilia Gogotchuri
5968e195b0
Moved for different types (#2370)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-02-05 15:14:19 +04:00
Andrei Ciobanu
8fe739dc83
MakeStaticTimestampFunc now returns unknown value if the given time.Time is zero (#2413)
Signed-off-by: yottta <andpectech@gmail.com>
Co-authored-by: yottta <andpectech@gmail.com>
2025-01-27 17:07:40 +02:00
Oleksandr Levchenkov
76d388b340
fix: provider not initialized in some cases (mostly, deposed) (#2335)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-08 12:34:52 -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
3dbf8aae7b tofu: eval_iteration.go is now eval_expansion.go
Using the word "iteration" to describe what count and for_each do tends to
confuse people because it sounds like explicit control flow rather than
just dynamically declaring multiple objects.

Elsewhere in the codebase we refer to this idea as "expansion" so this is
a rename for consistency with that and to remove the confusing terminology.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-02 13:24:11 -08:00
Martin Atkins
f1358f9fe8 evalchecks: Suggest -exclude as a workaround for unknown count/for_each
Previously we made a very generic suggestion to use -target to split a
change into two parts as a workaround for the fact that count and for_each
must be known during planning. That works, but we didn't have enough
information available to tell the operator exactly what to target and so
anyone who is not an expert on the configuration they're working with tends
to get stuck unable to figure out exactly what they need to do.

The new -exclude option gives us an opportunity to do better here: we tend
to know for which object we're currently evaluating count or for_each, and
so we can mention that object directly in the error message when if we
recommend to use -exclude instead of -target.

Not all objects that support count/for_each will necessarily be directly
targetable, so we can still potentially recommend -target when we're
dealing with one of those objects. For example, as of this commit that
is true for for_each in a provider block, because there is not currently
any syntax for specifying a provider configuration as an addrs.Targetable.
Perhaps we'll introduce such a thing in the future, but that's outside the
scope of this change that's primarily focused on improving the messaging
for resource and module count/for_each.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-02 13:24:11 -08:00
Oleksandr Levchenkov
c5b43b9f1a
fix: unused config's create_before_destroy on resource change with no refresh (#2248)
Signed-off-by: ollevche <ollevche@gmail.com>
2024-12-20 10:47:00 +02:00
Martin Atkins
27ab52fd03
Compare ModuleInstance to Module without allocating, and similar (#2261)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2024-12-12 12:47:57 -05:00
Christian Mesh
6c74923f22
Local values can now be used in provider key expressions (#2280)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-12-11 07:46:40 -05:00
Christian Mesh
ece1bb4f49
Fix data provider iteration destroy (#2270)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-12-09 07:56:58 -05:00
Christian Mesh
f6a1d8e2dd
Support References in Variable Validation (#2216)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-12-04 14:24:44 -05:00
Martin Atkins
91b43aecd1
tofu: Variable validation diagnostics must mark sensitive values (#2233)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2024-12-03 12:40:44 -05:00
Oleksandr Levchenkov
6c8bfa2794
implement override resources for mock providers (#2168)
Signed-off-by: ollevche <ollevche@gmail.com>
2024-12-03 11:24:26 -05:00
Christian Mesh
0903aeff58
Split variable evaluation / validation scope (#2199)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-12-02 09:18:07 -05:00
Ronny Orot
cf34b0e6a9
Skip imports on tofu destroy (#2214)
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
2024-11-25 23:52:03 +02:00
Oleksandr Levchenkov
2758f2cfbf
fix mock provider validation (#2140)
Signed-off-by: ollevche <ollevche@gmail.com>
2024-11-20 16:45:17 +02:00
Martin Atkins
2448204201 tofu: context.Context plumbed into the graph walk driver
Earlier commits arranged for each of our tofu.Context exported methods that
perform graph-based operations to take a context.Context from their
callers, and for the main callers in package command and package backend
to connect those contexts to the top-level context from "package main"
that can potentially have an OpenTelemetry span attached to it.

This propagates those contexts a little deeper into the guts of the
language runtime, getting it as far as the shared logic that drives a
graph walk.

The next step from here would be to change the interfaces
GraphNodeExecutable and GraphNodeDynamicExpandable so that their methods
both take a context.Context, but that would involve a big sprawling
update to every implementation of each of those interfaces and so
we'll save that for a later commit to keep this one relatively clean.

This commit also reaches the first point of ambiguity where our older
conventions call for "ctx" to be the variable name for a tofu.EvalContext
rather than a context.Context. Since "ctx context.Context" is a core idiom
in the Go community, we'll switch to using evalCtx as the variable name
for tofu.EvalContext both here and in our future commits that will
modify the two main graph walk interfaces that make extensive use of the
tofu.EvalContext interface.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2024-11-19 10:15:21 -08:00
Martin Atkins
a8b6342556 tofu: Context.Input 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.Input now passes this through to the UI input implementation,
which was already written to handle cancellation. However, that
implementation currently handles interruption itself by directly watching
for the interrupt signal and so we remove the cancellation from the
context for now to avoid changing how interrupts are handled. Hopefully
in future we can remove the inline SIGINT handling from the UIInput
implementation and use its context-cancellation-handling instead.

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
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
Martin Atkins
6522f73249 tofu: Context.Eval 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.Eval doesn't yet do anything with its new context, but we'll
plumb this deeper in future.

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
Martin Atkins
8ae790ca06 tofu: Context.Import 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.Import doesn't yet do anything with its new context, but we'll
plumb this deeper in future.

OpenTofu has some historical situational private uses of context.Context
to handle the graceful shutdown behaviors. Those use context.Context as
a private implementation detail rather than public API, and so this commit
leaves them as-is and adds a new "primary context" alongside. Hopefully
in future refactoring we can simplify this to use the primary context also
as the primary cancellation signal, but that's too risky a change to bundle
in with this otherwise-mostly-harmless context plumbing.

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
Martin Atkins
3b79efa834 tofu: Context.Refresh 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.Refresh is really just a vestigal wrapper around Context.Plan, so
this just passes the given context through to Context.Plan which itself
currently ignores it.

OpenTofu has some historical situational private uses of context.Context
to handle the graceful shutdown behaviors. Those use context.Context as
a private implementation detail rather than public API, and so this commit
leaves them as-is and adds a new "primary context" alongside. Hopefully
in future refactoring we can simplify this to use the primary context also
as the primary cancellation signal, but that's too risky a change to bundle
in with this otherwise-mostly-harmless context plumbing.

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
Martin Atkins
1134f19467 tofu: Context.Apply 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.Apply does not yet do anything with its new context, but this gets
the context plumbed in enough that we should be able to pass values like
telemetry spans all the way from the top-level in future.

OpenTofu has some historical situational private uses of context.Context
to handle the graceful shutdown behaviors. Those use context.Context as
a private implementation detail rather than public API, and so this commit
leaves them as-is and adds a new "primary context" alongside. Hopefully
in future refactoring we can simplify this to use the primary context also
as the primary cancellation signal, but that's too risky a change to bundle
in with this otherwise-mostly-harmless context plumbing.

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
Martin Atkins
3d5039f1f3 tofu: Context.Plan 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.Plan does not yet do anything with its new context, but this gets
the context plumbed in enough that we should be able to pass values like
telemetry spans all the way from the top-level in future.

OpenTofu has some historical situational private uses of context.Context
to handle the graceful shutdown behaviors. Those use context.Context as
a private implementation detail rather than public API, and so this commit
leaves them as-is and adds a new "primary context" alongside. Hopefully
in future refactoring we can simplify this to use the primary context also
as the primary cancellation signal, but that's too risky a change to bundle
in with this otherwise-mostly-harmless context plumbing.

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
Oleksandr Levchenkov
52cc91c87a
upgrade golangci-lint to v1.62 (#2174)
Signed-off-by: ollevche <ollevche@gmail.com>
2024-11-18 19:56:29 +02:00
Christian Mesh
c57e634bc4
Fix destroy/orphan path with provider instances (#2150)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-11-07 12:41:13 -05:00
Christian Mesh
30b5088da4
Improve log messages for providers with keys (#2152)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-11-07 11:56:21 -05:00
Christian Mesh
fd775f0fe3
Implement Provider for_each (#2105)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: ollevche <ollevche@gmail.com>
Co-authored-by: Ronny Orot <ronny.orot@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2024-11-05 18:08:23 -05:00
Arel Rabinowitz
3d4bf29c56
Add exclude flag support (#1900)
Signed-off-by: RLRabinowitz <rlrabinowitz2@gmail.com>
2024-11-05 10:16:00 -05:00
Christian Mesh
e802b23200
Partial revert of #1911, support provider for_each in aliases (#2121)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-11-05 06:19:52 -05:00
jinjiadu
384dc4cb93
chore: fix some function names (#2108)
Signed-off-by: jinjiadu <jinjiadu@aliyun.com>
2024-10-29 12:07:10 +02:00
Christian Mesh
e3a6bcab96
Fix provider functions in child modules (#2082)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-10-23 10:42:38 -04:00
Christian Mesh
7cacb9f066
Fix function refs in variable validation (#2052)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-10-17 12:37:54 -04:00
Christian Mesh
d36220e44c
Cleanup and encode existing "bugs" in ProviderTransformer (#2069)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-10-16 08:44:40 -04:00
Nathan Baulch
9b7bec31b4
Another batch of minor typos (#1953)
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
2024-09-09 07:51:39 -04:00
Andy Hayes
389f33fdc5
300/provider foreach (#1911)
Signed-off-by: Andrew Hayes <andrew.hayes@harness.io>
2024-09-06 14:33:05 +01: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
Syasusu
1c0cb13bf7
feat: Add support for tofu.workspace which will be resolved in the same way as terraform.workspace (#1305)
Signed-off-by: Syasusu <syasusu@163.com>
2024-08-01 08:14:34 -04:00
Jon Johnson
8f001311ad
Improve ModuleExpansionTransformer performance (#1809)
Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
2024-07-29 15:55:37 -04:00
Ronny Orot
884410e63a
Add more tests and refactor import for_each (#1645)
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
2024-07-26 11:01:47 -04:00
Jon Johnson
a003782fec
Assert that NodeRootVariable implements Execute (#1857)
Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
2024-07-26 07:32:33 -04:00
Jon Johnson
7d94797219
Only call StringWithNodeTypes for TRACE logs (#1810)
Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
2024-07-24 13:44:20 -04: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
James Humphries
12d9380982
Improve comparison of sensitive marks on resources, and propagate the sensitive_attributes correctly (#1640)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2024-07-09 08:42:02 -04:00