Commit Graph

116 Commits

Author SHA1 Message Date
RLRabinowitz
26fb627af9
Remove all Terraform mentions in STDOUTs in the codebase (#704) 2023-10-12 14:24:04 +01:00
RLRabinowitz
8967cdcee7
Remove all Terraform Cloud mentions in STDOUTs in the codebase (#703) 2023-10-12 12:07:16 +01: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
Dmitry Kisler
a127607a85
Rename terraform to tofu in GoString method and docstrings (#576)
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
2023-09-26 19:09:27 +02:00
Lars Lehtonen
7b799c9305
internal/configs/configload: prune copyDir() (#581) 2023-09-26 14:39:56 +03:00
Yaron Yarimi
90f7e5275f
Rename multiple packages to OpenTofu (depsfile, genconfig, getmodules) (#499) 2023-09-20 17:05:24 +03:00
Yaron Yarimi
c6aeb9e836
Rename legacy package to OpenTofu (#493) 2023-09-20 16:10:32 +03:00
Yaron Yarimi
c8acedd885
Rename github.com/placeholderplaceholderplaceholder/opentf to github.com/opentofu/opentofu (#461) 2023-09-20 14:35:35 +03:00
Lars Lehtonen
b65a5fd7a8
Multi Package Wrap Errors (#414) 2023-09-18 15:53:49 +03:00
Lars Lehtonen
ebe331fdd3
internal/configs: deprecate io/ioutil (#333)
Signed-off-by: Lars Lehtonen <lars.lehtonen@gmail.com>
2023-09-08 01:12:25 +02:00
RLRabinowitz
19239936a4 Rename internal/legacy/terraform to internal/legacy/opentf 2023-08-27 15:58:38 +03:00
Elbaz
2729114bec missed some 2023-08-23 11:41:04 +03:00
Elbaz
6000fe690e fix warning checks 2023-08-22 15:47:37 +03:00
Elbaz
75ff795326 more naming updates 2023-08-22 15:43:11 +03:00
Elbaz
60770c81a2 update namings 2023-08-22 15:33:08 +03:00
Kuba Martin
ebcf7455eb
Rename root module name. (#4)
* Rename module name from "github.com/hashicorp/terraform" to "github.com/placeholderplaceholderplaceholder/opentf".

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Gofmt.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Regenerate protobuf.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Fix comments.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo issue and pull request link changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo comment changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Fix comment.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo some link changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* make generate && make protobuf

Signed-off-by: Jakub Martin <kubam@spacelift.io>

---------

Signed-off-by: Jakub Martin <kubam@spacelift.io>
2023-08-17 14:45:11 +02:00
kmoe
765c25d2ed
allow interpolation in import block id (#33618)
The import block id field can now reference variables, attributes, and module outputs, as long as the result is a known non-empty string at plan time. A null or unknown value will result in an error.

This commit slightly modifies the legacy CLI terraform import code path to construct a synthetic hcl.Expression from the import id passed in from the command line, with no intended change of functionality.
2023-08-02 10:20:27 +01: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
e1019b3641
testing framework: validate the configuration before terraform test (#33559)
* testing framework: call validate on the configuration before running terraform test

* address comments

* make tests pass after merge

* fix tests
2023-07-26 10:56:44 +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
212ae6c4ba
Introduce separate testing scope for reference validation (#33339) 2023-06-28 09:47:24 +02:00
kmoe
fbff64ad45
configs: remove import block duplicate id check (#33434) 2023-06-27 19:25:36 +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
Martin Atkins
9f6a3ba701 build: Generate copyright headers automatically
HashiCorp legal now requires a copyright claim in a comment at the top of
every substantial file in this repository. If we don't add this ourselves
then a bot will open a PR to add missing entries, but that process adds
git history, pull request, and GitHub notification noise so instead we'll
deal with it proactively as part of our usual code generation steps.

This means that pull requests will fail their checks if there are any
files that lack copyright headers, so we can deal with those before we
merge rather than in a subsequent PR.
2023-05-30 08:21:40 -07:00
kmoe
be2ad69eda
plannable import: safer config generation and schema filters (#33232)
* genconfig: fix nil nested block panic

* genconfig: null NestingSingle blocks should be absent

A NestingSingle block that is null in state should be completely absent from config.

* configschema: make FilterOr variadic

* configschema: apply filters to nested types

* configschema: filter helper/schema id attribute

The legacy SDK adds an Optional+Computed "id" attribute to the
resource schema even if not defined in provider code.
During validation, however, the presence of an extraneous "id"
attribute in config will cause an error.
Remove this attribute so we do not generate an "id" attribute
where there is a risk that it is not in the real resource schema.

* configschema: filter test

* terraform: do not pre-validate generated config

Config generated from a resource's import state may fail validation in
the case of schema behaviours such as ExactlyOneOf and ConflictsWith.
We don't want to fail the plan now, because that would give the user no
way to proceed and fix the config to make it valid. We allow the plan to
complete and output the generated config.

* generate config alongside import process

Rather than waiting until we call `plan()`, generate the configuration
at the point of the import call, so we have the necessary data to return
in case planning fails later.

The `plan` and `state` predeclared variables in the plan() method were
obfuscating the actual return of nil throughout, so those identifiers
were removed for clarity.

* move generateHCLStringAttributes closer to caller

* store generated config in plan on error

* test for config gen with error

* add simple warning when generating config

---------

Co-authored-by: James Bardin <j.bardin@gmail.com>
2023-05-24 11:16:05 +01:00
Masayuki Morita
53755180fd
Fix an error message for import block with moved block (#33221)
Fixes #33220
2023-05-19 13:47:46 -07: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
CJ Horton
bd6ba6cf99
check for duplicate import blocks (#33190)
Importing to the same target address twice or importing the same ID
to multiple different resources of the same type is not allowed.
2023-05-12 23:14:44 +01: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
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
kmoe
c6400fabb1
configs: add import block (#33081) 2023-04-26 16:28:11 +01:00
kmoe
531efd303b
add types for plannable import (#33080) 2023-04-25 15:19:48 +01:00
Liam Cervante
3827120c25
Checks: Add configuration for check blocks (#32734)
* Add support for scoped resources

* refactor existing checks addrs and add check block addr

* Add configuration for check blocks

* address comments
2023-03-23 09:12:53 +01:00
Liam Cervante
af05cbb645
Add support for scoped resources (#32732) 2023-03-10 11:11:10 +01:00
Eugene Dementyev
36aac6b498
Fixes depends_on when overriding modules (#32796)
Fixes #32795
2023-03-09 11:53:13 +01:00
Alisdair McDiarmid
8df065a2fe initwd: Switch from earlyconfig to configs
This is a mostly mechanical refactor with a handful of changes which
are necessary due to the semantic difference between earlyconfig and
configs.

When parsing root and descendant modules in the module installer, we now
check the core version requirements inline. If the Terraform version is
incompatible, we drop any other module loader diagnostics. This ensures
that future language additions don't clutter the output and confuse the
user.

We also add two new checks during the module load process:

* Don't try to load a module with a `nil` source address. This is a
  necessary change due to the move away from earlyconfig.

* Don't try to load a module with a blank name (i.e. `module ""`).
  Because our module loading manifest uses the stringified module path
  as its map key, this causes a collision with the root module, and a
  later panic. This is the bug which triggered this refactor in the
  first place.
2023-03-06 09:14:28 -05:00
Nick Fagerlund
83428c91f1 Fix accidental mutation of shared cty.Paths in ValueMarks funcs
Go's `append()` reserves the right to mutate its primary argument in-place, and
expects the caller to assign its return value to the same variable that was
passed as the primary argument. Due to what was almost definitely a typo
(followed by copy-paste mishap), the configschema `Block.ValueMarks` and
`Object.ValueMarks` functions were treating it like an immutable function that
returns a new slice.

In rare and hard-to-reproduce cases, this was causing bizarre malfunctions when
marking sensitive schema attributes in deeply-nested block structures --
omitting the marks for some sensitive values (🚨), and marking other entire
blocks as sensitive (which is supposed to be impossible). The chaotic and
unreliable nature of the bugs is likely related to `append()`'s automatic slice
reallocation behavior (if the append operation overflows the original array
allocation, the resulting behavior can _look_ immutable), but there might be
other contributing factors too.

This commit fixes existing instances of the problem, and wraps the desired
copy-and-append behavior in a helper function to simplify handling shared parent
paths in an immutable way.
2023-01-19 12:39:19 -08:00
Alisdair McDiarmid
551f6316fa Do not apply type defaults to null values
Applying object type defaults to null values can convert null to an
object with partial attributes. This means that even a specified default
value of null will not remain null after variable evaluation.

In turn, the result can then be invalid, if not all attributes in an
object type have defaults specified.

This commit skips the type default application step during config load
and variable evaluation if the default or given value is null of any
type. We still perform type conversion.
2022-09-15 15:32:36 -04:00
Alisdair McDiarmid
9d864c2430 Use upstreamed HCL typexpr package
The 2.14.0 release of HCL includes the typeexpr changes we tested here,
so now we can revert to using the HCL package and remove our fork.
2022-09-01 16:03:48 -04:00
Martin Atkins
209b8de7a5 configs: Variable and Output both have Addr methods
We previously added methods like this for some of the other types in this
package, including Local in this same file, but apparently haven't needed
these two yet.
2022-08-26 15:47:29 -07:00
Martin Atkins
783a07d9e8 build: Use Go 1.19
Go 1.19's "fmt" has some awareness of the new doc comment formatting
conventions and adjusts the presentation of the source comments to make
it clearer how godoc would interpret them. Therefore this commit includes
various updates made by "go fmt" to acheve that.

In line with our usual convention that we make stylistic/grammar/spelling
tweaks typically only when we're "in the area" changing something else
anyway, I also took this opportunity to review most of the comments that
this updated to see if there were any other opportunities to improve them.
2022-08-22 10:59:12 -07:00
James Bardin
8354bc46cf
Merge pull request #31576 from hashicorp/jbardin/validate-deprecated-computed
validate deprecated attributes from static traversals
2022-08-09 11:10:13 -04:00