Commit Graph

259 Commits

Author SHA1 Message Date
Martin Atkins
c12d64f340 Use t.Helper() in our test helpers
Go 1.9 adds this new function which, when called, marks the caller as
being a "helper function". Helper function stack frames are then skipped
when trying to find a line of test code to blame for a test failure, so
that the code in the main test function appears in the test failure output
rather than a line within the helper function itself.

This covers many -- but probaly not all -- of our test helpers across
various packages.
2017-08-28 09:59:30 -07: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
Mitchell Hashimoto
864c79396d
terraform: default shadow to false
To avoid chasing down issues like #11635 I'm proposing we disable the
shadow graph for end users now that we have merged in all the new
graphs. I've kept it around and default-on for tests so that we can use
it to test new features as we build them. I think it'll still have value
going forward but I don't want to hold us for making it work 100% with
all of Terraform at all times.

I propose backporting this to 0-8-stable, too.
2017-02-06 18:02:32 -08:00
Mitchell Hashimoto
d3df7874d5
terraform: introduce EvalApplyPre so that PreApply is called even for
destroy provisioners.
2017-01-20 20:36:53 -08:00
Mitchell Hashimoto
89f7e3b79f
terraform: add module vars after providers to see references
Fixes #10711

The `ModuleVariablesTransformer` only adds module variables in use. This
was missing module variables used by providers since we ran the provider
too late. This moves the transformer and adds a test for this.
2016-12-13 21:22:21 -08:00
Mitchell Hashimoto
cabcc4b5b8
terraform: allow indexing into a computed list for multi-count resources
Fixes #8695

When a list count was computed in a multi-resource access
(foo.bar.*.list), we were returning the value as empty string. I don't
actually know the histocal reasoning for this but this can't be correct:
we must return unknown.

When changing this to unknown, the new tests passed and none of the old
tests failed. This leads me further to believe that the return empty
string is probably a holdover from long ago to just avoid crashes or
UUIDs in the plan output and not actually the correct behavior.
2016-12-10 19:17:29 -05:00
Mitchell Hashimoto
f50c7acf95
terraform: record dependency to self (other index)
Fixes #10313

The new graph wasn't properly recording resource dependencies to a
specific index of itself. For example: `foo.bar.2` depending on
`foo.bar.0` wasn't shown in the state when it should've been.

This adds a test to verify this and fixes it.
2016-11-23 09:25:20 -08:00
Mitchell Hashimoto
538302f143
terraform: resources nested within a module must also be depended on
For example: A => B => C (modules). If A depends on module B, then it
also must depend on everything in module C.
2016-11-12 15:38:28 -08:00
Mitchell Hashimoto
0b87ef82c3
terraform: depends_on can reference entire modules 2016-11-12 08:07:45 -08:00
Mitchell Hashimoto
f580a8ed7b Merge pull request #9894 from hashicorp/b-provider-alias
terraform: configure provider aliases in the new apply graph
2016-11-07 07:59:33 -08:00
Mitchell Hashimoto
b7954a42fe
terraform: remove pruning of module vars if they ref non-existing nodes
Fixes a shadow graph error found during usage.

The new apply graph was only adding module variables that referenced
data that existed _in the graph_. This isn't a valid optimization since
the data it is referencing may be in the state with no diff, and
therefore available but not in the graph.

This just removes that optimization logic, which causes no failing
tests. It also adds a test that exposes the bug if we had the pruning
logic.
2016-11-04 17:47:20 -07:00
Mitchell Hashimoto
d7ed6637c1
terraform: configure provider aliases in the new apply graph
Found via a shadow graph failure:

Provider aliases weren't being configured by the new apply graph.

This was caused by the transform that attaches configs to provider nodes
not being able to handle aliases and therefore not attaching a config.
Added a test to this and fixed it.
2016-11-04 16:51:52 -07:00
Mitchell Hashimoto
d2e9c35007
terraform: new apply graph creates provisioners in modules
Fixes #9840

The new apply graph wasn't properly nesting provisioners. This resulted
in reading the provisioners being nil on apply in the shadow graph which
caused the crash in the above issue.

The actual cause of this is that the new graphs we're moving towards do
not have any "flattening" (they are flat to begin with): all modules are
in the root graph from the beginning of construction versus building a
number of different graphs and flattening them. The transform that adds
the provisioners wasn't modified to handle already-flat graphs and so
was only adding provisioners to the root module, not children.

