Commit Graph

1223 Commits

Author SHA1 Message Date
James Bardin
60f82eea40
Merge pull request #32236 from hashicorp/jbardin/1.3-destroy-perf
check walkDestroy to help DestroyEdgeTransformer
2022-11-22 09:45:32 -05:00
James Bardin
c96da72319
Merge pull request #32246 from hashicorp/jbardin/plan-orphan-deleted
A deleted orphan should have no planned change
2022-11-22 09:43:34 -05:00
James Bardin
79175b29f3
Merge pull request #32261 from sivchari/fix-prealloc
fix: pre allocate for composite literal
2022-11-22 09:18:47 -05:00
Jarrett Spiker
cebd5e3fce Upgrade go-tfe to 1.12.0 2022-11-21 14:54:07 -05:00
Jarrett Spiker
c16d726f2c Succeed cloud workspace deletion if the workspace does not exist 2022-11-21 14:35:33 -05:00
Jarrett Spiker
1dafd7c0b1 Fix test compilation errors caused by interface change 2022-11-21 14:35:33 -05:00
Jarrett Spiker
060255a9d5 Use safe or force workspace delete for cloud backend 2022-11-21 14:35:33 -05:00
sivchari
ef4798de8e fix: pre allocate for composite literal 2022-11-22 02:20:54 +09:00
Sarah French
6fd3a8cdf4
go get cloud.google.com/go/storage@v1.28.0 (#32203)
* go get cloud.google.com/go/storage@v1.28.0

* go mod tidy

* Run `make generate` & `make protobuf` using go1.19.3
2022-11-21 13:14:55 +00:00
James Bardin
7946e4a88a a deleted orphan should have no plan
If when refreshing an orphaned instance the provider indicates it has
already been deleted, there is no reason to create a change for that
instance. A NoOp change should only represent an object that exists and
is not changing.

This was likely left in before in order to try and provide a record of
the change for external consumers of the plan, but newer plans also
contain all changes made outside of Terraform which better accounts for
the difference. The NoOp change now can cause problems, because it may
represent an instance with conditions to check even though that instance
does not exist.
2022-11-18 08:48:15 -05:00
James Bardin
62a8b9ef1d
Merge pull request #32207 from hashicorp/jbardin/destroy-plan-state
Ensure destroy plan contains valid state values
2022-11-17 14:18:17 -05:00
James Bardin
b5168eb6f4
Merge pull request #32208 from hashicorp/jbardin/pre-desstroy-refresh
Make the pre-destroy refresh a full plan
2022-11-17 14:18:06 -05:00
James Bardin
b6a67f622f check walkDestroy to help DestroyEdgeTransformer
In a heavily-connected graph with lots of inter-dependent providers, the
cycle checks for destroy edges across providers can seriously impact
performance. Since the specific cases we need to avoid will involve
create/update nodes, skip the extra checks during a full destroy
operation. Once we find a way to better track these dependencies, the
transformer will not need to do the cycle checks in the first place.
2022-11-17 13:29:09 -05:00
James Bardin
242b8a726c
Merge pull request #32206 from hashicorp/jbardin/communicator-size
fix typo in scp upload size check
2022-11-14 11:05:11 -05:00
James Bardin
3db3ed03fb ensure destroy plan contains valid state values
Some prior refactors left the detroyPlan method a bit confusing, and ran
into a case where the previous run state could be returned as nil.

Get rid of the no longer used pendingPlan value, and track the prior and
prev states directly, making sure we always have a value for both.
2022-11-11 14:34:21 -05:00
James Bardin
3ea704ef81 Make the pre-destroy refresh a full plan
In order to complete the terraform destroy command, a refresh must first
be done to update state and remove any instances which have already been
deleted externally. This was being done with a refresh plan, which will
avoid any condition evaluations and avoid planning new instances. That
however can fail due to invalid references from resources that are
already missing from the state.

A new plan type to handle the concept of the pre-destroy-refresh is
needed here, which should probably be incorporated directly into the
destroy plan, just like the original refresh walk was incorporated into
the normal planning process. That however is major refactoring that is
not appropriate for a patch release.

Instead we make two discrete changes here to prevent blocking a destroy
plan. The first is to use a normal plan to refresh, which will enable
evaluation because missing and inconsistent instances will be planned
for creation and updates, allowing them to be evaluated. That is not
optimal of course, but does revert to the method used by previous
Terraform releases until a better method can be implemented.

The second change is adding a preDestroyRefresh flag to the planning
process. This is checked in any location which evalCheckRules is called,
and lets us change the diagnosticSeverity of the output to only be
warnings, matching the behavior of a normal refresh plan.
2022-11-11 14:33:50 -05:00
James Bardin
8ba8d5aec4 fix typo in upload size check
The scp upload size check had a typo preventing files from reporting
their size, causing an extra temp file to be created.
2022-11-11 14:25:34 -05:00
Liam Cervante
0c7fda1906
Update HCL and go-cty to fix optional and default attributes (#32178)
* Add test cases to verify all the default and optional issues are fixed

* actually commit all the tests

* update go-cty

* Update hcl
2022-11-10 14:00:16 +00:00
Martin Atkins
d0a35c60a7 providercache: Ignore lock-mismatching global cache entries
When we originally introduced the trust-on-first-use checksum locking
mechanism in v0.14, we had to make some tricky decisions about how it
should interact with the pre-existing optional read-through global cache
of provider packages:

The global cache essentially conflicts with the checksum locking because
if the needed provider is already in the cache then Terraform skips
installing the provider from upstream and therefore misses the opportunity
to capture the signed checksums published by the provider developer. We
can't use the signed checksums to verify a cache entry because the origin
registry protocol is still using the legacy ziphash scheme and that is
only usable for the original zipped provider packages and not for the
unpacked-layout cache directory. Therefore we decided to prioritize the
existing cache directory behavior at the expense of the lock file behavior,
making Terraform produce an incomplete lock file in that case.

Now that we've had some real-world experience with the lock file mechanism,
we can see that the chosen compromise was not ideal because it causes
"terraform init" to behave significantly differently in its lock file
update behavior depending on whether or not a particular provider is
already cached. By robbing Terraform of its opportunity to fetch the
official checksums, Terraform must generate a lock file that is inherently
non-portable, which is problematic for any team which works with the same
Terraform configuration on multiple different platforms.

This change addresses that problem by essentially flipping the decision so
that we'll prioritize the lock file behavior over the provider cache
behavior. Now a global cache entry is eligible for use if and only if the
lock file already contains a checksum that matches the cache entry. This
means that the first time a particular configuration sees a new provider
it will always be fetched from the configured installation source
(typically the origin registry) and record the checksums from that source.

On subsequent installs of the same provider version already locked,
Terraform will then consider the cache entry to be eligible and skip
re-downloading the same package.

This intentionally makes the global cache mechanism subordinate to the
lock file mechanism: the lock file must be populated in order for the
global cache to be effective. For those who have many separate
configurations which all refer to the same provider version, they will
need to re-download the provider once for each configuration in order to
gather the information needed to populate the lock file, whereas before
they would have only downloaded it for the _first_ configuration using
that provider.

This should therefore remove the most significant cause of folks ending
up with incomplete lock files that don't work for colleagues using other
platforms, and the expense of bypassing the cache for the first use of
each new package with each new configuration. This tradeoff seems
reasonable because otherwise such users would inevitably need to run
"terraform providers lock" separately anyway, and that command _always_
bypasses the cache. Although this change does decrease the hit rate of the
cache, if we subtract the never-cached downloads caused by
"terraform providers lock" then this is a net benefit overall, and does
the right thing by default without the need to run a separate command.
2022-11-04 16:18:15 -07:00
Brandon Croft
be5984d664
Merge pull request #32004 from hashicorp/brandonc/nested_attr_sensitive
fix: don't reveal nested attributes with sensitive schema
2022-11-02 16:18:04 -06:00
James Bardin
1100eae89f use UIMode instead of 0 changes to detect refresh 2022-11-02 10:56:08 -04:00
James Bardin
cccfa5e4af
Merge pull request #32111 from hashicorp/jbardin/refresh-only-data-read
don't plan data source reads during refresh-only
2022-11-02 08:32:50 -04:00
Liam Cervante
6521355ba5
Convert variable types before applying defaults (#32027)
* Convert variable types before applying defaults

* revert change to unrelated test

* Add another test case to verify behaviour

* update go-cty

* Update internal/terraform/eval_variable.go

Co-authored-by: alisdair <alisdair@users.noreply.github.com>

Co-authored-by: alisdair <alisdair@users.noreply.github.com>
2022-11-02 09:38:23 +01:00
Graham Davison
6663cde619
Merge pull request #23965 from tpaschalis/disallow-s3-backend-key-trailing-slash
S3 Backend : Bucket key should not contain trailing slash
2022-11-01 13:56:43 -07:00
James Bardin
efd77159dd use key data from plan method for apply 2022-11-01 16:18:38 -04:00
James Bardin
ffe2e3935e avoid re-writing state for noop applies
We need to avoid re-writing the state for every NoOp apply. We may
still be evaluating the instance to account for any side-effects in the
condition checks, however the state of the instance has not changes.
Re-writing the state is a non-current operation, which may require
encoding a fairly large instance state and re-serializing the entire
state blob, so it is best avoided if possible.
2022-11-01 16:18:38 -04:00
James Bardin
eb88ccbc7b only add NoOp nodes with conditions
ONly add NoOp changes to the apply graph if they have conditions which
need to be evaluated.
2022-11-01 16:18:38 -04:00
James Bardin
19152e7ba5 fix log mesage 2022-11-01 16:18:38 -04:00
James Bardin
eae246cfb5 normalize empty CheckResults fields in stateV4
Ensure that empty check results are normalized in state serialization to
prevent unexpected state changes from being written.

Because there is no consistent empty, null and omit_empty usage for
state structs, there's no good way to create a test which will fail
for future additions.
2022-11-01 16:18:38 -04:00
James Bardin
fa4c652013 changes are mutated during apply 2022-11-01 16:18:38 -04:00
James Bardin
b61c02da05 don't lose checks from refresh-only plan
If there are no changes, then there is no reason to create an apply
graph since all objects are known. We however do need the walk to match
the expected state structure. This is probably only cleanup of empty
nested modules and outputs, but some investigation is needed before
making the full change.

For now we can store the checks from the plan directly into the new
state, since the apply walk overwrote the results we had already.
2022-11-01 16:18:38 -04:00
Paschalis Tsilias
4cb355f3d6 S3 Backend : Bucket key should not contain trailing slash 2022-10-31 16:19:26 -07:00
Tom Bamford
ff68c8d129
Merge pull request #31966 from kschu91/feature/azure-generic-oidc
backend/azurerm: add support for generic OIDC authentication
2022-10-31 11:25:36 +00:00
James Bardin
300ad02937 don't plan data source reads during refresh-only
When executing a refresh-only plan, it is not valid to plan a data
source read. If the data source config is not known during planning, the
only valid update would be the prior state, if there is any.
2022-10-28 10:45:49 -04:00
Brandon Croft
bd744ad4e9
Unify all sensitive value plan output as "(sensitive value)"
Previously, there was mixed usage of "(sensitive)" and "(sensitive value)" and even though it was more common to see "(sensitive)", the thought is that it's a value we are hiding rather than describing something already shown.
2022-10-24 12:50:46 -06:00
Brandon Croft
076fccd8e7
fix: don't reveal nested attributes with sensitive schema 2022-10-24 12:50:46 -06:00
James Bardin
92c8c76684 fix variable name 2022-10-20 13:14:16 -04:00
James Bardin
a44c859c86 update UIMode comment 2022-10-20 13:13:58 -04:00
James Bardin
ac99cd6051 remove extra import line 2022-10-20 11:03:58 -04:00
James Bardin
28d5a5bf63 NoOp nodes should not have destroy edges
NoOp changes should not participate in a destroy sequence, but because
they are included as normal update nodes the usual connections were
still being made.
2022-10-20 10:59:08 -04:00
James Bardin
586401aeea make naming consistent 2022-10-20 09:36:10 -04:00
James Bardin
8a4883fd13 don't eval checks on destroy 2022-10-19 17:47:53 -04:00
James Bardin
8d11c7f524 the destroy refresh plan should be refresh-only
Refreshing for a destroy should use the refresh-only plan to avoid
planning new objects or evaluating conditions. This should also be
skipped if there is no state, since there would be nothing to refresh.
2022-10-19 17:47:53 -04:00
James Bardin
08081097cb check console with preconditions 2022-10-19 17:47:53 -04:00
James Bardin
a0723442b9 test for incorrectly evaluated outputs 2022-10-19 17:47:53 -04:00
James Bardin
333bdecf39 checks must be registered during eval 2022-10-19 17:47:53 -04:00
James Bardin
1eb22fd94a fix output transformer names
The removeRootOutputs field was not strictly used for that purpose, and
was also copied to another DestroyPlan field.
2022-10-19 17:47:42 -04:00
James Bardin
47b6386348 remove IsFullDestroy workaround
IsFullDestroy was a workaround during apply to detect when the change
set was created by a destroy plan. This no longer works correctly, and
we need to fall back to the UIMode set in the plan.
2022-10-19 14:47:06 -04:00
James Bardin
bcb792ee00 complete the root output expansion
Not all root output instances were going through proper expansion when
destroy operations were involved, leading to cases where they would be
evaluated even though the expected result was only to remove them from
the state.

Normally destroy nodes stand alone in the graph, and do not produce
references to other nodes. Because root output nodes were replaced by
expansion nodes, these were being connected via normal references, even
in the case where we were working with a destroy graph.
2022-10-19 14:42:55 -04:00
James Bardin
8a24d73d15 outputs should not be checked during destroy
Module output may need to be evaluated during destroy in order to
possibly be used by providers. The final state however is that all
objects are destroyed, so preconditions should not be evaluated.
2022-10-19 14:39:21 -04:00