Commit Graph

78 Commits

Author SHA1 Message Date
Diógenes Fernandes
0a631be1d6 Provider validation for enabled at module calls (#3680)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2026-01-20 13:06:22 -03:00
Martin Atkins
d8b057b064 configs: Skip provider ref validation when modules fail to load
We previously already did some partial skipping of provider reference
validation when there are modules in the tree that failed to load, but we
were still running the main logic that checks whether the providers passed
between module boundaries are consistent.

Because that validation involves checking consistency between different
modules it will tend to generate spurious errors when run against a
partially-loaded module tree. Therefore we must also skip the other
validation steps whenever at least one module failed to load, so that the
reported diagnostics will only describe the problem loading the module and
not produce additional misleading reports describing downstream problems
caused by a module's content being incomplete due to those errors.

This one is kinda awkward to write a test for because it's a very specific
interaction that seems unlikely to arise again, but just to have _some_
representation of this historical problem I wrote a simple test that
intentionally makes one module fail to load and then tests that the result
only contains the diagnostic related to that intentional failure. Before
this fix that test would fail because of the spurious additional errors
produced by the functions we're now skipping.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2026-01-16 07:43:32 -08:00
Diogenes Fernandes
b2b6e84940 Meta-arguments validation source snippet
Previously, the source snippet was only showing the last defined
meta-argument. To have a better context of which meta-arguments
are being used, we start to show from the first one defined
until the last one.

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Martin Atkins
0fb0a4b707 lint: DiscardedObjectConstructorAttrs
This generalizes the previously-added lint-like check for when an object
constructor is used to define an input variable and it contains a
definition for an attribute that isn't part of the target type, so that
now it also works for various nested structures that commonly arise in
real-world configurations.

Because this is now considerably more complicated I factored it out into
a new package called "lint" which could potentially grow to include other
similar "technically valid but probably a mistake" situations in future,
but for now it just introduced an opportunity to produce similar warning
messages for ignored attribute definitions in the default value for an
input variable.

It seems to me that there is actually no useful reason to include an
unexpected attribute definition in either of these two cases: that
attribute will never appear as part of any expression that any other part
of the configuration can use. Therefore I considered making these be
treated as errors rather than warnings, but turning something that was
previously valid into an error is risky so I'm suggesting that we start
with these as warnings and then consider upgrading them to errors in a
later release if we don't hear of anyone reporting a false-positive that
was _somehow_ actually useful. (I find that very unlikely, but still...)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-26 09:08:31 -07:00
Diogenes Fernandes
1c90ca87f8 Implement validation on ephemeral and data resources (#3042)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
0eb18fb49c Add conditional enabled field on managed and data resources (#3042)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diógenes Fernandes
167fd0d263 fix internal/configs/ on Windows (#3276)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 16:14:31 -03: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
Andrei Ciobanu
4077c3d84f Feature branch: Ephemeral resources (#2852)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-08-04 16:39:12 +03:00
Yoshitaka Fujii
b6b1573482 fix: Support provider references with index expressions in .tf.json (#3022)
Signed-off-by: ystkfujii <ystk.fujii0731@gmail.com>
2025-07-17 12:03:28 -03: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
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
Andrei Ciobanu
3c51831e5c Enhance removed block with lifecycle and provisioner functionalities (#2628)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-04-25 06:29:42 -04:00
Oleksandr Levchenkov
2bcd0e7d57 add deprecation marks for module outputs (#2633)
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-24 11:16:06 -04:00
Andrei Ciobanu
8a55dc29da fix small pr suggestions
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-04-24 11:07:35 -04:00
yottta
00ad53b1d5 Add variable deprecation impl
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
2025-04-24 11:07:35 -04:00
Andrei Ciobanu
ab9a7f4d72 Fix error message when default value of variable is of wrong type (#2444)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
2025-01-29 10:50:45 +02:00
Andrei Ciobanu
089687061b Fix: When a RequiredProvider is having syntax errors, return an empty one to allow further validations to generate their diags (#2408)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Co-authored-by: yottta <andpectech@gmail.com>
2025-01-28 15:47:17 +02:00
Christian Mesh
de5f273390 Use import provider instead of guess (#2336)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-01-24 17:18:08 -05:00
Marcin Wyszynski
f83849e95a Catch invalid name in provider_meta before it causes a crash (#2347)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2025-01-09 14:36:56 +00: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
Christian Mesh
8fb8f066c4 Detect when provider and resource/module have identical for_each (#2186)
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>
2024-12-03 14:02:27 -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
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
Christian Mesh
0d1e6cd5f0 Handle static variable secret flag (#2045)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-10-03 10:46:58 -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
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
Ronny Orot
ab289fc07c OpenTofu Specific Code Override: Add support to .tofu files (#1738)
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
2024-06-24 16:10:35 +03:00
Siddhartha Sonker
de30707b6b Fix for tofu init failure when test have spaces in their name (#1489)
Signed-off-by: siddharthasonker95 <158144589+siddharthasonker95@users.noreply.github.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-04-25 11:11:38 -04:00
Arel Rabinowitz
63c88507a8 Make import block's to possibly more dynamic (#1270)
Signed-off-by: RLRabinowitz <rlrabinowitz2@gmail.com>
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
Co-authored-by: Ronny Orot <ronny.orot@gmail.com>
2024-04-15 13:06:35 +03:00
Syasusu
e25c06c673 Fix: improve unit test coverage for ProvisionerBlock decode (#1324)
Signed-off-by: Syasusu <syasusu@163.com>
2024-03-13 13:45:45 -04:00
Ronny Orot
e9fe0f1118 Add support for removed block (#1158)
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
2024-02-21 10:31:44 +02: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
RLRabinowitz
e0ecd2ebb3 Use registry.opentofu.org as the default registry (#379)
Signed-off-by: RLRabinowitz <rlrabinowitz2@gmail.com>
2023-10-03 10:49:38 +03:00
Yaron Yarimi
90f7e5275f Rename multiple packages to OpenTofu (depsfile, genconfig, getmodules) (#499) 2023-09-20 17:05:24 +03:00
Elbaz
6000fe690e fix warning checks 2023-08-22 15:47:37 +03:00
Liam Cervante
f397954c52 testing framework: allow users to specify deeply nested testing directories (#33584) 2023-07-27 10:38:21 +02:00
Liam Cervante
4122ba86fc terraform test: fix crash when using nested modules from test run blocks (#33589) 2023-07-27 10:22:53 +02:00
Liam Cervante
222676390c testing framework: add validation for provider blocks in test files (#33542)
* testing framework: add validation for provider blocks in test files

* .tftest -> .tftest.hcl
2023-07-26 10:01:18 +02:00
Liam Cervante
c91f91cc9e testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
Liam Cervante
4b34902fab [testing framework] allow tests to define and override providers (#33466)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks

* [testing framework] allow tests to define and override providers
2023-07-10 14:33:15 +01:00
Liam Cervante
5acc95dda7 [Testing Framework] Add module block to test run blocks (#33456)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks
2023-07-10 11:42:05 +01:00
Liam Cervante
f74a8d16cf [testing framework] implement expect_failures functionality (#33443) 2023-07-10 11:30:44 +01:00
Liam Cervante
cad9aa9025 [Testing Framework] Add test file HCL configuration and parser functionality (#33325)
* Add test structure to views package for rendering test output

* Add test file HCL configuration and parser functionality

* address comments
2023-06-22 17:03:37 +02:00
CJ Horton
adcecddb4f Merge pull request #33193 from hashicorp/radditude/no-import-blocks-in-child-modules
plannable import: disallow import blocks in child modules
2023-05-12 16:44:12 -07:00
kmoe
1172d40d7b error if import target is move source (#33192)
It is invalid for any import block to have a "to" argument matching any moved block's "from" argument.
2023-05-13 00:30:15 +01:00
CJ Horton
2dd89d9776 import blocks are only allowed in the root module 2023-05-12 16:04:47 -07:00
Liam Cervante
5d6c5a9a33 plannable import: add a provider argument to the import block (#33175)
* command: keep our promises

* remove some nil config checks

Remove some of the safety checks that ensure plan nodes have config attached at the appropriate time.

* add GeneratedConfig to plan changes objects

Add a new GeneratedConfig field alongside Importing in plan changes.

* add config generation package

The genconfig package implements HCL config generation from provider state values.

Thanks to @mildwonkey whose implementation of terraform add is the basis for this package.

* generate config during plan

If a resource is being imported and does not already have config, attempt to generate that config during planning. The config is generated from the state as an HCL string, and then parsed back into an hcl.Body to attach to the plan graph node.

The generated config string is attached to the change emitted by the plan.

* complete config generation prototype, and add tests

* plannable import: add a provider argument to the import block

* Update internal/configs/config.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/configs/config.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/configs/config.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* fix formatting and tests

---------

Co-authored-by: Katy Moe <katy@katy.moe>
Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-05-11 09:04:39 +02:00
Liam Cervante
79f7f59155 Plannable import: Generate config for imported resources during the plan. (#33153)
* command: keep our promises

* remove some nil config checks

Remove some of the safety checks that ensure plan nodes have config attached at the appropriate time.

* add GeneratedConfig to plan changes objects

Add a new GeneratedConfig field alongside Importing in plan changes.

* add config generation package

The genconfig package implements HCL config generation from provider state values.

Thanks to @mildwonkey whose implementation of terraform add is the basis for this package.

* generate config during plan

If a resource is being imported and does not already have config, attempt to generate that config during planning. The config is generated from the state as an HCL string, and then parsed back into an hcl.Body to attach to the plan graph node.

The generated config string is attached to the change emitted by the plan.

* complete config generation prototype, and add tests

---------

Co-authored-by: Katy Moe <katy@katy.moe>
2023-05-11 08:38:37 +02:00