Commit Graph

114 Commits

Author SHA1 Message Date
Christian Mesh
2f5dcd5c0a
Integrate Encryption into State Backends (#1288)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-04 09:25:14 -05:00
Christian Mesh
ac3ed86617
Integrate encryption into plan serialization (#1292)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-04 09:00:29 -05: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
namgyalangmo
cb2e9119aa
Update copyright notice (#1232)
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
2024-02-08 09:48:59 +00: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
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
Ikko Eltociear Ashimine
c15ae78b30
Fix typo in dynamic_value.go (#541) 2023-09-26 14:40:33 +03:00
Yaron Yarimi
059190f273
Rename multiple packages to OpenTofu (#488) 2023-09-20 15:59:27 +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
Jasdeep Singh
a5a8fbe62f
internal/plans: deprecate io/ioutil (#348)
Signed-off-by: jay-dee7 <me@jsdp.dev>
2023-09-08 12:06:18 +02:00
RLRabinowitz
27e5417752 Adjust mentions of terraform in internal/plans 2023-08-23 12:34:03 +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
Nick Fagerlund
f98f920b67 Add error wrapper types to highlight bad plan/state data
This commit uses Go's error wrapping features to transparently add some optional
info to certain planfile/state read errors. Specifically, we wrap errors when we
think we've identified the file type but are somehow unable to use it.

Callers that aren't interested in what we think about our input can just ignore
the wrapping; callers that ARE interested can use `errors.As()`.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
0df3c143bb New plans.Quality type for display-relevant facts about a plan
This commit replaces the existing jsonformat.PlanRendererOpt type with a new
type with identical semantics, located in the plans package.

We needed to be able to exchange the facts represented by
`jsonformat.PlanRendererOpt` across some package boundaries, but the jsonformat
package is implicated in too many dependency chains to be safe for that purpose!
So, we had to make a new one. The plans package seems safe to import from all
the places that must emit or accept this info, and already contains plans.Mode,
which is effectively a sibling of this type.
2023-07-24 14:12:44 -04:00
Nick Fagerlund
f9d937a4dd Apply a confirmable run when given a saved cloud plan (#33270)
It displays a run header with link to web UI, like starting a new plan does, then confirms the run
and streams the apply logs. If you can't apply the run (it's from a different workspace, is in an
unconfirmable state, etc. etc.), it displays an error instead.

Notable points along the way:

* Implement `WrappedPlanFile` sum type, and update planfile consumers to use it instead of a plain `planfile.Reader`.

* Enable applying a saved cloud plan

* Update TFC mocks — add org name to workspace, and minimal support for includes on MockRuns.ReadWithOptions.
2023-07-24 14:12:40 -04:00
Martin Atkins
a7807dac16 main: Optionally configure an OpenTelemetry OTLP exporter
Terraform CLI is sometimes used as part of a larger distributed system, in
which case it would be helpful to be able to gather telemetry from it
as part of the larger request it's being run in response to.

We'll now support optionally enabling an OTLP exporter by setting the
environment variable OTEL_TRACES_EXPORTER=otlp (a standard OpenTelemetry
convention). As of this commit there isn't actually anything emitting
traces to the specified collector, but we'll gradually add tracing
instrumentation to parts of Terraform CLI and Core in later commits.
2023-07-14 10:24:10 -07:00
Liam Cervante
c9bc7e8479
Add input validation into the 'checks' outputs and tracking (#33481) 2023-07-10 11:33:45 +01:00
Liam Cervante
3732bffe13
[Testing Framework] Adds TestContext for evaluating test assertions (#33326)
* Add test structure to views package for rendering test output

* Add test file HCL configuration and parser functionality

* Adds a TestContext structure for evaluating assertions against the state and plan
2023-06-26 17:42:53 +02:00
Martin Atkins
d49e991c3c plans/objchange: Support nested unknowns in our unrefinedValue shim
Several parts of the objchange logic incorrectly use cty.Value.RawEquals
for value comparison, instead of more appropriate comparison methods like
cty.Value.Equals or c.Value.Range().Includes. That makes them incorrectly
consider two unknown values with the same type but different refinements
as always non-equal, rather than evaluating based on the overlap between
the refinements (if any).

As a short-term fix for that we previously added this unrefinedValue shim
that just strips away the refinements for comparison, thus allowing
callers to continue using RawEquals as long as they've already taken care
of all of the other things that can make that go wrong, such as value
marks.

Unfortunately the shim was too simplistic and only supported direct
unknown values. Unknown values with refinements can also appear nested
inside known container values such as collections, so the shim needs to
recursively un-refine the entire data structure in that case.

This is still intended only as a temporary fix until we have time to
revisit all of the callers and make them use cty's own logic for
comparison. Using cty's own logic will make the results more precise,
because e.g. it can notice if two unknown strings have different known
prefixes and therefore cannot possibly be equal despite not being fully
known. For now this shim will accept any pair of unknown values of the
same type as equal, regardless of refinement.
2023-06-22 13:16:43 -07:00
James Bardin
f6c536e436 validate planned set sizes using refinements 2023-06-15 13:08:09 -04:00
James Bardin
3c8a163583 set length is unknown with partially known elems
If a set contains partially known values the length is unknown which
causes assertPlannedObjectValid to fail valid plans.

Revert to the old method if using LengthInt for the set lengths, which
returns the maximum number of possible elements, with a guard for
entirely unknown set values.
2023-06-15 09:29:42 -04:00
Martin Atkins
4c439b099f plans/objchange: Don't consider refinements when validating plans
Providers that existed prior to refinements (all of them, at the time of
writing) cannot preserve refinements sent in unknown values in the
configuration, and even if one day providers _are_ aware of refinements
there we might add new ones that existing providers don't know how to
handle.

For that reason we'll absolve providers of the responsibility of
preserving refinements from config into plan by fixing some cases where
we were incorrectly using RawEquals to compare values; that function isn't
appropriate for comparing values that might be unknown.

However, to avoid a disruptive change right now this initial fix just
strips off the refinements before comparing. Ideally this should be using
Value.Equals and handling unknown values more explicitly, but we'll save
that for a possible later improvement.

This does not include a similar exception for validating whether a final
value conforms to a plan because the plan value and the final value are
both produced by the same provider and so providers ought to be able to
be consistent with their _own_ treatment of refinements, if any.
Configuration is special because Terraform itself generates that, and so
it can potentially contain refinements that a particular provider has no
awareness of.
2023-05-24 13:48:13 -07:00
Martin Atkins
dfe5e1ddc4 plans/objchange: Providers must honor their unknown value refinements
If the original value was unknown but its range was refined then the
provider must return a value that is within the refined range, because
otherwise downstream planning decisions could be invalidated.

This relies on cty's definition of whether a value is in a refined range,
which has pretty good coverage for the "false" case and so should give a
pretty good signal, but it'll probably improve over time and so providers
must not rely on any loopholes in the current implementation and must
keep their promises even if Terraform can't currently check them.
2023-05-24 13:44:08 -07:00
CJ Horton
258bdbe89f
Merge pull request #33238 from hashicorp/radditude/import-plan-plumbing
plannable import: correct plumbing when using a plan output file
2023-05-23 10:36:19 -07:00
James Bardin
2f308cf948
Merge pull request #32962 from hashicorp/jbardin/validate-unknown-coll-attrs
validate unknown nested attribute collections
2023-05-23 11:38:13 -04:00
CJ Horton
40ff381887 plumb import changes to and from binary plan 2023-05-22 22:19:42 -07: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
Alisdair McDiarmid
b5658a46a2 Rebuild protobuf 2023-05-02 11:44:23 -04:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Liam Cervante
4210d905c0
[plannable import] embed the resource id within the changes (#33134)
* [plannable import] embed the resource id within the changes

* make pointers and update docs
2023-05-02 16:04:51 +02:00
kmoe
28643516b2
Plannable import 3: Make import plannable (#33085)
During a plan, Terraform now checks for the presence of import blocks.

For each resource in config, if an import block is present with a matching address, planning that node will now trigger an ImportResourceState and ReadResource. The resulting state is treated as the node's "refresh state", and planning proceeds as normal from there.

The walkImport operation is now only used for the legacy "terraform import" CLI command. This is the only case under which the plan should produce graphNodeImportStates.
2023-04-28 23:45:43 +01:00
kmoe
531efd303b
add types for plannable import (#33080) 2023-04-25 15:19:48 +01:00
Liam Cervante
aae6990d38
Add native plantimestamp function to Terraform (#32980)
* add plantimestamp function

* documentation

* add missing links

* fix typo
2023-04-21 09:47:28 +02:00
James Bardin
8ab7af8c5f validate unknown nested attribute collections
It is not valid for a provider to return an unknown value for a
configured nested collection, but we need to check for unknowns before
comparing the number of values in the collection.
2023-04-03 13:31:36 -04:00
Liam Cervante
978263efe9
Checks: Introduce check blocks into the terraform node and transform graph (#32735)
* Add support for scoped resources

* refactor existing checks addrs and add check block addr

* Add configuration for check blocks

* introduce check blocks into the terraform node and transform  graph

* address comments

* address comments

* don't execute checks during destroy operations

* don't even include check nodes for destroy operations
2023-03-23 16:07:31 +01:00
kmoe
76b34e891c
remove unused actionforchange (#32759) 2023-03-01 14:15:26 +00:00
James Bardin
b6906f3572
Merge pull request #32563 from hashicorp/jbardin/optional-computed-comparison-next
a new method of `ProposedNew` set comparison
2023-01-25 15:05:50 -05:00
James Bardin
799f4a76ab
Merge pull request #32554 from hashicorp/jbardin/optional-computed-comparison
refactor ProposedNew
2023-01-25 15:05:39 -05:00
James Bardin
33c1ffa7c2
Merge pull request #32553 from hashicorp/jbardin/nesting-map-objchange
Fix crashes with NestingMap values
2023-01-25 15:05:27 -05:00
James Bardin
d1d55653e4 update comment for fixed test 2023-01-25 12:11:31 -05:00
James Bardin
60d6e52021 a new method of ProposedNew set comparison
The existing set comparison method uses the prior elements with the computed
portions nulled out to find candidates to match the configuration. This
has the shortcoming of always removing optional+computed attributes,
because we have not yet found the configuration to know if attribute was
set or not.

Rather than having to take the most pessimistic value before comparison
to precompute the nulled values, we can compare each candidate directly,
walking the values in tandem. Each prior value is compared against the
config and checked to see if it could have been derived from that
configuration value, which allows us to treat optional+computed as
optional if there is config and computed if there is not.

This removes the ambiguity from having optional+computed attributes
within sets, giving us consistent plans when all values are known.
Unknown values of course are still undecidable, as are edge cases were
providers refresh with altered values or retained changed prior values
plan that were deemed not functionally significant.
2023-01-24 14:05:57 -05:00
James Bardin
9459f0b214 refactor ProposedNew
Unify the ProposedNew paths for Blocks and Objects. Break out the
individual case blocks into functions, then use a common interface to
dispatch the object creation to the correct function based on schema
type. This cuts the code in half, and prevents the block and object
behavior from diverging.
2023-01-20 15:59:32 -05:00
James Bardin
375c2da3e3 update NestingMap logic
Simplify the logic in the NestingMap cases. Prevent uninitialized
cty.NilVal from appearing in block case.
2023-01-20 13:51:10 -05:00
James Bardin
fcbfc365e6 fix panics when handling null values in maps
NestingMap structures are not well tested, and we panic in many
situations when null crops up. Fix the first test cases and start
refactoring best we can. This probably won't go so far as making all the
objchange functions generic over Block and Object, but we can simplify a
lot and verify parity in implementations for now.
2023-01-20 13:38:55 -05:00
James Bardin
8e917e5513 check for non-computed within optional+computed
We can check if an object in state must have at least partially come
from configuration, by seeing if the prior value has any non-null
attributes which are not computed in the schema.

This is used when the configuration contains a null optional+computed
value, and we want to know if we should plan to send the null value or
the prior state.
2023-01-20 10:50:57 -05:00
James Bardin
e16b848d00 expand test case 2023-01-19 15:03:27 -05:00
James Bardin
7ca9abe463 optional+computed
Simplify the proposedNewAttributes cases, and add another test for
coverage.
2023-01-19 10:51:38 -05:00
James Bardin
470ed22730 failing tests for nested sets in objchange
Add a number of test cases which fail without the prior changes.
2023-01-19 09:53:55 -05:00