Commit Graph

1772 Commits

Author SHA1 Message Date
Martin Atkins dd8af65c82 core: Input walk shouldn't clobber dynamic provider config
During the input walk we stash the values resulting from user input
(if any) in the eval context for use when later walks need to resolve
the provider config.

However, this repository of input results is only able to represent
literal values, since it does not retain the record of which of the keys
have values that are "computed".

Previously we were blindly stashing all of the results, failing to
consider that some of them might be computed. That resulted in the
UnknownValue placeholder being misinterpreted as a literal value when
the data is used later, which ultimately resulted in it clobbering the
actual expression evaluation result and thus causing the provider to
fail to configure itself.

Now we are careful to only retain in this repository the keys whose values
are known statically during the input phase. This eventually gets merged
with the dynamic evaluation results on subsequent walks, with the dynamic
keys left untouched due to their absence from the stored input map.

This fixes #11264.
2017-04-04 10:31:42 -07:00
James Bardin c55a5082f5 delegate BackendState.Rehash to config.Backend 2017-03-29 18:01:03 -04:00
James Bardin ff2d753062 add Rehash to terraform.BackendState
This method mirrors that of config.Backend, so we can compare the
configration of a backend read from a config vs that of a backend read
from a state. This will prevent init from reinitializing when using
`-backend-config` options that match the existing state.
2017-03-29 15:53:42 -04:00
Martin Atkins 21cd5595e2 Update stringer-generated files to new boilerplate
golang/tools commit 23ca8a263 changed the format of the leading comment
to comply with some new standards discussed here:
https://golang.org/issue/13560

This is the result of running generate with the latest version of
stringer. Everyone working on Terraform will need to update stringer
after this is merged, to avoid reverting this:
    go get -u golang.org/x/tools/cmd/stringer
2017-03-29 08:07:06 -07:00
Paul Stack 7479b8d150 release: clean up after v0.9.2 2017-03-28 10:05:25 +00:00
Paul Stack 6365269541
v0.9.2 2017-03-28 09:56:35 +00:00
Mitchell Hashimoto 69759e04ca
terraform: convert empty path to root path in V1 state 2017-03-21 11:37:12 -07:00
Mitchell Hashimoto e7b07e109f
terraform: V1 to V2 upgrade should treat nil path as root path
It appears there are no tests for this as far as I can find.

We change V1 states (very old) to assume a nil path is a root path.
Staet.Validate() later will catch any duplicate paths.
2017-03-21 11:12:44 -07:00
James Bardin b7152c4405 Merge pull request #12897 from hashicorp/jbardin/ignore-changes
ignore_changes causes keys in other flatmapped objects to be lost from diff
2017-03-21 09:25:47 -04:00
James Bardin 0ae0076e3a Correctly filter flatmapped values in diff
When transforming a diff from DestroyCreate to a simple Update,
ignore_changes can cause keys from flatmapped objects to be filtered
form the diff. We need to filter each flatmapped container as a whole to
ensure that unchanged keys aren't lost in the update.
2017-03-21 09:11:54 -04:00
James Bardin 3001f0c1b9 Fix test that relied on empty Old diff 2017-03-20 17:44:38 -04:00
James Bardin 970e7c1923 Add a failing test for missing keys in diff
ignore_changes is causing changes in other flatmapped sets to be
filtered out incorrectly.

