Commit Graph

358 Commits

Author SHA1 Message Date
Chris Bednarski e942a74def Set a log prefix for each plugin and remove go-dynect global log prefix (#6336) 2016-05-10 14:49:13 -04:00
James Nugent 991dc3f86f core: Add Cobbler provider to internal plugin list 2016-05-10 14:49:13 -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 6aac79e194 state: Add support for outputs of multiple types
This commit adds the groundwork for supporting module outputs of types
other than string. In order to do so, the state version is increased
from 1 to 2 (though the "public-facing" state version is actually as the
first state file was binary).

Tests are added to ensure that V2 (1) state is upgraded to V3 (2) state,
though no separate read path is required since the V2 JSON will
unmarshal correctly into the V3 structure.

Outputs in a ModuleState are now of type map[string]interface{}, and a
test covers round-tripping string, []string and map[string]string, which
should cover all of the types in question.

Type switches have been added where necessary to deal with the
interface{} value, but they currently default to panicking when the input
is not a string.
2016-05-10 14:40:12 -04:00
Chris Bednarski 6360e6c8b6 Implemented internal plugin calls; which allows us to compile plugins into the main terraform binary 2016-05-10 14:40:11 -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
Mitchell Hashimoto e133452663 command/state: pattern => address 2016-05-10 14:14:48 -04:00
Mitchell Hashimoto 5737c0a13b website: update docs for state show 2016-05-10 14:14:48 -04:00
Mitchell Hashimoto f6692e66ac add command/state show 2016-05-10 14:14:47 -04:00
Mitchell Hashimoto d1b46e99bd Add `terraform state list` command
This introduces the terraform state list command to list the resources
within a state. This is the first of many state management commands to
come into 0.7.

This is the first command of many to come that is considered a
"plumbing" command within Terraform (see "plumbing vs porcelain":
http://git.661346.n2.nabble.com/what-are-plumbing-and-porcelain-td2190639.html).
As such, this PR also introduces a bunch of groundwork to support
plumbing commands.

The main changes:

- Main command output is changed to split "common" and "uncommon"
  commands.

- mitchellh/cli is updated to support nested subcommands, since
  terraform state list is a nested subcommand.

- terraform.StateFilter is introduced as a way in core to filter/search
  the state files. This is very basic currently but I expect to make it
  more advanced as time goes on.

- terraform state list command is introduced to list resources in a
  state. This can take a series of arguments to filter this down.

Known issues, or things that aren't done in this PR on purpose:

- Unit tests for terraform state list are on the way. Unit tests for the
  core changes are all there.
2016-05-10 14:14:47 -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
Dan Carley 64c1280951 command/fmt: Improve documentation for -diff and defaults (#6398)
* command/fmt: Document -diff doesn't disable -write

As noted in hashicorp/terraform#6343, this description misleadingly
suggested that the `-diff` option disables the `-write` option.

This isn't the case and because of the default options (described in
c753390) the behaviour of `terraform fmt -diff` is actually the same as
`terraform fmt -write -list -diff`.

Replace the "instead of rewriting" description to clarify that.

Documentation in hcl/fmtcmd is corrected in hashicorp/hcl#117 but it's not
really necessary to bump the dependency version.

* command/fmt: Show flag defaults in help text

These were documented on the website but not in the `-help` text. This
should help to clarify that you need to pass `-list=false -write=false
-diff` if you only want to see diffs.

Accordingly I've replaced the word "disabled" with "always false" in the
STDIN special cases so that it matches the terminology used in the defaults
and better indicates that it is overridden.

NB: The 3x duplicated defaults and documentation makes me feel uneasy once
again. I'm not sure how to solve that, though.
2016-04-29 00:39:53 +01:00
Paul Hinze c74c5fe7f0
Update HCL to latest, unskip fmt tests
See https://github.com/hashicorp/hcl/pull/115
2016-04-27 07:37:47 -05:00
Paul Hinze ac10a7979d
command/fmt tests: temporarily skip newline failures
Skipping tests to get the master build green while I sort out these
failing tests.

They should be fixed for real in just a few here.
2016-04-26 15:26:16 -05:00
Mitchell Hashimoto 08ad84d8b2 command: defer the lock unlock 2016-04-13 12:02:24 -07:00
Mitchell Hashimoto 284bc92c04 command: show periodic messages about continued ops 2016-04-13 11:12:05 -07: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
David Glasser 320773d6c1 command: delete unused class 2016-04-05 18:42:09 -07:00
Martin Atkins fa703db8a6 Merge #4955: "terraform fmt" command 2016-04-04 01:07:32 -07:00
Paul Hinze c7f5450a96 command: Add `terraform untaint`
- [x] Docs
 - [x] Command Unit Tests
 - [x] State Unit Tests

Closes #4820
2016-03-11 12:38:57 -06:00
Dan Carley d883b76070 command/fmt: Test non-default options
To ensure that these are passed over to `fmtcmd` correctly.
2016-03-07 15:07:15 +00:00
Dan Carley 79e2753e41 command/fmt: Disable list/write when using STDIN
These options don't make sense when passing STDIN. `-write` will raise an
error because there is no file to write to. `-list` will always say
`<standard input>`. So disable whenever using STDIN, making the command
much simpler:

    cat main.tf | terraform fmt -
2016-03-07 15:07:15 +00:00
Dan Carley e9128769b5 command/fmt: Accept input from STDIN
So that you can do automatic formatting from an editor. You probably want to
disable the `-write` and `-list` options so that you just get the
re-formatted content, e.g.

    cat main.tf | terraform fmt -write=false -list=false -

I've added a non-exported field called `input` so that we can override this
for the tests. If not specified, like in `commands.go`, then it will default
to `os.Stdin` which works on the command line.
2016-03-07 15:07:15 +00:00
Dan Carley 1b967e612f command/fmt: Accept optional directory argument
So that you can operate on files in a directory other than your current
working directory.
2016-03-07 15:07:14 +00:00
Dan Carley c753390399 command/fmt: Default write and list to true
The most common usage usage will be enabling the `-write` and `-list`
options so that files are updated in place and a list of any modified files
is printed. This matches the default behaviour of `go fmt` (not `gofmt`). So
enable these options by default.

This does mean that you will have to explicitly disable these if you want to
generate valid patches, e.g. `terraform fmt -diff -write=false -list=false`
2016-03-07 15:07:14 +00:00
Dan Carley cc41c7cfa0 command/fmt: Add new fmt command
This uses the `fmtcmd` package which has recently been merged into HCL. Per
the usage text, this rewrites Terraform config files to their canonical
formatting and style.

Some notes about the implementation for this initial commit:

- all of the fmtcmd options are exposed as CLI flags
- it operates on all files that have a `.tf` suffix
- it currently only operates on the working directory and doesn't accept a
  directory argument, but I'll extend this in subsequent commits
- output is proxied through `cli.UiWriter` so that we write in the same way
  as other commands and we can capture the output during tests
- the test uses a very simple fixture just to ensure that it is working
  correctly end-to-end; the fmtcmd package has more exhaustive tests
- we have to write the fixture to a file in a temporary directory because it
  will be modified and for this reason it was easier to define the fixture
  contents as a raw string
2016-03-07 15:07:04 +00:00
James Nugent b787fe2798 Merge pull request #5012 from jrnt30/TF-5011-Backend-flag-normalization
Fixes #5011 - Backend downcased for init
2016-02-08 17:59:20 -05:00
stack72 1628f19bc1 Fixing some golint issues on the new validate command 2016-02-08 22:04:24 +00:00
Soren Mathiasen db69a2959b Added verify command 2016-02-08 12:48:14 +01:00
Justin Nauman 61240b4250 Fixes #5011 - Backend downcased for init 2016-02-05 06:26:12 -06:00
Paul Hinze 4a51e4fe91 core: write planfile even on empty plans
This makes the planfile workflow more consistent. If a plan yields a
noop, the apply of that planfile will noop.

Fixes #1783
2016-01-20 16:00:20 -06:00
Paul Hinze e67fc0fe9b command: Change module-depth default to -1
This means that terraform commands like `plan`, `apply`, `show`, and
`graph` will expand all modules by default.

While modules-as-black-boxes is still very true in the conceptual design
of modules, feedback on this behavior has consistently suggested that
users would prefer to see more verbose output by default.

The `-module-depth` flag and env var are retained to allow output to be
optionally limited / summarized by these commands.
2016-01-20 13:58:02 -06:00
Mitchell Hashimoto 6a972a7713 command/init: put remote state config at proper path [GH-2927] 2016-01-19 17:13:19 -08:00
James Nugent a5e51f6dad command/refresh: Fix import formats to prevent flapping 2015-11-27 15:10:42 +00:00
Paul Hinze 0e277a6714 core: test coverage around map key regression
tests to cover the HCL-level issue fixed in
https://github.com/hashicorp/hcl/pull/65
2015-11-24 16:00:02 -06:00
James Nugent 50b5e7c1a5 Validate context after input of vars on refresh
Fixes #4013.
2015-11-23 10:33:40 +02:00
James Nugent 890e214c00 Add failing test replicating #4013 2015-11-23 10:32:46 +02: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
James Nugent a49b162dd1 Prompt for input variables before context validate
Also adds a regression test using Mock UI. Fixes #3767.
2015-11-10 14:03:56 -05:00
James Nugent f4c03ec2a6 Reflect new comment format in stringer.go
As of November 8th 2015, (4b07c5ce8a), the word "Code" is prepended to
the comments in Go source files generated by the stringer utility.
2015-11-09 11:38:51 -05: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
John Gosset 61e890ecc9 Update list of backends in RemoteConfigCommand's Help() method 2015-10-25 16:46:02 -04:00
Martin Atkins e4e9c13c20 Merge #3136: Colorize the 'forces new resource' message 2015-10-22 08:44:37 -07:00
Mitchell Hashimoto 344e7c26b5 fix a bunch of tests from go-getter import 2015-10-15 13:48:58 -07:00
Panagiotis Moustafellos e4845f75cc removed extra parentheses 2015-10-08 15:48:04 +03: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 bf9c5c46d0 Tests for apply parallelism=1 and parallelism=2 2015-09-29 22:41:26 -07:00
Kevin Nuckolls fc60b2858c Added -parallelism to refresh and plan cli UI 2015-09-29 22:41:26 -07:00