Commit Graph

158 Commits

Author SHA1 Message Date
Martin Atkins 9a5c865040 command: validate config as part of loading it
Previously we required callers to separately call .Validate on the root
module to determine if there were any value errors, but we did that
inconsistently and would thus see crashes in some cases where later code
would try to use invalid configuration as if it were valid.

Now we run .Validate automatically after config loading, returning the
resulting diagnostics. Since we return a diagnostics here, it's possible
to return both warnings and errors.

We return the loaded module even if it's invalid, so callers are free to
ignore returned errors and try to work with the config anyway, though they
will need to be defensive against invalid configuration themselves in
that case.

As a result of this, all of the commands that load configuration now need
to use diagnostic printing to signal errors. For the moment this just
allows us to return potentially-multiple config errors/warnings in full
fidelity, but also sets us up for later when more subsystems are able
to produce rich diagnostics so we can show them all together.

Finally, this commit also removes some stale, commented-out code for the
"legacy" (pre-0.8) graph implementation, which has not been available
for some time.
2017-12-07 14:28:43 -08: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
Martin Atkins 6f7bc4f5d7 command: use c.showDiagnostics for backend operation errors
This allows richer diagnostics produced by some subsystems to be displayed
in full-fidelity to the user.
2017-10-16 17:53:06 -07:00
Martin Atkins 5cd00a13ec command: use new diagnostics output for config errors
This uses the new diagnostics printer for config-related errors in the
main five commands that deal with config.

The immediate motivation for this is to allow HCL2-produced diagnostics
to be printed out in their full fidelity, though it also slightly changes
the presentation of other errors so that they are not presented in all
red text, which can be hard to read on some terminals.
2017-10-06 11:46:07 -07:00
Robert Liebowitz 8d98fdecac Autoload only .auto.tfvars files 2017-07-05 17:24:17 -07:00
Robert Liebowitz 006744bfe0 Use all tfvars files in working directory
As a side effect, several commands that previously did not have a failure
state can now fail during meta-parameter processing.
2017-07-05 17:24:17 -07:00
David Glasser 14af879fe0 command: also print plan for destroy 2017-06-27 11:22:31 -07:00
David Glasser 039d36bf91 command: add "apply -auto-approve=false" flag
A common reason to want to use `terraform plan` is to have a chance to
review and confirm a plan before running it.  If in fact that is the
only reason you are running plan, this new `terraform apply -auto-approve=false`
flag provides an easier alternative to

    P=$(mktemp -t plan)
    terraform refresh
    terraform plan -refresh=false -out=$P
    terraform apply $P
    rm $P

The flag defaults to true for now, but in a future version of Terraform it will
default to false.
2017-06-27 11:22:26 -07:00
James Bardin 000e860706 Add plugin dir scaffolding
add pluginDir to command.Meta, the flag to initialize it, and the
methods to save and restore it.
2017-06-15 14:26:12 -04:00
James Bardin 718ede0636 have Meta.Backend use a Config rather than loading
Instead of providing the a path in BackendOpts, provide a loaded
*config.Config instead. This reduces the number of places where
configuration is loaded.
2017-06-09 14:03:59 -07:00
James Bardin 6ef7c83ec5 add data-loss warning to SIGINT handler in apply
Warning user about data loss after receiving an interrupt.
2017-04-25 11:43:59 -04:00
James Bardin 5eca913b14 add cli flags for -lock-timeout
Add the -lock-timeout flag to the appropriate commands.
Add the -lock flag to `init` and `import` which were missing it.
Set both stateLock and stateLockTimeout in Meta.flagsSet, and remove the
extra references for clarity.
2017-04-01 17:09:21 -04:00
Mitchell Hashimoto a5ab6e447b command/apply: update help text to be "parallel" instead of concurrent 2017-02-08 11:49:08 -08:00
James Bardin eb8e5ac739 Change CLI flag to '-lock' 2017-02-06 10:07:32 -05:00
James Bardin 07903189f1 s/Meta.lockState/Meta.stateLock/g 2017-02-06 09:58:04 -05:00
James Bardin a157ebbccd add -lock-state usage to plan/refresh/apply/destr 2017-02-03 14:17:17 -05:00
James Bardin 9cdba1f199 enable local state locking for apply
Have the LocalBackend lock the state during operations, and enble this
for the apply comand.
2017-02-02 18:08:28 -05:00
Mitchell Hashimoto ad7b063262
command: convert to use backends 2017-01-26 14:33:49 -08:00
Mitchell Hashimoto 785cc7b78a
terraform: default new graphs on, old graphs behind -Xlegacy-graph
This turns the new graphs on by default and puts the old graphs behind a
flag `-Xlegacy-graph`. This effectively inverts the current 0.7.x
behavior with the new graphs.

