Commit Graph

10258 Commits

Author SHA1 Message Date
Mitchell Hashimoto d94f503501
command/state meta: State func 2016-05-11 09:16:48 -07:00
Mitchell Hashimoto f34ef1f92a
command: compilation works
This still isn't ready. But this gets tests passing and compilation
working
2016-05-10 17:03:58 -07:00
Mitchell Hashimoto 9ddf73ad81
website: update docs 2016-05-10 13:25:43 -07:00
Mitchell Hashimoto eaf3d608ed
terraform: test moving a module to be nested 2016-05-10 13:25:43 -07:00
Mitchell Hashimoto 04598baa25
website: document state mv 2016-05-10 13:25:42 -07:00
Mitchell Hashimoto c966a70ff9
command: update docs for state mv 2016-05-10 13:25:04 -07:00
Mitchell Hashimoto 32d0d29b56
command: test for moving into another state file 2016-05-10 13:25:04 -07:00
Mitchell Hashimoto 235e860118
command/state mv: handle -state-out to a different path 2016-05-10 13:25:04 -07:00
Mitchell Hashimoto c4e5355a02
command/state mv 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto 163f19fd00
terraform: instance => module 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto 4d268b6eca
terraform: instance => resource 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto e497c26517
terraform: resource => module 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto d3fcfcc027
terraform: moving resource to resource 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto e65a726936
terraform: copy deps and provider for resource state 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto cb060f9063
terraform: unify on init addr 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto c324062645
terraform: state add resource existing fails 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto 21d7ffc3f3
terraform: add resource 2016-05-10 13:25:03 -07:00
Mitchell Hashimoto 2de4324607
terraform: add stateadd to its own test file 2016-05-10 13:25:02 -07:00
Mitchell Hashimoto af3c3e4c60
terraform: Module copy copies outputs and dependencies 2016-05-10 13:25:02 -07:00
Mitchell Hashimoto 30cf550fc5
terraform: can't move module to module that exists 2016-05-10 13:25:02 -07:00
Mitchell Hashimoto bbc812d035
terraform: fix failing tests 2016-05-10 13:25:02 -07:00
Mitchell Hashimoto 25098f20c9
terraform: State.Add works for module to module (new) 2016-05-10 13:25:02 -07:00
Mitchell Hashimoto 407be65cc8
terraform: ResourceAddress should output instance type if set 2016-05-10 13:25:02 -07:00
James Nugent 4faa6b37e4 Merge pull request #6596 from hashicorp/merge-dev-0.7
Merge rebased dev-0.7 branch into master
2016-05-10 16:13:20 -04:00
James Nugent f1d0fc46aa core: Fix go vet issues shown by Travis 2016-05-10 16:00:28 -04:00
James Nugent 0f5f73eae1 Update CHANGELOG.md 2016-05-10 15:52:31 -04: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 9d77e0af6c core: Add new providers to internal list 2016-05-10 14:49:14 -04:00
James Nugent 7b6df27e4a helper/schema: Read native maps from configuration
This adds a test and the support necessary to read from native maps
passed as variables via interpolation - for example:

```
resource ...... {
     mapValue = "${var.map}"
}
```

We also add support for interpolating maps from the flat-mapped resource
config, which is necessary to support assignment of computed maps, which
is now valid.

Unfortunately there is no good way to distinguish between a list and a
map in the flatmap. In lieu of changing that representation (which is
risky), we assume that if all the keys are numeric, this is intended to
be a list, and if not it is intended to be a map. This does preclude
maps which have purely numeric keys, which should be noted as a
backwards compatibility concern.
2016-05-10 14:49:14 -04:00
James Nugent 244da895cd core: Remove StringList
Much celebration may now ensue! ♪┏(°.°)┛┗(°.°)┓┗(°.°)┛┏(°.°)┓ ♪
2016-05-10 14:49:14 -04:00
James Nugent f49583d25a core: support native list variables in config
This commit adds support for native list variables and outputs, building
up on the previous change to state. Interpolation functions now return
native lists in preference to StringList.

List variables are defined like this:

variable "test" {
    # This can also be inferred
    type = "list"
    default = ["Hello", "World"]
}

output "test_out" {
    value = "${var.a_list}"
}
This results in the following state:

```
...
            "outputs": {
                "test_out": [
                    "hello",
                    "world"
                ]
            },
...
```

And the result of terraform output is as follows:

```
$ terraform output
test_out = [
  hello
  world
]
```

Using the output name, an xargs-friendly representation is output:

```
$ terraform output test_out
hello
world
```

The output command also supports indexing into the list (with
appropriate range checking and no wrapping):

```
$ terraform output test_out 1
world
```

Along with maps, list outputs from one module may be passed as variables
into another, removing the need for the `join(",", var.list_as_string)`
and `split(",", var.list_as_string)` which was previously necessary in
Terraform configuration.

This commit also updates the tests and implementations of built-in
interpolation functions to take and return native lists where
appropriate.

A backwards compatibility note: previously the concat interpolation
function was capable of concatenating either strings or lists. The
strings use case was deprectated a long time ago but still remained.
Because we cannot return `ast.TypeAny` from an interpolation function,
this use case is no longer supported for strings - `concat` is only
capable of concatenating lists. This should not be a huge issue - the
type checker picks up incorrect parameters, and the native HIL string
concatenation - or the `join` function - can be used to replicate the
missing behaviour.
2016-05-10 14:49:14 -04:00
Mitchell Hashimoto a49b17147a deps: vendor columnize 2016-05-10 14:49:14 -04:00
Mitchell Hashimoto 473a58a672 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:49:14 -04:00
Mitchell Hashimoto e81fb10e61 terraform: test file for last commit 2016-05-10 14:49:14 -04:00
Mitchell Hashimoto 3480b7ebee terraform: state filter wasn't comparing resource names 2016-05-10 14:49:14 -04:00
James Nugent 0c56144d7f build: Only build once for core-dev 2016-05-10 14:49:13 -04:00
Chris Bednarski 3c774af9c2 Warn when an internal plugin is overridden
Also added documentation explaining what happened and how to fix it
2016-05-10 14:49:13 -04:00
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
James Nugent 3393492033 Renumber original binary state as V0
This commit rectifies the fact that the original binary state is
referred to as V1 in the source code, but the first version of the JSON
state uses StateVersion: 1. We instead make the code refer to V0 as the
binary state, and V1 as the first version of JSON state.
2016-05-10 14:40:12 -04:00
James Nugent 14cf31cf43 deps: Update github.com/hashicorp/hil/... 2016-05-10 14:40:11 -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 a94b9fdc92 terraform: Internals for `state rm` command
I decided to split this up from the terraform state rm command to make the diff easier to see. These changes will also be used for terraform state mv.

This adds a `Remove` method to the `*terraform.State` struct. It takes a list of addresses and removes the items matching that list. This leverages the `StateFilter` committed last week to make the view of the world consistent across address lookups.

There is a lot of test duplication here with StateFilter, but in Terraform style: we like it that way.
2016-05-10 14:14:48 -04:00
Mitchell Hashimoto e133452663 command/state: pattern => address 2016-05-10 14:14:48 -04:00
Mitchell Hashimoto b10f22484e deps: vendor columnize 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