This required fixing the testDiffFn to create diffs which include the
old value, breaking one other test.
2017-03-20 17:44:37 -04:00
Benjamin Boudreau 073fa873ac Fix receive typo (#12881) 2017-03-20 13:15:27 -04:00
Mitchell Hashimoto 1d1dc7cf30 release: clean up after v0.9.1 2017-03-17 22:54:23 +00:00
Mitchell Hashimoto 7c25ef851b
v0.9.1 2017-03-17 22:48:44 +00:00
Mitchell Hashimoto e8b3062629
terraform: unknown value for variables not set
Fixes #12836

Realistically, these should be caught during validation anyways. In this
case, this was causing 12386 because refresh with a data source will
attempt to use module variables. I don't see any clear logic to prune
those module variables or not add them so its easier to return unknown
to cause the data to be computed and not run.
2017-03-17 15:33:33 -07:00
James Bardin 9e8ddaed47 Don't interpolate multivariables during walkInput
We don't need these expanded for input, and if the multivar's count is a
variable, it may be known but not available during the input walk.
2017-03-16 13:45:07 -04:00
James Bardin fe5f519817 Add failing test for invalid interpolation
Adding the submodule causes the count variable interpolation to fail.
2017-03-16 10:35:18 -04:00
Mitchell Hashimoto 37b3fe1119 release: clean up after v0.9.0 2017-03-15 16:39:53 +00:00
Mitchell Hashimoto 5bd194faa6
v0.9.0 2017-03-15 16:33:13 +00:00
James Bardin 7c9863ccb0 fix another hot lop in tests
Found another test spinlock.
Slow it down to prevent it from blocking the runtime scheduler.
2017-03-15 12:02:28 -04:00
Mitchell Hashimoto 9900bd752a
terraform: string through the context meta 2017-03-13 16:21:09 -07:00
Mitchell Hashimoto 4e1511c77f
terraform: interpolate "terraform.env" 2017-03-13 16:14:27 -07:00
James Bardin ecb1944c31 Merge pull request #12498 from hashicorp/jbardin/test-reset
Add schema.Provider.TestReset to reset StopContext between tests
2017-03-09 08:34:54 -05:00
James Bardin 5238f51dc7 move TestReset mock from terraform to helper
the terraform package doesn't know about TestProvider, so don't put the
hooks in terraform.MockResourceProvider. Wrap the mock in the test where
we need to check the TestProvider functionality.
2017-03-08 17:48:11 -05:00
James Bardin 38d2a8f6ac Fix logic race with Context.watchStop
Always wait for watchStop to return during context.walk.

Context.walk would often complete immediately after sending the close
signal to watchStop, which would in turn call the deferred releaseRun
cancelling the runContext.

Without any synchronization points after the select statement in
watchStop, that goroutine was not guaranteed to be scheduled
immediately, and in fact it often didn't continue until after the
runContext was canceled. This in turn left the select statement with
multiple successful cases, and half the time it would chose to Stop the
providers.

Stopping the providers after the walk of course didn't cause any
immediate failures, but if there was another walk performed, the
provider StopContext would no longer be valid and could cause
cancellation errors in the provider.
2017-03-08 15:11:10 -05:00
James Bardin 0279d11c8a Add TestReset to terraformMockResourceProvider
Have MockResourceProvider implement TestProvider to check that TestReset
is called by the test harness.
2017-03-07 11:39:12 -05:00
James Bardin 3e0af2abbb Sort Validation warning and errors
Make the UI output consistent
2017-03-03 09:46:08 -05:00
Mitchell Hashimoto a2d78b62aa release: clean up after v0.9.0-beta2 2017-03-02 19:42:41 +00:00
Mitchell Hashimoto dbb920ff54
v0.9.0-beta2 2017-03-02 19:38:11 +00:00
James Bardin e5e37b0025 Merge pull request #12340 from hashicorp/jbardin/GH-12253
return 0 from resourceCountMax with a nil Resource
2017-03-02 11:59:32 -05:00
Mitchell Hashimoto 19a594ba3d
terraform: run Gosched in test so other goroutines run
Starting with Go 1.8 betas, we've periodically received SIGQUITs on our
tests in Travis. The stack trace looks like this:

https://gist.github.com/mitchellh/abf09b0980f8ea01269f8d9d6133884d

The tests are timing out! This is a test that hasn't been touched really
in a very long time and has always passed. I've **reproduced this
locally** by setting `GOMAXPROCS=1` and running the test. By yielding
the scheduler in the hot loop, it now passes almost instantly every
time.

Perhaps the test can be written in a different way, but this gets tests
passing and I think will fix our periodic errors.
2017-03-01 23:12:41 -08:00
James Bardin ff445d3c26 fix test that were relying on non-matching configs
A couple interpolation tests were using invalid state that didn't match
the config. These will still pass but were flushed out by an attempt to
make this an error. The repl however still required interpolation
without a config, and tests there will provide a indication if this
behavior changes.
2017-03-01 15:24:52 -05:00
James Bardin 6fa4a591a0 prevent calling Count() on non-existent resources
It turns out that a few use cases depend on not finding a resource
without an error.

The other code paths had sufficient nil checks for this, but there was
one place where we called Count() that needed to be checked. If the
existence of the resource matters, it would be caught at a higher level
and still return an "unknown resource" error to the user.
2017-03-01 15:24:40 -05:00
James Bardin 1e80c402bf add failing test for GH-12253 2017-03-01 11:48:38 -05:00
James Bardin 41ec5b3bd2 missing defaults in sort
Need to properly catch some sort cases around 0-1 indexing.
This can cause output to shift slightly, resulting in an intermittent
test failure.
2017-02-25 16:50:24 -05:00
James Bardin 82914b5e44 Merge pull request #12219 from hashicorp/jbardin/state-mv-sort
fix sorting of module resources during state mv
2017-02-24 09:49:26 -05:00
James Bardin d6eb7c8989 one test was relying on out-of-order output 2017-02-24 09:36:24 -05:00
James Bardin 43c7bd648c fix sorting of module resources during state mv
Module resource were being sorted lexically by name by the state filter.
If there are 10 or more resources, the order won't match the index
order, and resources will have different indexes in their new location.

Sort the FilterResults by index numerically when the names match.

Clean up the module String output for visual inspection by sorting
Resource name parts numerically when they are an integer value.
2017-02-23 18:27:16 -05:00
Mitchell Hashimoto 41d2c145b2
terraform: State.Equal needs to use reflect for rich types
Due to the change to `interface{}` we need to use `reflect.DeepEqual`
here. With the restriction of primitive types this should always be
safe. We'll never get functions, channels, etc.
2017-02-23 14:00:40 -08:00
Mitchell Hashimoto 3342aa580c
terraform: InstanceState.Meta is value type interface{}
This changes the type of values in Meta for InstanceState to
`interface{}`. They were `string` before.

This will allow richer structures to be persisted to this without
flatmapping them (down with flatmap!). The documentation clearly states
that only primitives/collections are allowed here.

The only thing using this was helper/schema for schema versioning.
Appropriate type checking was added to make this change safe.

The timeout work @catsby is doing will use this for a richer structure.
2017-02-23 10:44:05 -08:00
Mitchell Hashimoto c6d0333dc0
flatmap: mark computed list as a computed value in Expand
Fixes #12183

The fix is in flatmap for this but the entire issue is a bit more
complex. Given a schema with a computed set, if you reference it like
this:

    lookup(attr[0], "field")

And "attr" contains a computed set within it, it would panic even though
"field" is available. There were a couple avenues I could've taken to
fix this:

1.) Any complex value containing any unknown value at any point is
entirely unknown.