We've incubated most of these for a few weeks now. We've found issues
and we've fixed them and we've been using these graphs internally for
awhile without any major issue. Its time to default them on and get them
part of a beta.
2016-11-10 21:53:20 -08:00
Mitchell Hashimoto 57c0cadc79 Merge pull request #9666 from hashicorp/jbardin/debug
preliminary debug output
2016-11-04 09:03:58 -07:00
James Bardin 797a1b339d DebugInfo and DebugGraph
Implement debugInfo and the DebugGraph

DebugInfo will be a global variable through which graph debug
information can we written to a compressed archive. The DebugInfo
methods are all safe for concurrent use, and noop with a nil receiver.
The API outside of the terraform package will be to call SetDebugInfo
to create the archive, and CloseDebugInfo() to properly close the file.
Each write to the archive will be flushed and sync'ed individually, so
in the event of a crash or a missing call to Close, the archive can
still be recovered.

The DebugGraph is a representation of a terraform Graph to be written to
the debug archive, currently in dot format. The DebugGraph also contains
an internal buffer with Printf and Write methods to add to this buffer.
The buffer will be written to an accompanying file in the debug archive
along with the graph.

This also adds a GraphNodeDebugger interface. Any node implementing
`NodeDebug() string` can output information to annotate the debug graph
node, and add the data to the log. This interface may change or be
removed to provide richer options for debugging graph nodes.

The new graph builders all delegate the build to the BasicGraphBuilder.
Having a Name field lets us differentiate the actual builder
implementation in the debug graphs.
2016-11-04 11:30:51 -04:00
Mitchell Hashimoto d429e82661
command: show shadow errors to the user 2016-11-03 18:14:07 -07:00
Mitchell Hashimoto 6c801d0386
command/apply: add additional nil check to loading state for outputs 2016-11-02 22:33:49 -07: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 1a418c1452
command/apply: -Xnew-destroy 2016-10-22 12:36:47 -07:00
Mitchell Hashimoto e8516f259d
command/apply: Xnew-apply 2016-10-19 13:39:28 -07:00
Radek Simko 8494cad8c4 Output 'destroy complete' when it's destroy (was: apply) (#8453) 2016-08-25 22:26:40 +01:00
James Nugent 0e4e94a86f core: Fix -module for terraform output command
The behaviour whereby outputs for a particular nested module can be
output was broken by the changes for lists and maps. This commit
restores the previous behaviour by passing the module path into the
outputsAsString function.

We also add a new test of this since the code path for indivdual output
vs all outputs for a module has diverged.
2016-07-29 16:39:59 -05:00
James Nugent 3ea3c657b5 core: Use OutputState in JSON instead of map
This commit forward ports the changes made for 0.6.17, in order to store
the type and sensitive flag against outputs.

It also refactors the logic of the import for V0 to V1 state, and
fixes up the call sites of the new format for outputs in V2 state.