The change modifies the `MissingProvisionerTransformer` (primarily) to
support already-flat graphs and add provisioners for all module levels.
Tests are there to cover this as well.

**NOTE:** This PR focuses on fixing that specific issue. I'm going to follow up
this PR with another PR that is more focused on being robust against
crashing (more nil checks, recover() for shadow graph, etc.). In the
interest of focus and keeping a PR reviewable this focuses only on the
issue itself.
2016-11-03 10:25:11 -07:00
Mitchell Hashimoto
9e5d1f10b0
terraform: add test to verify orphan outputs in modules are removed
For #7598

This doesn't work with the old graph, we guard it as such.
2016-11-01 22:42:41 -07:00
Mitchell Hashimoto
c21610f533
terraform: for tempEnv, if the var wans't set before, unset
This was causing flaky behavior in our tests because `TF_VAR_x=""` is
actually a valid env var. For tests, we need to actually unset env vars
that haven't been set before.
2016-10-31 11:01:05 -07:00
Mitchell Hashimoto
69b32223b8 Merge pull request #9633 from hashicorp/f-experiment
helper/experiment: a helper for setting, making experiments
2016-10-27 11:22:07 -04:00
Mitchell Hashimoto
f142978456
terraform: add test to verify tainted resources don't process
ignore_changes

For #7855
2016-10-27 08:44:59 -04:00
Mitchell Hashimoto
af82be19ea
helper/experiment: a helper for setting, making experiments
This creates a standard package and interface for defining, querying,
setting experiments (`-X` flags).

I expect we'll want to continue to introduce various features behind
experimental flags. I want to make doing this as easy as possible and I
want to make _removing_ experiments as easy as possible as well.

The goal with this packge has been to rely on the compiler enforcing our
experiment references as much as possible. This means that every
experiment is a global variable that must be referenced directly, so
when it is removed you'll get compiler errors where the experiment is
referenced.

This also unifies and makes it easy to grab CLI flags to enable/disable
experiments as well as env vars! This way defining an experiment is just
a couple lines of code (documented on the package).
2016-10-26 15:47:58 -04:00
Mitchell Hashimoto
aed23a0a31 Merge pull request #9527 from hashicorp/f-destroy-builder2
terraform: destroy graph builder based on state
2016-10-26 12:53:20 -04:00
Mitchell Hashimoto
eb20db92cf
terraform: test that data sources can reference other data sources 2016-10-23 18:53:00 -07:00
Mitchell Hashimoto
ceb613d449
terraform: don't set destroy module on diff
This is something that should be determined and done during an apply. It
doesn't make a lot of sense that the plan is doing it (in its current
form at least).
2016-10-22 12:12:30 -07:00
Mitchell Hashimoto
db807f4b0f
terraform: destroy graph builder, -Xnew-destroy flag 2016-10-22 12:12:29 -07:00
Mitchell Hashimoto
1d27e554a5
terraform: test to ensure data sources work on Apply operation
It appears data sources have always been coded to work during apply, as
can be verified with this test (no impl. changes were necessary to make
it pass).

This test should be added to ensure our apply graph always works with
data sources as well.
2016-10-20 21:53:54 -07:00
Mitchell Hashimoto
2c1a21a8ef
terraform: disable shadowing the experimental graph 2016-10-20 15:17:28 -07:00
Mitchell Hashimoto
ec15783f24
-Xnew-apply to enable the new apply graph 2016-10-19 13:39:28 -07:00
Mitchell Hashimoto
eb9ecea863
terraform: don't set Provider on destroy nodes
This doesn't explicitly set `rs.Provider` on destroy nodes.

To be honest, I'm not sure why this was done in the first place (git
blame points to 6fda7bb5483a155b8ae1e1e4e4b7b7c4073bc1d9). Tests always
passed without it, and by adding it it causes other tests to fail. I
should've never changed those other tests.

