Commit Graph

380 Commits

Author SHA1 Message Date
Pam Selle eb2a027684
Merge pull request #26518 from hashicorp/pselle/sensitive-experiment
Remove sensitive_variables experiment
2020-10-08 16:14:37 -04:00
James Bardin f5361286cc fix tests that happened during the cleanup 2020-10-08 14:58:43 -04:00
James Bardin 57a47d0b82
Merge pull request #26519 from hashicorp/jbardin/FIXME
Cleanup and remove legacy types from test mocks
2020-10-08 14:54:40 -04:00
James Bardin a0caed541d remove legacy ApplyFn from mock provisioner 2020-10-08 13:13:13 -04:00
James Bardin 177797100d remove old mock validateFn 2020-10-08 12:43:46 -04:00
James Bardin ea5ee39f38 remove old mock provider ConfigureFn 2020-10-08 12:26:12 -04:00
James Bardin 0a6853a3f8 replace testDiffFn and testApplyFn
Replace the old mock provider test functions with modern equivalents.
There were a lot of inconsistencies in how they were used, so we needed
to update a lot of tests to match the correct behavior.
2020-10-08 11:47:34 -04:00
Pam Selle bc57c20d10 Remove sensitive_variables experiment
Ahead of the beta, remove the sensitive_variable experiment
and update tests accordingly
2020-10-08 11:22:20 -04:00
Pam Selle 2c352ef182 Apply should not communicate w provider if only sensitivity changes
If sensitivity changes, we have an update plan,
but should avoid communicating with the provider
on the apply, as the values are equal (and otherwise
a NoOp plan)
2020-10-07 13:30:35 -04:00
James Bardin 8d5e844158 no need to loop this test any longer 2020-10-07 10:47:09 -04:00
James Bardin c48af3f18b
Merge pull request #26470 from hashicorp/jbardin/inverse-destroy-references
Allow special-case evaluation of instances pending deletion.
2020-10-05 16:20:22 -04:00
Pam Selle f35b530837 Update compatibility checks for blocks to not use marks
Remove marks for object compatibility tests to allow apply
to continue. Adds a block to the test provider to use
in testing, and extends the sensitivity apply test to include a block
2020-10-02 13:11:55 -04:00
James Bardin 43c0525277 fix the test that was supposed to break
The test for this behavior did not work, because the old mock diff
function does not work correctly. Write a PlanResourceChange function to
return a correct plan.
2020-10-02 08:50:24 -04:00
James Bardin 8c699fbe32 Unsynchronized maps in test 2020-09-30 12:14:31 -04:00
Alisdair McDiarmid e41b2ef2d4 terraform: Add test for complex sensitive values
When a sensitive variable has a complex type, any traversal of the
variable should still result in a sensitive value. This test uses a
sensitive `map(string)` and verifies that both plan and state output
include the appropriate sensitive marks for the resource attribute.
2020-09-25 11:37:45 -04:00
Kristin Laemmert 90655b98b0 terraform: rename mustReourceAddr to mustConfigResourceAddr and add mustAbsResourceAddr
there are too many things that can be called resource addrs and it can
be hard to find the must* I'm looking for, so I renamed one and added
another.
2020-09-25 09:29:18 -04:00
Pam Selle 0a02e7040f
Store sensitive attribute paths in state (#26338)
* Add creation test and simplify in-place test

* Add deletion test

* Start adding marking from state

Start storing paths that should be marked
when pulled out of state. Implements deep
copy for attr paths. This commit also includes some
comment noise from investigations, and fixing the diff test

* Fix apply stripping marks

* Expand diff tests

* Basic apply test

* Update comments on equality checks to clarify current understanding

* Add JSON serialization for sensitive paths

We need to serialize a slice of cty.Path values to be used to re-mark
the sensitive values of a resource instance when loading the state file.
Paths consist of a list of steps, each of which may be either getting an
attribute value by name, or indexing into a collection by string or
number.

To serialize these without building a complex parser for a compact
string form, we render a nested array of small objects, like so:

[
  [
    { type: "get_attr", value: "foo" },
    { type: "index", value: { "type": "number", "value": 2 } }
  ]
]

The above example is equivalent to a path `foo[2]`.

* Format diffs with map types

Comparisons need unmarked values to operate on,
so create unmarked values for those operations. Additionally,
change diff to cover map types

* Remove debugging printing

* Fix bug with marking non-sensitive values

When pulling a sensitive value from state,
we were previously using those marks to remark
the planned new value, but that new value
might *not* be sensitive, so let's not do that

* Fix apply test

Apply was not passing the second state
through to the third pass at apply

* Consistency in checking for length of paths vs inspecting into value

* In apply, don't mark with before paths

* AttrPaths test coverage for DeepCopy

* Revert format changes

Reverts format changes in format/diff for this
branch so those changes can be discussed on a separate PR

* Refactor name of AttrPaths to AttrSensitivePaths

* Rename AttributePaths/attributePaths for naming consistency

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2020-09-24 12:40:17 -04:00
James Bardin bc82347a04 fix tests
Update tests to match the new behavior. Some were incorrect, some no
longer make sense, and some just weren't setup to handle th plan api
calls.
2020-09-21 16:17:46 -04:00
James Bardin 1fa3503acd fixup last tests that need correct state 2020-09-17 09:54:59 -04:00
James Bardin d19f440d81 contexts have a copy of the state
We need to build a new context go get at the modified state
2020-09-17 09:54:59 -04:00
James Bardin 7d6472dad0 use plan state in contextOptsForPlanViaFile 2020-09-17 09:54:59 -04:00
James Bardin 696290e481
Merge pull request #26264 from hashicorp/jbardin/evaluate-destroy
allow evaluation of 0 instances during apply
2020-09-16 11:35:33 -04:00
James Bardin 7156649336 allow evaluation of 0 instances during apply
While this was easier to spot during plan, it is also possible to
evaluate resources with 0 instances during apply as well.

This doesn't effect the failure when scaling CBD instances, it only
changes the fact that the inconsistent value is no longer unknown.
2020-09-16 11:18:23 -04:00
James Bardin 67fd32db7e improve failing test
Correct the initial test state, and expand the test to cause a cycle
without the previous fix.
2020-09-16 10:38:41 -04:00
James Bardin 7695d1cefe add test for forced cbd with no other changes
If a resource is forced CreateBeforeDestroy from a dependent resource,
and that dependent has no changes, the plan is changed from
CreateThenDelete to DeleteThenCreate causing an apply error.
2020-09-09 16:41:01 -04:00
James Bardin c9e581e58a don't connect module closers to destroy nodes
One of the tenants of the graph transformations is that resource destroy
nodes can only be ordered relative to other resources, and can't be
referenced directly. This was broken by the module close node which
naively connected to all module nodes, creating cycles in some cases
when edges are reversed from CreateBeforeDestroy.
2020-09-09 12:23:23 -04:00
Kristin Laemmert 196c183dda
terraform: remove state from `validate` graph walk (#26063)
This pull reverts a recent change to backend/local which created two context, one with and one without state. Instead I have removed the state entirely from the validate graph (by explicitly passing a states.NewState() to the validate graph builder).

This changed caused a test failure, which (ty so much for the help) @jbardin discovered was inaccurate all along: the test's call to `Validate()` was actually what was removing the output from state. The new expected test output matches terraform's actual behavior on the command line: if you use -target to destroy a resource, an output that references only that resource is *not* removed from state even though that test would lead you to believe it did.

This includes two tests to cover the expected behavior:

TestPlan_varsUnset has been updated so it will panic if it gets more than one request to input a variable
TestPlan_providerArgumentUnset covers #26035

Fixes #26035, #26027
2020-08-31 15:45:39 -04:00
James Bardin 058dff44f9
Merge pull request #25922 from hashicorp/jbardin/destroy-pruning
Fix node-pruning during destroy
2020-08-21 16:49:14 -04:00
James Bardin 59b7ae8eb4
Merge pull request #25694 from alrs/alrs/terraform-test-err
terraform: fix dropped test error
2020-08-19 11:37:41 -04:00
James Bardin b68ab92392 more complicated for_each destroy 2020-08-19 11:10:12 -04:00
Lars Lehtonen 9499ec4422
terraform: fix dropped test error 2020-07-28 20:11:54 -07:00
James Bardin 5c31add2fc test data source index reference too 2020-07-23 17:16:32 -04:00
James Bardin 5b8e5ec276 destroy provisioner test
Ensure that we have destroy provisioner test that reference self
2020-07-20 15:49:51 -04:00
James Bardin 3223e352ea skip broken test
This is the known case broken by the changes to allow resources pending
destruction to be evaluated from state. When a resource references
another that is create_before_destroy, and that resource is being scaled
in, the first resource will not be updated correctly.
2020-07-20 09:49:47 -04:00
James Bardin ca8338e343 fix tests after moving incorrect references
The destroy graph builder test requires state in order to be correct,
which it didn't have. The other tests hits the edge case where a planned
destroy cannot remove outputs, because the apply phase does not know it
was created from a destroy.
2020-07-20 09:49:47 -04:00
James Bardin c0dbc95236 test destroy with provider depending on a resource 2020-07-20 09:49:47 -04:00
James Bardin b62640d2d5 update output destroy test to reference expander
Have the output reference the expansion of a resource (via the whole
resource object), so that we can be sure we don't attempt to evaluate
that expansion during destroy.
2020-07-07 11:08:14 -04:00
James Bardin 6243a6307a don't evaluate destroy instances
Orphaned instances that are create_before_destroy will still be in the
state when their references are evaluated. We need to skip instances
that are planned to be destroyed altogether, as they can't be part of an
evaluation.
2020-06-26 18:05:53 -04:00
James Bardin f9ff7d1ee8 test for targeting with modules and output 2020-06-24 12:52:29 -04:00
James Bardin 58babccc7a improve depends_on test to check ordering 2020-06-04 18:03:03 -04:00
James Bardin 74ae34865d re-add test lost in merge 2020-05-28 21:41:15 -04:00
James Bardin b860b40127 re-enable depend_on test 2020-05-28 21:35:05 -04:00
James Bardin 75ec201e6a temporarily disable module depends_on test 2020-05-28 21:33:56 -04:00
James Bardin a9e0f46f23 expanded module depends_on test 2020-05-28 21:33:05 -04:00
James Bardin 70ac00595b fix apply tests
sSme apply tests had outputs in empty modules, which won't be saved to
state.
2020-05-28 21:30:44 -04:00
James Bardin d2466fab3d add module self-reference test 2020-05-27 15:09:52 -04:00
James Bardin 14ef51bfcd module depends_on test
verify a chain of depends_on references through modules execute in the
correct order
2020-05-20 14:46:30 -04:00
James Bardin e690fa1363
Merge pull request #24904 from hashicorp/jbardin/plan-data-sources
Evaluate data sources in plan when necessary
2020-05-20 10:00:32 -04:00
James Bardin c052463f62 test for inherited create_before_destroy in state 2020-05-14 15:46:08 -04:00
James Bardin c6c851eb3f add test for using a data source with depends_on
Ensure that a data source with depends_on not only plans to update
during refresh, but evaluates correctly in the plan ensuring
dependencies are planned accordingly.
2020-05-13 13:58:11 -04:00