Finally we fix up tests which did not previously set a state version
where one is required.
2016-05-18 13:25:20 -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
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 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
David Glasser b44f7f28e0 Document saved plan use in `terraform apply -help` (#6126)
Wording borrowed from the website docs.
2016-04-11 12:24:08 -05:00
Jake Champlin 39e7f42490 Clear up `destroy --target` message
When destroying infrastructure with `--target`, print out which
infrastructure will be destroyed instead of saying `Terraform will
delete all your managed infrastructure`.

```
 terraform destroy --target aws_instance.test2 --target aws_instance.test1
Do you really want to destroy?
  Terraform will delete the following infrastructure:
        aws_instance.test2
        aws_instance.test1
  There is no undo. Only 'yes' will be accepted to confirm
```

Omitting `--target` arguments will use the default input description.

```
$ terraform destroy
Do you really want to destroy?
  Terraform will delete all your managed infrastructure.
  There is no undo. Only 'yes' will be accepted to confirm.
```
2015-11-11 12:04:58 -05:00
Mitchell Hashimoto 344e7c26b5 fix a bunch of tests from go-getter import 2015-10-15 13:48:58 -07:00
Paul Hinze 374070d066 website: docs for parallelism setting
/cc @stack72 @knuckolls @mitchellh
2015-10-05 17:21:29 -05:00
Paul Hinze e1a46904d6 command: pull parallelism default up to CLI layer
/cc @knuckolls @josephholsten
2015-10-05 15:06:08 -05:00
Kevin Nuckolls f59c71b35a works for apply, no tests yet 2015-09-29 22:41:26 -07:00
Anthony Scalisi 198e1a5186 remove various typos 2015-09-11 11:56:20 -07:00
Paul Hinze ad680b1832 core: show outputs after `terraform refresh`
closes #25
2015-06-15 10:41:42 -05:00
Paul Hinze 18924d24fe command/apply: flatten multierrors
Before:

```
Error applying plan:

1 error(s) occurred:

* 1 error(s) occurred:

* 1 error(s) occurred:

* 1 error(s) occurred:

* Error creating ...
```

After:

```
Error applying plan:

1 error(s) occurred:

* Error creating ...
```

Muuuch better! :D
2015-06-07 21:32:00 -05:00
Paul Hinze 97acccd3ed core: targeted operations
Add `-target=resource` flag to core operations, allowing users to
target specific resources in their infrastructure. When `-target` is
used, the operation will only apply to that resource and its
dependencies.

The calculated dependencies are different depending on whether we're
running a normal operation or a `terraform destroy`.

Generally, "dependencies" refers to ancestors: resources falling
_before_ the target in the graph, because their changes are required to
accurately act on the target.

For destroys, "dependencies" are descendents: those resources which fall
_after_ the target. These resources depend on our target, which is going
to be destroyed, so they should also be destroyed.
2015-03-31 14:49:38 -05:00
Mitchell Hashimoto 95cf69aa32 command: StateHook for continous state updates 2015-02-23 21:57:17 -08:00
Mitchell Hashimoto fb3f10efb0 command/apply: ask for user variables before validation [GH-736] 2015-01-16 10:46:38 -08:00
Mitchell Hashimoto 90138825a2 command/apply: don't init if no args given [GH-780]
I really don't know how to unit test this since I don't know what input
triggers this except that it has been reporting a few times in the wild.
2015-01-16 10:22:20 -08:00
Armon Dadgar 0fb87e499d command: Meta provides the state output path 2014-12-10 13:27:09 -08:00
Armon Dadgar bf10111745 command/apply: Move state persistence to Meta 2014-12-10 13:27:09 -08:00
Armon Dadgar 5b745e5d46 command: Run validation before asking for input. Fixes #602 2014-12-08 18:32:03 -08:00
Panagiotis Moustafellos 3d51bae4b2 switch phrasing 2014-10-15 18:57:24 +03:00
Panagiotis Moustafellos 08515edc43 fixed typo on terraform destroy 2014-10-15 11:17:56 +03:00
Mitchell Hashimoto 8fc134caa1 command/destroy: don't show outputs 2014-10-11 17:37:28 -07:00
Mitchell Hashimoto 0914e17a2a command/apply: more than one ctrl-c properly exits immediately 2014-10-11 13:23:15 -07:00
Mitchell Hashimoto 16b023bd2b command: ask for the proper level of input 2014-10-08 10:29:54 -07:00
Mitchell Hashimoto a5f70ead2d command: destroy should ask for confirmation always 2014-10-03 16:08:50 -07: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 817f0d9f30 command: don't ask for input if terraform.tfvars file given [GH-346] 2014-10-01 08:37:57 -07:00
Mitchell Hashimoto 2131e4ffd2 command: fix failing tests 2014-09-30 22:11:55 -07:00
Mitchell Hashimoto 245c1ce05a command: enable destroy 2014-09-30 22:01:11 -07:00
Mitchell Hashimoto ab9dd71bcb command/destroy: first steps 2014-09-30 21:49:24 -07:00
Mitchell Hashimoto 260c5301e6 command/apply: update usage 2014-09-29 15:57:35 -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 63453f3f1a command: apply and refresh ask for input 2014-09-29 12:46:58 -07:00
Mitchell Hashimoto ed538a9594 command: Get command, not functional yet. Converted to use modules. 2014-09-22 10:56:50 -07:00
Mitchell Hashimoto cdad3036ae command: closer to compiling 2014-09-17 11:15:07 -07:00
AJ Bourg aefa4b2399 expacts -> expects. (minor) 2014-09-04 16:33:05 -06:00
Alex Gaynor 46154ca1d3 Fixed a ton of typos in docs and comments 2014-08-07 00:19:56 -07:00
Mitchell Hashimoto 642fed0356 command: terraform.tfvars loaded by default if it exists 2014-08-05 09:32:01 -07:00
Mitchell Hashimoto b172f45b94 command: make state unexported on Meta 2014-07-27 22:58:35 -07:00
Mitchell Hashimoto 80ce9ad513 command: f.Close instead of defer 2014-07-27 22:56:55 -07:00
Armon Dadgar 16ef3f5733 command: Testing the -backup feature 2014-07-27 23:38:41 -04:00
Armon Dadgar 54cc66367d command: Adding backup of state file 2014-07-27 18:09:04 -04:00
Mitchell Hashimoto 9759606989 command/apply: check if state non-nil for interrupt 2014-07-26 21:28:42 -07:00
Mitchell Hashimoto 0f45ebbdc3 command: better UI for showing completion of steps 2014-07-26 21:20:31 -07:00
Mitchell Hashimoto 795142c43c command/apply: -refresh flag 2014-07-26 17:51:16 -07:00
Mitchell Hashimoto ef6fba754d command: refactor so Context never plans 2014-07-26 17:51:15 -07:00
Mitchell Hashimoto 82e7d58250 command/apply: -init is gone
/cc @pearkes - hurray!
2014-07-26 14:44:05 -07:00
Mitchell Hashimoto 3534470ca3 command: -var flag works 2014-07-18 11:37:27 -07:00
Mitchell Hashimoto f78f97647a command/apply: clearer that in error state is updated 2014-07-17 15:18:00 -07:00
Mitchell Hashimoto ba4435f99c command/apply: show add/remove/change count for apply 2014-07-17 15:14:45 -07:00
Mitchell Hashimoto 6c8c09c784 command/*: only Plan on the Apply 2014-07-14 11:48:03 -07:00
Mitchell Hashimoto 52d29a6ecf command/apply: outputs 2014-07-13 09:34:35 -07:00
Mitchell Hashimoto 4bc00fa047 command/apply: cleaner output 2014-07-13 09:20:27 -07:00
Mitchell Hashimoto 9b090a5505 command/apply: use new state formatting 2014-07-12 21:02:53 -07:00
Mitchell Hashimoto 3a851bece0 command: convert all to use the new Meta thing 2014-07-12 20:37:30 -07:00
Mitchell Hashimoto 6c736bd3c4 command: introduce Meta and "-no-color" option 2014-07-12 20:21:46 -07:00
Mitchell Hashimoto c615afc097 command/apply: improved output, still not done 2014-07-12 17:03:55 -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 43889a8c59 command: validate context 2014-07-03 13:12:45 -07:00
Mitchell Hashimoto a6ae7230d1 command: use new API 2014-07-03 11:46:40 -07:00
Mitchell Hashimoto 5608175c13 command: fix build 2014-07-02 19:45:00 -07:00
Mitchell Hashimoto 5aa6ada589 command/apply: Ctrl-C works 2014-07-02 17:01:02 -07:00
Mitchell Hashimoto 93fbb9ea8f command/graph 2014-07-01 10:02:13 -07:00
Mitchell Hashimoto 5c836ab861 terraform: PlanOpts for expanding plan configuration 2014-06-28 13:10:11 -07:00
Mitchell Hashimoto fe79e5df03 command/apply: can take a plan as an argument 2014-06-27 14:43:33 -07:00
Mitchell Hashimoto 6b765328c2 command: UI in Apply 2014-06-26 22:13:54 -07:00