Commit Graph

42 Commits

Author SHA1 Message Date
Mitchell Hashimoto 71a1e215d9
terraform: add more Same test cases to cover #9171 2016-11-21 17:31:47 -08:00
Mitchell Hashimoto 55ef93f0f9
terraform: Diff.Same should understand that Destroy might go false 2016-11-15 11:26:42 -08:00
Mitchell Hashimoto f9fee4106f
terraform: Diff.Prune 2016-11-08 13:28:50 -08:00
Mitchell Hashimoto df981b234d
terraform: NewComputed doesn't quit Same logic
For #9618, we added the ability to ignore old diffs that were computed
and removed (because the ultimate value ended up being the same). This
ended up breaking computed list/set logic.

The correct behavior, as is evident by how the other "skip" logics work,
is to set `ok = true` so that the remainder of the logic can run which
handles stuff such as computed lists and sets.
2016-11-01 09:53:53 -07:00
Mitchell Hashimoto 3f36787207 Merge pull request #9618 from hashicorp/b-computed-prim
helper/schema,terraform: handle computed primitives in diffs
2016-10-28 10:44:13 -04:00
Mitchell Hashimoto 95d37ea79c
helper/schema,terraform: handle computed primtives in diffs
Fixes #3309

There are two primary changes, one to how helper/schema creates diffs
and one to how Terraform compares diffs. Both require careful
understanding.

== 1. helper/schema Changes

helper/schema, given any primitive field (string, int, bool, etc.)
_used to_ create a basic diff when given a computed new value (i.e. from
an unkown interpolation). This would put in the plan that the old value
is whatever the old value was, and the new value was the actual
interpolation. For example, from #3309, the diff showed the following:

```
~ module.test.aws_eip.test-instance.0
    instance: "<INSTANCE ID>" => "${element(aws_instance.test-instance.*.id, count.index)}"
```

Then, when running `apply`, the diff would be realized and you would get
a diff mismatch error because it would realize the final value is the
same and remove it from the diff.

**The change:** `helper/schema` now marks unknown primitive values with
`NewComputed` set to true. Semantically this is correct for the diff to
have this information.

== 2. Terraform Diff.Same Changes

Next, the way Terraform compares diffs needed to be updated

Specifically, the case where the diff from the plan had a NewComputed
primitive and the diff from the apply _no longer has that value_. This
is possible if the computed value ended up being the same as the old
value. This is allowed to pass through.

Together, these fix #3309.
2016-10-25 22:36:59 -04:00
Mitchell Hashimoto ac9a049d19
terraform: Diff.Equal ignores ModuleDiff.Destroy
This is necessary to get the shadow working properly with the destroy
graph since the destroy graph doesn't set this field but the end state
is still the same.
2016-10-22 12:12:30 -07:00
Mitchell Hashimoto 50afee2a30
terraform: Diff.Empty should be true for nil Diff 2016-10-19 13:38:01 -07:00
Mitchell Hashimoto 31f8d13678
terraform: Diff.Equal and tests 2016-10-11 22:17:31 +08:00
Mitchell Hashimoto 5053872e82
terraform: Diff.DeepCopy test to catch a bug that in copystructure
This was fixed upstream but keeping the test around to prevent
regressions.
2016-10-11 22:17:29 +08:00
Paul Hinze 3dccfa0cc9
terraform: diffs with only tainted set are non-empty
Fixes issue where a resource marked as tainted with no other attribute
diffs would never show up in the plan or apply as needing to be
replaced.

One unrelated test needed updating due to a quirk in the testDiffFn
logic - it adds a "type" field diff if the diff is non-Empty. NBD
2016-08-12 17:37:49 -05:00
James Bardin 0e507e7e5e Remove computed maps from the diff Same check
Just like computed sets, computed maps may have both different values
and different cardinality after they're computed. Remove the computed
maps and the values from the compared diffs.
2016-06-27 10:04:45 -04:00
James Nugent 1f9a2b241e Merge pull request #7207 from hashicorp/b-diff-maps
core/diff: Fix attribute mismatch with tags.%
2016-06-24 15:03:36 +03:00
clint shryock 9967641c4b core/diff: Fix attribute mismatch with tags.% 2016-06-16 18:22:21 -05:00
James Bardin f4ef16a84b Add a core test for InstanceDiff.Same 2016-06-16 18:43:15 -04:00
Chris Marchesi 9d7fb89114 core: Adding Sensitive attribute to resource schema
This an effort to address hashicorp/terraform#516.

Adding the Sensitive attribute to the resource schema, opening up the
ability for resource maintainers to mark some fields as sensitive.
Sensitive fields are hidden in the output, and, possibly in the future,
could be encrypted.
2016-05-29 22:18:44 -07:00
Paul Hinze 4af2c5f5dd core: fix diff mismatch when RequiresNew field and list both change
fixes #1752

Includes AccTest reproducing example from the issue as well as a bunch
of explanatory comments in the tests and impls.
2016-01-19 15:38:04 -06:00
Paul Hinze 64f0897c82 core: avoid diff mismatch on NewRemoved fields during -/+
fixes #1508