2.) Only the specific part of the complex value is unknown.

I took route 2 so that the above works without any computed (since
"name" is not computed but something else is). This may actually have an
effect on other parts of Terraform configs, however those similar
configs would've simply crashed previously so it shouldn't break any
pre-existing configs.
2017-02-23 10:03:59 -08:00
Mitchell Hashimoto a49875067d
terraform: extra logging 2017-02-21 20:35:36 -08:00
Mitchell Hashimoto f6ab0bc5c4
terraform: interpolation failures on a destroy provisioner should error 2017-02-17 14:32:32 -08:00
Mitchell Hashimoto a1ec81964b
terraform: destroy ordering needs to handle destroy provisioner edges
This ensures that things aren't destroyed before their values are used.
2017-02-17 14:29:22 -08:00
Mitchell Hashimoto 757217b91f
terraform: destroy resource should depend on destroy-time prov deps 2017-02-17 13:13:44 -08:00
Mitchell Hashimoto ef546517be
terraform: close transform should not include untargeted providers 2017-02-17 09:27:47 -08:00
Mitchell Hashimoto 9062a1893e
terraform: don't include providers if not targeted
Fixes #12009

This is a simple change similar to #10911 where we need to exclude
providers that aren't targeted.
2017-02-17 09:21:29 -08:00
Mitchell Hashimoto 1607c1187d release: clean up after v0.9.0-beta1 2017-02-15 22:39:57 +00:00
Mitchell Hashimoto 4e96da57ee
v0.9.0-beta1 2017-02-15 22:35:37 +00:00