Commit Graph

22 Commits

Author SHA1 Message Date
Paul Hinze 24c45fcd5d
terraform: Filter untargeted variable nodes
When targeting, only Addressable untargeted nodes were being removed
from the graph. Variable nodes are not directly Addressable, so they
were hanging around. This caused problems with module variables that
referred to Resource nodes. The Resource node would be filtered out of
the graph, but the module Variable node would not, so it would try to
interpolate during the graph walk and be unable to find it's referent.

This would present itself as strange "cannot find variable" errors for
variables that were uninvolved with the currently targeted set of
resources.

Here, we introduce a new interface that can be implemented by graph
nodes to indicate they should be filtered out from targeting even though
they are not directly addressable themselves.
2016-07-29 16:55:30 -05:00
James Nugent 1401a52a5c Merge pull request #7493 from hashicorp/b-pass-map-to-module
terraform: allow literal maps to be passed to modules
2016-07-08 11:50:29 +01:00
James Bardin 21e2173e0a Fix nested module "unknown variable" during dest (#7496)
* Fix nested module "unknown variable" during dstry

During a destroy with nested modules, accessing a variable between them
causes an "unknown variable accessed" during destroy.
2016-07-06 11:22:41 -04:00
Paul Hinze 559f14c3fa
terraform: allow literal maps to be passed to modules
Passing a literal map to a module looks like this in HCL:

    module "foo" {
      source = "./foo"
      somemap {
        somekey = "somevalue"
      }
    }

The HCL parser always wraps an extra list around the map, so we need to
remove that extra list wrapper when the parameter is indeed of type "map".

Fixes #7140
2016-07-06 09:52:32 -05:00
Paul Hinze bf0e7705b1
core: Fix destroy when module vars used in provider config
For `terraform destroy`, we currently build up the same graph we do for
`plan` and `apply` and we do a walk with a special Diff that says
"destroy everything".

We have fought the interpolation subsystem time and again through this
code path. Beginning in #2775 we gained a new feature to selectively
prune out problematic graph nodes. The past chain of destroy fixes I
have been involved with (#6557, #6599, #6753) have attempted to massage
the "noop" definitions to properly handle the edge cases reported.

"Variable is depended on by provider config" is another edge case we add
here and try to fix.

This dive only makes me more convinced that the whole `terraform
destroy` code path needs to be reworked.

For now, I went with a "surgical strike" approach to the problem
expressed in #7047. I found a couple of issues with the existing
Noop and DestroyEdgeInclude logic, especially with regards to
flattening, but I'm explicitly ignoring these for now so we can get this
particular bug fixed ahead of the 0.7 release. My hope is that we can
circle around with a fully specced initiative to refactor `terraform
destroy`'s graph to be more state-derived than config-derived.

Until then, this fixes #7407
2016-06-11 21:21:08 -05:00
Chris Marchesi 2a679edd25 core: Fix destroy on nested module vars for count
Building on b10564a, adding tweaks that allow the module var count
search to act recursively, ensuring that a sitaution where something
like var.top gets passed to module middle, as var.middle, and then to
module bottom, as var.bottom, which is then used in a resource count.
2016-05-18 13:32:56 -05:00
Paul Hinze f33ef43195 core: Fix destroy when modules vars are used in resource counts
A new problem was introduced by the prior fixes for destroy
interpolation messages when resources depend on module variables with
a _count_ attribute, this makes the variable crucial for properly
building the graph - even in destroys. So removing all module variables
from the graph as noops was overzealous.

By borrowing the logic in `DestroyEdgeInclude` we are able to determine
if we need to keep a given module variable relatively easily.

I'd like to overhaul the `Destroy: true` implementation so that it does
not depend on config at all, but I want to continue for now with the
targeted fixes that we can backport into the 0.6 series.
2016-05-18 13:32:49 -05:00
Paul Hinze 559f017ebb
terraform: Correct fix for destroy interp errors
The fix that landed in #6557 was unfortunately the wrong subset of the
work I had been doing locally, and users of the attached bugs are still
reporting problems with Terraform v0.6.16.

At the very last step, I attempted to scope down both the failing test
and the implementation to their bare essentials, but ended up with a
test that did not exercise the root of the problem and a subset of the
implementation that was insufficient for a full bugfix.

The key thing I removed from the test was a _referencing output_ for the
module, which is what breaks down the #6557 solution.

I've re-tested the examples in #5440 and #3268 to verify this solution
does indeed solve the problem.
2016-05-10 15:58:51 -05:00
Paul Hinze 8223e606df
terraform: add debug logging to Noop impls
This sort of output is needed to debug these codepaths anyways, so I
figured might as well leave it in.
2016-05-10 15:58:46 -05:00
James Nugent e57a399d71 core: Use native HIL maps instead of flatmaps
This changes the representation of maps in the interpolator from the
dotted flatmap form of a string variable named "var.variablename.key"
per map element to use native HIL maps instead.

This involves porting some of the interpolation functions in order to
keep the tests green, and adding support for map outputs.

There is one backwards incompatibility: as a result of an implementation
detail of maps, one could access an indexed map variable using the
syntax "${var.variablename.key}".

This is no longer possible - instead HIL native syntax -
"${var.variablename["key"]}" must be used. This was previously
documented, (though not heavily used) so it must be noted as a backward
compatibility issue for Terraform 0.7.
2016-05-10 14:49:13 -04:00
James Nugent d7d39702c0 Type check variables between modules (#6185)
These tests demonstrates a problem where the types to a module input are 
not checked. For example, if a module - inner - defines a variable
"should_be_a_map" as a map, or with a default variable of map, we do not
fail if the user sets the variable value in the outer module to a string
value. This is also a problem in nested modules.

The implementation changes add a type checking step into the graph
evaluation process to ensure invalid types are not passed.
2016-04-15 12:07:54 -07:00
Mitchell Hashimoto 4d361c839e terraform: prune resources and variables 2015-07-20 08:57:34 -07:00
Mitchell Hashimoto 6752ccfe10 terraform: only include variables in graph if count of a resource
depends
2015-05-07 10:50:56 -07:00
Mitchell Hashimoto 6b2e0b938d terraform: only omit vars on full destroys 2015-05-06 20:55:14 -07:00
Mitchell Hashimoto 19b33326be terraform: don't include variables in destroy node requirements 2015-05-06 20:13:19 -07:00
Mitchell Hashimoto c207beda36 terraform: set variables in the proper location 2015-05-01 16:29:19 -07:00
Mitchell Hashimoto 86d07d3b5b terraform: redo how flattening works 2015-05-01 15:18:40 -07:00
Mitchell Hashimoto 9a54dddc85 terraform: eval for variables 2015-05-01 14:10:41 -07:00
Mitchell Hashimoto e544e1d401 terraform: hook up the proxies 2015-05-01 11:45:42 -07:00
Mitchell Hashimoto dd14ce9a0b terraform: test that variable deps reach out to parent graph 2015-05-01 11:09:23 -07:00
Mitchell Hashimoto 3bfef7c374 terraform: wrap variable values and prefix dependencies
(untested yet)
2015-05-01 10:56:05 -07:00
Mitchell Hashimoto 1152ff562b terraform: add variables as graph nodes (no eval yet) 2015-04-30 16:27:20 -07:00