In a DESTROY/CREATE scenario, the plan diff will be run against the
state of the old instance, while the apply diff will be run against an
empty state (because the state is cleared when the destroy node does its
thing.)

For complex attributes, this can result in keys that seem to disappear
between the two diffs, when in reality everything is working just fine.

Same() needs to take into account this scenario by analyzing NewRemoved
and treating as "Same" a diff that does indeed have that key removed.
2015-04-14 17:23:30 -05:00
Paul Hinze d168cc1bd1 terraform: add reason to diff mismatch error
Helps with debugging those pesky "diffs did not match" errors.
2015-04-13 09:31:09 -05:00
Sander van Harmelen 8347569396 Adding a test for the change in PR #681
Should have already done that together with that PR…
2014-12-16 19:15:07 +01:00
Sander van Harmelen 83c760fcb3 core: refactoring the way sets work internally v2
This is a refactored solution for PR #616. Functionally this is still
the same change, but it’s implemented a lot cleaner with less code and
less changes to existing parts of TF.
2014-12-12 23:21:20 +01:00
Emil Hessman 4bfe18b40d argument and verb formatting fixes reported by go vet
builtin/providers/aws/tags_test.go:56: unrecognized printf verb 'i'
builtin/providers/aws/tags_test.go:59: unrecognized printf verb 'i'

config/config_test.go:101: possible formatting directive in Fatal call
config/config_test.go:157: possible formatting directive in Fatal call

config/module/get_file_test.go:91: missing argument for Fatalf(%s): format reads arg 1, have only 0 args

helper/schema/schema.go:341: arg v.Type for printf verb %s of wrong type: schema.ValueType
helper/schema/schema.go:656: missing argument for Errorf(%s): format reads arg 2, have only 1 args
helper/schema/schema.go:912: arg schema.Type for printf verb %s of wrong type: schema.ValueType

terraform/context.go:178: arg v.Type() for printf verb %s of wrong type: github.com/hashicorp/terraform/config.VariableType
terraform/context.go:486: arg c.Operation for printf verb %s of wrong type: terraform.walkOperation

terraform/diff_test.go💯 arg actual for printf verb %s of wrong type: terraform.DiffChangeType
terraform/diff_test.go:235: arg actual for printf verb %s of wrong type: terraform.DiffChangeType
2014-11-02 13:56:44 +01:00
Mitchell Hashimoto ab6741f6fc terraform: require the prefix match with a "." in Diff.Instances 2014-10-10 13:46:44 -07:00
Mitchell Hashimoto 75e79da9c3 terraform: modify Same to return true if list is computed 2014-10-09 20:52:38 -07:00
Mitchell Hashimoto a12f785211 terraform: add some helpers to ModuleDiff and InstanceDiff for UX 2014-09-24 17:51:45 -07:00
Mitchell Hashimoto 672bf58337 command: compiles, tests don't pass yet 2014-09-24 14:37:24 -07:00
Mitchell Hashimoto bc67e7c443 terraform: diff is split down into modules 2014-09-23 11:43:21 -07:00
Mitchell Hashimoto 29603f36d2 terraform: remove Read/WriteDiff, we don't use it 2014-09-23 11:15:05 -07:00
Mitchell Hashimoto 9b2b3a963f ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
Mitchell Hashimoto 7221e01110 terraform: unit test Same function on ResourceDiff 2014-07-22 19:39:48 -07:00
Mitchell Hashimoto ff79fa9c9f terraform: tests for ResourceDiff.Empty 2014-06-30 20:56:25 -07:00
Mitchell Hashimoto 0ab7faf5c1 terraform: update test to latest 2014-06-25 22:19:27 -07:00
Mitchell Hashimoto 1449d8a510 terraform: Diff.Empty 2014-06-19 14:57:36 -07:00
Mitchell Hashimoto e5b82931ff terraform: read/write diff to binary format 2014-06-18 20:34:39 -07:00
Mitchell Hashimoto f032ce6c1b terraform: ResourceDiff tests 2014-06-17 18:10:38 -07:00
Mitchell Hashimoto 997724dc57 terraform: know whether create or update resource 2014-06-10 11:37:04 -07:00
Mitchell Hashimoto 469d20afe3 terraform: note which attributes require a new resource 2014-06-10 11:33:59 -07:00
Mitchell Hashimoto fac68b0c09 terraform: match key lengths up in a diff 2014-06-10 11:30:54 -07:00
Mitchell Hashimoto 36a99b5920 terraform: alphabetize attributes in diff 2014-06-10 11:27:17 -07:00
Mitchell Hashimoto 32afc6dc70 terraform: Diff.String 2014-06-10 11:22:32 -07:00
Mitchell Hashimoto 967d4a61c1 terraform: tests that computed placeholders get inserted proprely 2014-06-05 20:17:03 -07:00
Mitchell Hashimoto 7c6920bba1 terraform: diff/state work better together, merge 2014-06-05 06:57:06 -07:00