Commit Graph

126 Commits

Author SHA1 Message Date
Martin Atkins a270a18a4d command: Update tests for changes in "terraform" package
This is not exhaustive, but it gets the tests in this package compiling
again and gets most of them working.
2018-10-16 18:49:20 -07:00
James Bardin e980156451 cleanup temp files from command tests
Rather than try to modify all the hundreds of calls to the temp helper
functions, and cleanup the temp files at every call site, have all tests
work within a single temp directory that is removed at the end of
TestMain.
2018-03-28 13:08:38 -04:00
James Bardin ecd9ef0f77 ignore error in plan shutdown test
The error was being silently dropped before.

There is an interpolation error, because the plan is canceled before
some of the resources can be evaluated. There might be a better way to
handle this in the walk cancellation, but the behavior has not changed.

Make the plan and apply shutdown match implementation-wise
2018-02-12 11:56:54 -05:00
James Bardin 4b49a323c3 go fmt
slight change to go fmt coming in 0.10
2017-12-26 13:26:38 -05:00
James Bardin 2941ed464c replace the testShutdownHook with a check for Stop
Now that the local backend can be cancelled during plan and refresh, we
don't really need the testShutdownHook. Simplify the tests by just
checking for Stop being called on the provider.
2017-12-05 10:17:20 -05:00
James Bardin e2501d7830 make apply shutdown test completely deterministic
Add a shutdown hook to verify that a context has been correctly
cancelled, so we can remove the sleep and stop guessing.

Add a plan version of the shutdown test as well.
2017-12-01 15:56:49 -05:00
James Bardin 3aaa1e9d04 make plans cancellable
There was no cancellation context for a plan, so it would always have to
run to completion as SIGINT was being swallowed.

Move the shutdown channel to the command Meta since it's used in
multiple commands.
2017-12-01 13:14:44 -05:00
Martin Atkins 400038eda4 command: "terraform apply" uses interactive confirmation by default
In the 0.10 release we added an opt-in mode where Terraform would prompt
interactively for confirmation during apply. We made this opt-in to give
those who wrap Terraform in automation some time to update their scripts
to explicitly opt out of this behavior where appropriate.

Here we switch the default so that a "terraform apply" with no arguments
will -- if it computes a non-empty diff -- display the diff and wait for
the user to type "yes" in similar vein to the "terraform destroy" command.

This makes the commonly-used "terraform apply" a safe workflow for
interactive use, so "terraform plan" is now mainly for use in automation
where a separate planning step is used. The apply command remains
non-interactive when given an explicit plan file.

The previous behavior -- though not recommended -- can be obtained by
explicitly setting the -auto-approve option on the apply command line,
and indeed that is how all of the tests are updated here so that they can
continue to run non-interactively.
2017-11-01 06:54:39 -07:00
James Bardin fb397060eb add some Serial checks to apply and refresh tests 2017-07-05 18:18:28 -04:00
James Bardin 054716c397 use testStateRead helper in apply tests
We have a helper function that we hardly ever use.
TODO: convert the rest of the manual ReadState calls eventually.
2017-07-05 18:18:16 -04:00
James Bardin a30007b41d Merge pull request #15032 from hashicorp/jbardin/init
change init args to remove source copy
2017-06-12 09:06:32 -04:00
Martin Atkins 31d556894f command: shallow UI-focused rename of "environment" to "workspace"
Feedback after 0.9 was that the term "environment" was confusing due to
it colliding with several other concepts, such as OS environment
variables, a non-aligned Terraform Enterprise concept, and differing ideas
of "environment" within various organizations.

This new term "workspace" is intended to ease some of that confusion. This
term is not used anywhere else in Terraform today, and we expect it to not
be used in a manner that would be confusing within user organizations.

This begins a deprecation cycle for the "terraform env" family of commands,
instead moving to an equivalent set of "terraform workspace" commands.

There are some remaining references to the old "environment" concept in
the code, which will be cleaned up in a separate change. This change is
instead focused on text visible in the UI and wording within code comments
for the benefit of human maintainers of the code.
2017-06-09 15:01:39 -07:00
James Bardin 2bfcdbbd08 change init args to remove source copy
When init was modified in 0.9 to initialize a terraform working
directory, the legacy behavior was kept to copy or fetch module sources.
This left the init command without the ability that the plan and apply
commands have to target a specific directory for the operation.

This commit removes the legacy behavior altogether, and allows init to
target a directory for initialization, bringing it into parity with plan
and apply. If one want to copy a module to the target or current
directory, that will have to be done manually before calling init. We
can later reintroduce fetching modules with init without breaking this
new behavior, by adding the source as an optional second argument.