Removing it now to get tests passing, this also reverts the test changes
made in 8213824962f085279810f04b60b95d1176a3a3f2.
2016-10-19 13:39:13 -07:00
Mitchell Hashimoto
c1664d2eaa
terraform: cbd works! 2016-10-19 13:38:53 -07:00
Mitchell Hashimoto
f7134d95e4
terraform: Diff.DeepCopy 2016-10-11 22:17:28 +08:00
Mitchell Hashimoto
9ae9f208d1
terraform: Context knows how to walk a shadow graph and report errors 2016-10-11 22:17:28 +08:00
Sander van Harmelen
47dd1ad153 Add wildcard (match all) support to ignore_changes (#8599) 2016-09-02 15:44:35 +02:00
Mitchell Hashimoto
60f212b73e
terraform: test for referencing counts that are from vars 2016-08-31 11:54:14 -07:00
Mitchell Hashimoto
d2e15ab69a
terraform: add test explicitly for referencing count 2016-08-31 11:49:25 -07:00
Mitchell Hashimoto
cc5abd0815
terraform: add tests for variables 2016-08-17 11:28:58 -07:00
James Bardin
2e5791ab2b Allow the HCL input when prompted
We already accept HCL encoded input for -vars, and this expands that to
accept HCL when prompted for a value on the command line as well.
2016-08-10 11:14:31 -04:00
James Bardin
1af7ee87a2 Silence log output when not verbose
Set the default log package output to iotuil.Discard during tests if the
`-v` flag isn't set. If we are verbose, then apply the filter according
to the TF_LOG env variable.
2016-08-01 17:19:14 -04:00
James Nugent
681d94ae20 core: Allow lists and maps as variable overrides
Terraform 0.7 introduces lists and maps as first-class values for
variables, in addition to string values which were previously available.
However, there was previously no way to override the default value of a
list or map, and the functionality for overriding specific map keys was
broken.

Using the environment variable method for setting variable values, there
was previously no way to give a variable a value of a list or map. These
now support HCL for individual values - specifying:

    TF_VAR_test='["Hello", "World"]'

will set the variable `test` to a two-element list containing "Hello"
and "World". Specifying

    TF_VAR_test_map='{"Hello = "World", "Foo" = "bar"}'

will set the variable `test_map` to a two-element map with keys "Hello"
and "Foo", and values "World" and "bar" respectively.

The same logic is applied to `-var` flags, and the file parsed by
`-var-files` ("autoVariables").

Note that care must be taken to not run into shell expansion for `-var-`
flags and environment variables.

We also merge map keys where appropriate. The override syntax has
changed (to be noted in CHANGELOG as a breaking change), so several
tests needed their syntax updating from the old `amis.us-east-1 =
"newValue"` style to `amis = "{ "us-east-1" = "newValue"}"` style as
defined in TF-002.

In order to continue supporting the `-var "foo=bar"` type of variable
flag (which is not valid HCL), a special case error is checked after HCL
parsing fails, and the old code path runs instead.
2016-07-26 15:27:29 -05:00
James Nugent
56aadab115 core: Add context test for module var from splat
This adds additional coverage of the situation reported in #7195 to
prevent against regression. The actual fix was in 2356afd, in response
to #7143.
2016-07-13 11:23:56 -06:00
James Nugent
088feb933f terraform: Add test case reproducing #7241
The reproduction of issue #7421 involves a list of maps being passed to
a module, where one or more of the maps has a value which is computed
(for example, from another resource). There is a failure at the point of
use (via lookup interpolation) of the computed value of the form:

```
lookup: lookup failed to find 'elb' in:
${lookup(var.services[count.index], "elb")}
```

Where 'elb' is the key of the map.
2016-07-08 16:43:42 +01:00
Paul Hinze
1a4bd24e1a
terraform: add test helper for inline config loading
In scenarios with a lot of small configs, it's tedious to fan out actual
dir trees in a test-fixtures dir. It also spreads out the context of the
test - requiring the reader fetch a bunch of scattered 3 line files in
order to understand what is being tested.

Our config loading code still only reads from disk, but in
the `helper/resource` acc test framework we work around this by writing
inline config to temp files and loading it from there. This helper is
based on that strategy.

Eventually it'd be great to be able to build up a `module.Tree` from
config directly, but this gets us the functionality today.

Example Usage:

    testModuleInline(t, map[string]string{
      "top.tf": `
        module "middle" {
          source = "./middle"
        }
      `,
      "middle/mid.tf": `
        module "bottom" {
          source = "./bottom"
          amap {
            foo = "bar"
          }
        }
      `,
      "middle/bottom/bot.tf": `
        variable "amap" {
          type = "map"
        }
      `,
    }),
2016-07-06 09:12:19 -05:00
Sander van Harmelen
d97b24e3c1
Add tests and fix last issues 2016-05-26 19:56:03 -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
bc6107508d Fix additional vet warnings 2016-02-17 11:59:50 -08:00
Mitchell Hashimoto
54de9057ba terraform: failing test case 2016-01-19 12:37:55 -08:00
James Nugent
2a0334125c Add test attempting to reproduce #2598
This attempts to reproduce the issue described in #2598 whereby outputs
added after an apply are not reflected in the output. As per the issue
the outputs are described using the JSON syntax.
2015-11-09 15:27:09 -05:00
Mitchell Hashimoto
263cc1b855 terraform: final failing test 2015-10-15 13:52:27 -07:00
Rob Zienert
a1939e70f7 Adding ignore_changes lifecycle meta property 2015-10-14 16:34:27 -05:00
Mitchell Hashimoto
61d275f475 terraform: get nested oprhans in the transform 2015-07-19 13:53:31 -07:00
Mitchell Hashimoto
51a7e05f8a terraform: all providers for ProvidedBy() should be added 2015-06-26 12:00:02 -07:00
Mitchell Hashimoto
29eadb8194 terraform: missing provider should add missing aliases [GH-2023] 2015-06-24 20:58:52 -07:00
Sander van Harmelen
c62370f9e9 Add a function to load JSON directly
Without this 12 line function it’s impossible to use any of the
Terraform code without the need for having the files on disk. As more
and more people are using (parts of) Terraform in other software, this
seems to be a very welcome addition. It has no negative impact on
Terraform itself whatsoever (the function is never called), but it
opens up a lot of other use cases.

Next to the single new function, I renamed the existing function (and
related tests) to better reflect what the function does. So now there
is a `LoadDir` function which calls `LoadFile` for each file, which
kind of made sense to me, especially when now adding a `LoadJSON`
function as well.

But of course if the rename is a problem, I can revert that part as
it’s not related to the added `LoadJSON` function.

Thanks!
2015-06-23 16:15:26 +02:00
Mitchell Hashimoto
19b33326be terraform: don't include variables in destroy node requirements 2015-05-06 20:13:19 -07:00
Mitchell Hashimoto
6afc14982a terraform: destroy transform must happen globally 2015-05-02 18:21:00 -07:00
Mitchell Hashimoto
873f5a91bb terraform: EvalDeleteOutput and context test 2015-04-29 11:27:12 -07:00
Mitchell Hashimoto
5ae9ee4d27 terraform: allow TF_VAR_name to be set to set variables 2015-04-22 06:31:53 +02:00
Matt Good
21b0a03d70 Support for multiple providers of the same type
Adds an "alias" field to the provider which allows creating multiple instances
of a provider under different names. This provides support for configurations
such as multiple AWS providers for different regions. In each resource, the
provider can be set with the "provider" field.

(thanks to Cisco Cloud for their support)
2015-04-20 14:14:34 -07:00
Mitchell Hashimoto
b64fd8401c terraform: prune tainted destroys if no tainted in state [GH-1475] 2015-04-14 10:48:45 -07:00
Mitchell Hashimoto
2dce764d75 terraform: add input mode to only ask for unset variables
This adds a new input mode for Context.Input() that will only ask for
variable values that are not set.
2015-03-24 13:30:21 -07:00
Paul Hinze
6c93fbb85d core: [refactor] store Deposed resource instances as a list
Deposed instances need to be stored as a list for certain pathological
cases where destroys fail for some reason (e.g. upstream API failure,
Terraform interrupted mid-run). Terraform needs to be able to remember
all Deposed nodes so that it can clean them up properly in subsequent
runs.

Deposed instances will now never touch the Tainted list - they're fully
managed from within their own list.

Added a "multiDepose" test case that walks through a scenario to
exercise this.
2015-03-04 12:25:59 -06:00
Mitchell Hashimoto
11d073f7d4 terraform: test the increase from one case 2015-03-01 21:39:48 -08:00
Mitchell Hashimoto
2389251c38 terraform: catch scenario where both "foo" and "foo.0" are in state 2015-03-01 21:28:41 -08:00
Mitchell Hashimoto
341be226f4 terraform: test for various taint cases 2015-02-26 09:50:18 -08:00
Mitchell Hashimoto
dd7bc5db0c terraform: more self tests 2015-02-23 15:02:26 -08:00
Mitchell Hashimoto
0e59acc2c9 terraform: enable self vars 2015-02-23 14:56:02 -08:00
Mitchell Hashimoto
022967acdb terraform: module inputs/vars can be non-strings [GH-819] 2015-02-23 13:50:53 -08:00
Mitchell Hashimoto
4b6f258f1f terraform: only depose state if we're doing the destroy side 2015-02-19 12:08:34 -08:00
Mitchell Hashimoto
459ad04d71 terraform: provider cache should append the provider name to it 2015-02-19 12:08:33 -08:00
Mitchell Hashimoto
b8ebcc85d7 terraform: partial state works properly 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
5f8d1b86d5 terraform: more passing tests 2015-02-19 12:08:07 -08:00
Mitchell Hashimoto
6bb3cb8f2f terraform: a lot more passing tests 2015-02-19 12:08:06 -08:00
Mitchell Hashimoto
a3e4b3e966 terraform: more apply tests 2015-02-19 12:08:05 -08:00
Mitchell Hashimoto
d24082da1e config: validate that module variables can go to ints, convert [GH-624] 2014-12-15 22:10:16 -08:00
Luke Amdor
6dcb7166d1 fix destroy so incoming module vars get set 2014-12-05 17:18:45 -06:00
Luke Amdor
fead5872e5 Fix for multivars when modulestate not created yet 2014-12-02 13:53:09 -06:00
Luke Amdor
60022978a6 adding context test for module multi-vars 2014-11-28 13:16:33 -06:00
Armon Dadgar
a5d444b8e3 terraform: fix module output handling. Fixes #474 2014-11-24 19:18:52 -08:00
Armon Dadgar
f26b8df92f Merge pull request #598 from hashicorp/f-mod-deps
Fix dependency handling of modules
2014-11-24 18:53:22 -08:00
Armon Dadgar
5b025c89f9 terraform: guard output types. Fixes #593 2014-11-24 16:49:38 -08:00
Armon Dadgar
d8ecb32a7c terraform: test module is marked for destroy 2014-11-24 15:50:15 -08:00
Mitchell Hashimoto
bf7c40d115 terraform: test case for variable count 2014-10-17 18:03:30 -07:00
Mitchell Hashimoto
35352a2746 terraform: some more test cases for sanity 2014-10-16 23:20:46 -07:00
Mitchell Hashimoto
82bf4f485b terraform: taint resources who error on create with provisioners
[GH-434]
2014-10-16 23:19:07 -07:00
Mitchell Hashimoto
f59e89ccb8 terraform: add count tainted apply test 2014-10-12 09:41:27 -07:00
Mitchell Hashimoto
36f225dea0 fmt 2014-10-10 14:50:35 -07:00
Mitchell Hashimoto
6c96e0f6ac terraform: nil out the Diff on a resource when expanding
This fixes a bug where the Destroy diff was being kept around for
nodes that shouldn't be destroyed. We added a test to verify this
doesn't happen.
2014-10-09 23:15:42 -07:00
Mitchell Hashimoto
8b5c120ecf terraform: add InputMode to determine what is asked for 2014-10-08 10:18:45 -07:00
Mitchell Hashimoto
d714c6f2f1 terraform: test path variables 2014-10-07 20:09:30 -07:00
Mitchell Hashimoto
88ac1b030a terraform: another test for count index 2014-10-02 22:07:23 -07:00
Mitchell Hashimoto
ea18b62e8f terraform: count.index 2014-10-02 22:02:59 -07:00
Mitchell Hashimoto
66c58788fe terraform: test count = 1 variable access 2014-10-02 17:24:22 -07:00
Mitchell Hashimoto
221e40a3a9 terraform: test count == zero 2014-10-02 17:18:40 -07:00
Mitchell Hashimoto
ced4125037 teraform: test that count can be a variable 2014-10-02 15:47:00 -07:00
Armon Dadgar
5207e1d268 terraform: test ordering when using create before with depedencies 2014-09-29 17:00:45 -07:00
Armon Dadgar
bce9b664d8 terraform: test happy path create-before-destroy 2014-09-29 15:20:04 -07:00
Armon Dadgar
465f3f2676 terraform: test create-before-destroy with failed destroy 2014-09-29 15:20:03 -07:00
Armon Dadgar
59b7cb171a terraform: Testing failed apply with create_before_destroy 2014-09-29 15:20:03 -07:00
Armon Dadgar
f248ae3aee terraform: test provising fail create-before-destroy 2014-09-29 15:20:03 -07:00
Mitchell Hashimoto
2791badf01 terraform: ask for input for providers 2014-09-29 09:13:15 -07:00
Mitchell Hashimoto
fd70e5e7bf terraform: Input() asks for variable inputs 2014-09-28 23:37:36 -07:00
Mitchell Hashimoto
0d1867c0b3 Merge branch 'f-module-apply'
Conflicts:
	terraform/context.go
2014-09-26 10:08:35 -07:00