The unit tests testing the copying of sources with init have been
removed, as well as some out of date (and commented out) init tests
regarding remote states.
2017-06-09 17:50:14 -04:00
Martin Atkins 8364383c35 Push plugin discovery down into command package
Previously we did plugin discovery in the main package, but as we move
towards versioned plugins we need more information available in order to
resolve plugins, so we move this responsibility into the command package
itself.

For the moment this is just preserving the existing behavior as long as
there are only internal and unversioned plugins present. This is the
final state for provisioners in 0.10, since we don't want to support
versioned provisioners yet. For providers this is just a checkpoint along
the way, since further work is required to apply version constraints from
configuration and support additional plugin search directories.

The automatic plugin discovery behavior is not desirable for tests because
we want to mock the plugins there, so we add a new backdoor for the tests
to use to skip the plugin discovery and just provide their own mock
implementations. Most of this diff is thus noisy rework of the tests to
use this new mechanism.
2017-06-09 14:03:59 -07:00
Edward Betts be265479a9 correct spelling mistakes (#13979) 2017-04-27 02:10:04 +12:00
James Bardin 3d604851c2 test -lock-timeout from cli 2017-04-03 11:50:19 -04:00
James Bardin 2cffa25235 Add test to verify that Validation isn't called
The apply won't succeed because we don't have a valid plan, but this
verifies that providing a plan file prevents Validation.
2017-03-27 18:39:18 -04:00
Mitchell Hashimoto f7964194eb
command: fix odd formatting that snuck in 2017-03-13 16:41:33 -07:00
Mitchell Hashimoto d475fc29a8
command: test that terraform meta information is passed through 2017-03-13 16:31:35 -07:00
James Bardin ec00564be6 Clean up LockInfo and LockError and use them
Gove LockInfo a Marshal method for easy serialization, and a String
method for more readable output.

Have the state.Locker implementations use LockError when possible to
return LockInfo and an error.
2017-02-15 14:44:43 -05:00
James Bardin b80ae5e13e Add source path argument to testLockState
The new test pattern is to chdir into a temp location for the test, but
the prevents us from locating the testdata directory in the source. Add
a source path to testLockState so we can find the statelocker.go source.
2017-02-06 13:50:01 -05:00
James Bardin bd65ddbcaa Add test for apply/refresh on locked state files
Verify that these operations fail when a state file is locked.
2017-02-03 15:32:40 -05:00
James Bardin 6a20c35d61 apply-test 2017-02-03 14:55:21 -05:00
James Bardin 94f2f4d6ae Create state files first for backup tests
Previously when runnign a plan with no exitsing state, the plan would be
written out and then backed up on the next WriteState by another
BackupState instance. Since we now maintain a single State instance
thoughout an operation, the backup happens before any state exists so no
backup file is created.

This is OK, as the backup state the tests were checking for is from the
plan file, which already exists separate from the state.
2017-02-03 13:07:34 -05:00
Mitchell Hashimoto ad7b063262
command: convert to use backends 2017-01-26 14:33:49 -08:00
Mitchell Hashimoto 1248b147ac
command/meta: always ask for unset variable input
Fixes #7975

This changes the InputMode for the CLI to always be:

    InputModeProvider | InputModeVar | InputModeVarUnset

Which means:

  * Ask for provider variables
  * Ask for user variables _that are not already set_

The change is the latter point. Before, we'd only ask for variables if
zero were given. This forces the user to either have no variables set
via the CLI, env vars, tfvars or ALL variables, but no in between. As
reported in #7975, this isn't expected behavior.

The new change makes is so that unset variables are always asked for.
Users can retain the previous behavior by setting `-input=false`. This
would ensure that variables set by external sources cover all cases.
2016-11-01 19:16:43 -07:00
Mitchell Hashimoto 2019a44f04
command/apply: apply from plan respects -backup and -state-out
Fixes #5409

I didn't expect this to be such a rabbit hole!

Based on git history, it appears that for "historical reasons"(tm),
setting up the various `state.State` structures for a plan were
_completely different logic_ than a normal `terraform apply`. This meant
that it was skipping things like disabling backups with `-backup="-"`.

This PR unifies loading from a plan to the normal state setup mechanism.
A few tests that were failing prior to this PR were added, no existing
tests were changed.
2016-10-28 20:51:05 -04:00
James Bardin 54d50c90b1 Make TestApply_parallelism more reliable
Wait for our expected number of goroutines to be staged and ready, then
allow Run() to complete. Use a high-water-mark counter to ensure we
never exceeded the max expected concurrent goroutines at any point
during the run.
2016-10-17 18:26:16 -04:00
James Bardin cdb80f68a8 Ensure better state normalization
Fix checksum issue with remote state

If we read a state file with "null" objects in a module and they become
initialized to an empty map the state file may be written out with empty
objects rather than "null", changing the checksum. If we can detect
this, increment the serial number to prevent a conflict in atlas.

Our fakeAtlas test server now needs to decode the state directly rather
than using the ReadState function, so as to be able to read the state
unaltered.

The terraform.State data structures have initialization spread out
throughout the package. More thoroughly initialize State during
ReadState, and add a call to init() during WriteState as another
normalization safeguard.

Expose State.init through an exported Init() method, so that a new State
can be completely realized outside of the terraform package.
Additionally, the internal init now completely walks all internal state
structures ensuring that all maps and slices are initialized.  While it
was mentioned before that the `init()` methods are problematic with too
many call sites, expanding this out better exposes the entry points that
will need to be refactored later for improved concurrency handling.

The State structures had a mix of `omitempty` fields. Remove omitempty
for all maps and slices as part of this normalization process. Make
Lineage mandatory, which is now explicitly set in some tests.
2016-08-12 11:09:50 -04:00
James Bardin 6b5ee73e86 Use -state-out option when applying from a plan
When working from an existing plan, we weren't setting the PathOut field
for a LocalState. This required adding an outPath argument to the
StateFromPlan function to avoid having to introspect the returned
state.State interface to find the appropriate field.

To test we run a plan first and provide the new plan to apply with
`-state-out` set.
2016-07-01 14:18:51 -04:00
Sander van Harmelen d97b24e3c1
Add tests and fix last issues 2016-05-26 19:56:03 -05:00
James Nugent 6a20e8927d core: Fix issues from rebasing dev-0.7 onto master
- Fix sensitive outputs for lists and maps
- Fix test prelude which was missed during conflict resolution
- Fix `terraform output` to match old behaviour and not have outputs
  header and colouring
- Bump timeout on TestAtlasClient_UnresolvableConflict
2016-05-10 15:43:50 -04:00
Mitchell Hashimoto 35c87836b4 core: Add terraform_version to state
This adds a field terraform_version to the state that represents the
Terraform version that wrote that state. If Terraform encounters a state
written by a future version, it will error. You must use at least the
version that wrote that state.

Internally we have fields to override this behavior (StateFutureAllowed),
but I chose not to expose them as CLI flags, since the user can just
modify the state directly. This is tricky, but should be tricky to
represent the horrible disaster that can happen by enabling it.

We didn't have to bump the state format version since the absense of the
field means it was written by version "0.0.0" which will always be
older. In effect though this change will always apply to version 2 of
the state since it appears in 0.7 which bumped the version for other
purposes.
2016-05-10 14:40:11 -04:00
James Nugent b62f6af158 core: Add support for marking outputs as sensitive (#6559)
* core: Add support for marking outputs as sensitive

This commit allows an output to be marked "sensitive", in which case the
value is redacted in the post-refresh and post-apply list of outputs.

For example, the configuration:

```
variable "input" {
    default = "Hello world"
}

output "notsensitive" {
    value = "${var.input}"
}

output "sensitive" {
    sensitive = true
    value = "${var.input}"
}
```

Would result in the output:

```
terraform apply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

  notsensitive = Hello world
  sensitive    = <sensitive>
```

The `terraform output` command continues to display the value as before.

Limitations: Note that sensitivity is not tracked internally, so if the
output is interpolated in another module into a resource, the value will
be displayed. The value is still present in the state.
2016-05-09 15:46:07 -04:00
Paul Hinze 9428e9f1d1 command: fix failing TestPlan_noState test
Turns out that isolating statefiles in the Apply tests is an important
step to prevent leaking .tfstate in a common dir, which can affect other
tests.
2015-10-29 18:07:44 -05:00
Paul Hinze 715437537d command: fix flaky parallelism tests
Thanks to @mitchellh for helping sort out concurrency stuff here.
2015-10-29 15:16:34 -05:00
Kevin Nuckolls bf9c5c46d0 Tests for apply parallelism=1 and parallelism=2 2015-09-29 22:41:26 -07:00
Anthony Scalisi 198e1a5186 remove various typos 2015-09-11 11:56:20 -07:00
Mitchell Hashimoto 71315076c3 command: autoload terraform.tfvars.json as well [GH-1030] 2015-03-02 09:22:28 -08:00
Mitchell Hashimoto 8e76a02a56 command: disable backup with "-" [GH-1072]
/cc @phinze
2015-03-02 09:11:49 -08:00
Mitchell Hashimoto 0fcc417ddd command/apply: remove remote package 2015-02-23 15:13:55 -08:00
Emil Hessman b40c2fe997 command: fix test failure on Windows
URLs are `/`-based. Windows path Separator is `\`.
Convert `\` in test fixture path to `/` with filepath.ToSlash
such that proper URLs are constructed even on Windows.

Fixes a test failure on Windows.
2015-01-28 08:13:44 +01:00
Emil Hessman 92e68c1ee6 command: fix test failure on Windows
Adjust the laddr argument to net.Listen to the form host:port,
as documented for net.Dial.

Fixes a test failure on Windows.
2015-01-28 08:10:52 +01:00
Mitchell Hashimoto fb3f10efb0 command/apply: ask for user variables before validation [GH-736] 2015-01-16 10:46:38 -08:00
Armon Dadgar 408ae62306 command/apply: Handle remote state in a plan file 2015-01-07 13:08:32 -08:00
Mitchell Hashimoto 95f43d8230 command/apply: if with plan, don't ask for input [GH-346] 2014-10-01 08:43:00 -07:00
Mitchell Hashimoto 3572b8ff2f command/apply: allow `terraform apply SOURCE` as shortcut for init 2014-09-29 15:55:28 -07:00
Mitchell Hashimoto a36b3e1ec5 command: tests pass 2014-09-24 15:48:46 -07:00
Mitchell Hashimoto 91eb3c73fc command: fix failing tests 2014-09-18 18:16:09 -06:00
Mitchell Hashimoto 15564b04a5 command: tests pass 2014-09-18 10:40:35 -07:00
Mitchell Hashimoto 9b2b3a963f ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
Mitchell Hashimoto cdad3036ae command: closer to compiling 2014-09-17 11:15:07 -07:00
Mitchell Hashimoto 2caf33f97f command/apply: keep track of default variables separately [GH-153] 2014-08-24 21:40:58 -07:00
Mitchell Hashimoto 642fed0356 command: terraform.tfvars loaded by default if it exists 2014-08-05 09:32:01 -07:00
Armon Dadgar 16ef3f5733 command: Testing the -backup feature 2014-07-27 23:38:41 -04:00
Mitchell Hashimoto 795142c43c command/apply: -refresh flag 2014-07-26 17:51:16 -07:00
Mitchell Hashimoto 82e7d58250 command/apply: -init is gone
/cc @pearkes - hurray!
2014-07-26 14:44:05 -07:00
Mitchell Hashimoto 79033f240f command: error if variables present when creating context from plan 2014-07-26 14:32:09 -07:00
Mitchell Hashimoto dc0ec11ec9 command: fix tests 2014-07-22 19:43:09 -07:00
Mitchell Hashimoto 7b4119027a command: -var-file works 2014-07-18 14:00:40 -07:00
Mitchell Hashimoto 3534470ca3 command: -var flag works 2014-07-18 11:37:27 -07:00
Armon Dadgar 104b28e19e terraform: Remove ResourceConnectionInfo, use raw map 2014-07-15 12:34:07 -07:00
Mitchell Hashimoto 3a851bece0 command: convert all to use the new Meta thing 2014-07-12 20:37:30 -07:00
Mitchell Hashimoto 2c77837a64 command/apply: optional arg, default to pwd for config dir 2014-07-11 21:32:34 -07:00
Mitchell Hashimoto abc6df2a7d command/apply: default state path, only one optional arg 2014-07-11 21:30:40 -07:00
Mitchell Hashimoto 6a7e3668a2 command: apply saves state even if error occurs 2014-07-07 21:20:48 -07:00
Mitchell Hashimoto a6ae7230d1 command: use new API 2014-07-03 11:46:40 -07:00
Mitchell Hashimoto d23733263f command: validate configuration, test for it 2014-07-02 21:16:36 -07:00
Mitchell Hashimoto f1dce8f076 command: stabilize tests 2014-07-02 17:08:58 -07:00
Mitchell Hashimoto 5aa6ada589 command/apply: Ctrl-C works 2014-07-02 17:01:02 -07:00
Mitchell Hashimoto 2729050d19 command: fix failing tests 2014-06-30 20:49:49 -07:00
Mitchell Hashimoto fe79e5df03 command/apply: can take a plan as an argument 2014-06-27 14:43:33 -07:00
Mitchell Hashimoto 344fd805f4 command/apply: fail if state doesn't exist and no -init 2014-06-19 12:17:56 -07:00
Mitchell Hashimoto 879921d70f command/apply: test that diff runs with existing state 2014-06-19 12:13:47 -07:00
Mitchell Hashimoto d4994b5d44 command/apply: read existing state 2014-06-19 12:12:24 -07:00
Mitchell Hashimoto 82af81b606 command: tests for apply 2014-06-18 21:36:44 -07:00