Commit Graph

796 Commits

Author SHA1 Message Date
Mitchell Hashimoto e3a01ccfd8 Merge pull request #10072 from hashicorp/f-output-depends-on
terraform: output nodes can have `depends_on`
2016-11-14 11:52:18 -08:00
Mitchell Hashimoto 15979435d6
config: update error string for new HIL merge 2016-11-13 10:28:31 -08:00
Mitchell Hashimoto 85d3439fa0
config: parse and validate terraform.required_version 2016-11-12 16:22:35 -08:00
Mitchell Hashimoto 576b61a21d
config: validate depends_on with module values 2016-11-12 08:21:27 -08:00
Mitchell Hashimoto 10426ba619
config: parse depends_on for outputs 2016-11-11 17:46:34 -08:00
Mitchell Hashimoto 5107c33119
command/import: load configurations and allow empty config dirs
Fixes #7774

This modifies the `import` command to load configuration files from the
pwd. This also augments the configuration loading section for the CLI to
have a new option (default false, same as old behavior) to
allow directories with no Terraform configurations.
For import, we allow directories with no Terraform configurations so
this option is set to true.
2016-11-09 15:08:22 -08:00
Mitchell Hashimoto a8fbf3420c
config: clean up unused fucntions 2016-11-09 14:28:16 -08:00
Mitchell Hashimoto 2d656b484c
config: test that partial interpolation in a list works properly 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto b979d8927e
config: use ast.TypeUnknown and don't remove computed values 2016-11-09 14:28:15 -08:00
Mitchell Hashimoto 260fb81373 Merge pull request #9795 from hashicorp/b-formatlist-empty
config: formatlist accepts an empty list
2016-11-04 08:47:57 -07:00
Mitchell Hashimoto 29287937e3 Merge pull request #9818 from hashicorp/b-var-parse
config: manually parse variable blocks for better validation
2016-11-04 08:47:40 -07:00
Mitchell Hashimoto ef3148bbfa
config: validate that outputs have a name 2016-11-02 16:56:20 -07:00
Mitchell Hashimoto f054c5ca2c
config: manually parse variable blocks for better validation
Fixes #7846

This changes from using the HCL decoder to manually decoding the
`variable` blocks within the configuration. This gives us a lot more
power to catch validation errors. This PR retains the same tests and
fixes one additional issue (covered by a test) in the case where a
variable has no named assigned.
2016-11-02 14:59:16 -07:00
Mitchell Hashimoto d69b6257df
config: formatlist accepts an empty list
Fixes #7607

An empty list is a valid value for formatlist which means to just return
an empty list as a result. The logic was somewhat convoluted here so I
cleaned that up a bit too. The function overall can definitely be
cleaned up a lot more but I left it mostly as-is to fix the bug.
2016-11-01 22:57:11 -07:00
Raphael Randschau e97785c899 terraform/core: typo in RawConfig documentation (#9714) 2016-10-29 16:18:56 +01:00
Jesse Szwedko 0fbd72a355 Add some basic math interpolation functions
Support the following math functions for interpolation:

* ceil
* floor
* max
* min

Fixes #7409
2016-10-28 17:49:31 +00:00
James Nugent 47bce79b29 core: Add zipmap interpolation function
This commit adds a new interpolation function, zipmap, which produces a
map given a list of string keys and a list of values of the same length
as the list of keys.

The name comes from the same operation in Clojure (and likely other
functional langauges).
2016-10-26 11:28:36 -05:00
Gustavo 5910e3b8af Adds ‘tittle’ built-in function. (#9087)
The tittle function returns a copy of the string with the first characters of all the words capitalized.
2016-10-26 13:21:32 +01:00
Mitchell Hashimoto 694b16de5d
config: ignore_changes cannot have interpolations
This is the limitation of all lifecycle attributes currently. Right now,
interpolations are allowed through and the user ends up thinking it
should work. We should give an error.

In the future it should be possible to support some minimal set of
interpolations (static variables, data sources even perhaps) but for now
let's validate that this doesn't work.
2016-10-24 23:06:33 -07:00
Mitchell Hashimoto fee0351c66
config: RawConfig merge should only set unknown keys non-nil if
non-empty
2016-10-19 15:21:09 -07:00
Mitchell Hashimoto 5cd6898109
config: fix a conflicting test name
A public API TestNewRawConfig was added to easily create a raw config
for testing, but this conflicted with the test. Just rename it.
2016-10-19 13:39:28 -07:00
Mitchell Hashimoto dfa02e4412
terraform: rename attach config to only attach provider config 2016-10-19 13:38:51 -07:00
Mitchell Hashimoto 55ef966b88
config/module: tree.Child on a nil tree works 2016-10-19 13:38:49 -07:00
Mitchell Hashimoto 0fe51b334c Merge pull request #9334 from hashicorp/f-shadow-graph
terraform: Shadow Graph
2016-10-19 13:36:10 -07:00
Mitchell Hashimoto 30596ca371
terraform: sanity test (passes, always passed) 2016-10-11 22:17:31 +08:00
Mitchell Hashimoto 098225dc0d
config/module: use the raw source as part of the key
This changes the key for the storage to be the _raw_ source from the
module, not the fully expanded source. Example: it'll be a relative path
instead of an absolute path.

This allows the ".terraform/modules" directory to be portable when
moving to other machines. This was a behavior that existed in <= 0.7.2
and was broken with #8398. This amends that and adds a test to verify.
2016-09-30 10:44:46 -07:00
Mitchell Hashimoto 37c880c377
Update reflectwalk to fix failing tests
As part of working on ResourceConfig.DeepCopy, Equal I updated
reflectwalk (to fix some issues in the new functions) but this
introduced more issues in other parts of Terraform. This update fixes
those.
2016-09-27 19:16:29 -07:00
James Bardin e2b6ccad8a Failing test for GH-8820 2016-09-15 16:51:12 -04:00
Mitchell Hashimoto 609219fc65 command/meta: validate config immediately
* config: test for validating multi-vars (passes)

* command/plan: test invalid run

* command/meta: validate module on load
2016-09-03 15:26:49 -07:00
James Bardin 94674fe93c Add a test load of a data source with count 2016-09-03 13:08:41 -07:00
James Bardin a3fc7e2e21 remove "count" while loading a data source
Data sources should be able to support counts like a resource. We need
to remove "count" when we load the config because the key doesn't exist
in the schema, and the resource won't validate.
2016-09-03 13:08:41 -07:00
Sander van Harmelen 47dd1ad153 Add wildcard (match all) support to ignore_changes (#8599) 2016-09-02 15:44:35 +02:00
James Bardin 14138fc449 Add test for RawMap
Ensure that RawMap() returns an identical copy, and not a reference to
the original map.
2016-08-31 14:00:59 -04:00
James Bardin 632c16c212 Fix inconsistent results with self interpolation
Due to a race in interpolateForce(), a reference to self could return
inconsistent results.
2016-08-30 14:16:37 -04:00
Mitchell Hashimoto 706b2e2aea Merge pull request #8482 from hashicorp/b-output-dup
config: variable names and outputs must be unique
2016-08-26 13:57:59 -07:00
Mitchell Hashimoto 0fceeaaeb0
config: test for var uniqueness in overrides 2016-08-26 13:48:21 -07:00
Mitchell Hashimoto 4e7f2dd01e Merge pull request #8398 from hashicorp/b-module-collide
config/module: use source as part of key
2016-08-26 13:27:56 -07:00
Mitchell Hashimoto 8a3559560d
config: JSON resource keys with only one item load properly GH-5140
When a resource has only a single key set, the HCL parser treats that
key as part of the overall set of object keys. This isn't valid since
we expect resources to have exactly two keys. In this scenario, we have
to "unwrap" the keys back into a set of objects.
2016-08-25 17:18:18 -07:00
Mitchell Hashimoto fbf06e2a59
config: vars must be unique 2016-08-25 14:51:49 -07:00
Mitchell Hashimoto 099293b690
config: outputs must be unique 2016-08-25 14:43:57 -07:00
Mitchell Hashimoto 92336281a5
config/module: use source as part of key 2016-08-22 14:07:28 -07:00
Mitchell Hashimoto f4faf2274b
config: count can't be a SimpleVariable 2016-08-16 13:48:12 -07:00
James Bardin 81bb6b7264 Merge pull request #7905 from hashicorp/jbardin/merge
core: Add merge interpolation function
2016-08-02 09:45:20 -04:00
James Bardin 39bbbb8da6 Add merge interpolation function
Add a `merge` interpolation function, which merges any number of maps.
Duplicate keys are OK, with the last write winning.
2016-08-01 18:30:58 -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 Bardin c9e1522103 Use HIL to limit concat to ast.TypeList
we can remove some type checks in the concat function
2016-08-01 15:24:18 -04:00
James Bardin c15c0eb0cb Disallow strings as arguments to concat
The concat interpolation function now only accepts list arguments.
Strings are no longer supported, for concatenation or appending to
lists. All arguments must be a list, and single elements can be promoted
with the `list` interpolation function.
2016-08-01 15:06:20 -04:00
James Nugent 796ce7bdd7 build: Opt-in to building rather than opt-out 2016-07-29 18:40:31 -05:00
James Nugent b2d5b66508 Merge pull request #7880 from hashicorp/b-fix-freebsd
build: Fix errors in FreeBSD build
2016-07-29 18:30:55 -05:00
James Nugent 2eb00c9184 build: Fix errors in FreeBSD build
Fixes the following error when cross compiling:

```
--> freebsd/amd64 error: exit status 2
Stderr: # github.com/hashicorp/terraform/config/module
config/module/inode.go:18: cannot use st.Ino (type uint32) as type uint64 in return argument
```
2016-07-29 18:26:22 -05:00
James Bardin 5802f76eaa Make all terraform package tests pass under -race
This isn't a pretty refactor, but fixes the race issues in this package
for now.

Fix race on RawConfig.Config()

fix command package races
2016-07-29 16:12:21 -04:00
Paul Hinze 88030764ff
config: Audit all interpolation functions for list/map behavior
- `distinct()` - error on non-flat lists
 - `element()` - error on non-flat lists
 - `join()` - error on non-flat lists
 - `length()` - support maps
 - `lookup()` - error on non-flat maps
 - `values()` - error on non-flat maps
2016-07-28 09:56:30 -05:00
Paul Hinze 1425b34562
config: Add map() interpolation function
* `map(key, value, ...)` - Returns a map consisting of the key/value pairs
  specified as arguments. Every odd argument must be a string key, and every
  even argument must have the same type as the other values specified.
  Duplicate keys are not allowed. Examples:
  * `map("hello", "world")`
  * `map("us-east", list("a", "b", "c"), "us-west", list("b", "c", "d"))`
2016-07-27 13:03:08 -05:00
James Bardin 8dcbc0b0a0 Add concat to accept lists of lists and maps
This will allow the concat interpolation function to accept lists of
lists, and lists of maps as well as strings. We still allow bare strings
for backwards compatibility, but remove some of the old comment wording
as it could cause confusion of this function with actual string
concatenation.

Since maps are now supported in the config, this removes the superfluous
(and failing) TestInterpolationFuncConcatListOfMaps.
2016-07-19 17:45:50 -04:00
James Bardin 2bd7cfd5fe Expand list interpolation to lists and maps
Allow lists and maps within the list interpolation function via variable
interpolation. Since this requires setting the variadic type to TypeAny,
we check for non-heterogeneous lists in the callback.
2016-07-19 13:44:37 -04:00
James Nugent 58dd41f3b1 core: Add list() interpolation function
The list() interpolation function provides a way to add support for list
literals (of strings) to HIL without having to invent new syntax for it
and modify the HIL parser.

It presents as a function, thus:

    - list() -> []
    - list("a") -> ["a"]
    - list("a", "b") -> ["a", "b"]

Thanks to @wr0ngway for the idea of this approach, fixes #7460.
2016-07-18 18:12:11 -04:00
James Nugent c6e03cba96 core: Fix slice element keys on interpolateWalk
Part of the interpolation walk is to detect keys which involve computed
values and therefore cannot be resolved at this time. The interplation
walker keeps sufficient state to be able to populate the ResourceConfig
with a slice of such keys.

Previously they didn't take slice indexes into account, so in the
following case:

```
"services": []interface{}{
    map[string]interface{}{
        "elb": "___something computed___",
    },
    map[string]interface{}{
        "elb": "___something else computed___",
    },
    map[string]interface{}{
        "elb": "not computed",
    },
}
```

Unknown keys would be populated as follows:

```
services.elb
services.elb
```

This is not sufficient information to be useful, as it is impossible to
distinguish which of the `services.elb`s are unknown vs not.

This commit therefore retains the slice indexes as part of the key for
unknown keys - producing for the example above:

```
services.0.elb
services.1.elb
```
2016-07-08 16:43:42 +01:00
James Bardin e78dc291af Add test to ensure key/values interp order
Test that interpolated values are returned in the order of the sorted
keys.
2016-06-29 15:06:59 -04:00
James Nugent 8284b79957 Merge pull request #7298 from hashicorp/jbardin/GH-7273-fixup
code: Add proper build constraints for GH-7273
2016-06-24 14:33:10 +03:00
James Nugent 8403a465bc core: Add test and fix for element with empty list
The incldued test previously caused a panic, it now returns an error
message explaining the issue.
2016-06-23 21:15:33 +01:00
James Bardin 525485c213 Add proper build constraints for GH-7273
The syscall.Stat_t type doesn't exist on windows, so the inode lookup
needs to be in a file with proper build constraints.
2016-06-23 08:02:32 -04:00
James Bardin 558e023e26 Don't try to copy files over themselves
When copying a config module, make sure the full path for src and dst
files don't match, and also check the inode in case we resolved a
different path to the same file.

Make a note about the unsafe usage of reusing a tempDir path.
2016-06-22 11:25:42 -04:00
James Nugent 9d6c629689 config: Update test to reflect new behaviour
Escaped quotes are no longer supported as HIL syntax (as of the last
update to HIL), so this commit changes the Terraform config-layer test
to verify the non-presence of this behaviour for 0.7.
2016-06-20 19:06:03 +03:00
James Nugent 4b6a632246 core: Rename uniq -> distinct and add docs 2016-06-15 13:25:17 +02:00
Jan Schumann df3e017f6c fix #7106 2016-06-15 13:25:16 +02:00
Paul Hinze 9bc980f569
core: Fix panic on concat() w/ list of nonprimitives
The `concat()` interpolation function does not yet support types other
than strings / lists of strings. Make it an error message instead of a
panic when a list of non-primitives is supplied.

Fixes the panic in #7030
2016-06-12 13:29:06 -05:00
Paul Hinze ffa29090ec
core: Better error for dot indexing on user vars
Dot indexing worked in the "regexps and strings" world of 0.6.x, but it
no longer works on the 0.7 series w/ proper List / Map types.

There is plenty of dot-indexed config out in the wild, so we need to do
what we can to point users to the new syntax.

Here is one place we can do it for user variables (`var.somemap`). We'll
also need to address Resource Variables and Module Variables in a
separate PR.

This fixes the panic in #7103 - a proper error message is now returned.
2016-06-12 10:45:48 -05:00
James Nugent 01cd596c60 core: Fix detection of empty list/map defaults
This commit changes config parsing from weak decoding lists and maps
into []string and map[string]string respectively to decode into
[]interface{} and map[string]interface{} respectively. This is in order
to take advantage of the work integrated in #7082 to defeat the backward
compatibility features of the mapstructure library.

Test coverage of loading empty variables and validating their default
types against expectation.
2016-06-12 11:19:03 +02:00
James Nugent 578ff9569e core: Add sort() interpolation function 2016-06-11 18:03:52 +01:00
James Nugent cb9ef298f3 core: Defeat backward compatibilty in mapstructure
The mapstructure library has a regrettable backward compatibility
concern whereby a WeakDecode of []interface{}{} into a target of
map[string]interface{} yields an empty map rather than an error. One
possibility is to switch to using Decode instead of WeakDecode, but this
loses the nice handling of type conversion, requiring a large volume of
code to be added to Terraform or HIL in order to retain that behaviour.

Instead we add a DecodeHook to our usage of the mapstructure library
which checks for decoding []interface{}{} or []string{} into a map and
returns an error instead.

This has the effect of defeating the code added to retain backwards
compatibility in mapstructure, giving us the correct (for our
circumstances) behaviour of Decode for empty structures and the type
conversion of WeakDecode.

The code is identical to that in the HIL library, and packaged into a
helper.
2016-06-08 18:38:41 +01:00
David Adams b5d1279107 Allow specifying a default value to lookup()
Fixes #4474, where lookup() calls fail out the entire interpolation when
the provided key value is not found in the map. This will allow using
coalesce() along with lookup() to greatly improve module flexibility.
2016-05-25 19:25:15 -05:00
David Glasser 594ea105d8 config: support lists and maps in jsonencode
For now we only support lists and maps whose values are strings, not
deeply nested data.
2016-05-18 10:46:06 -07:00
Martin Atkins 60c24e3319 command: Prevent data resources from being tainted
Since the data resource lifecycle contains no steps to deal with tainted
instances, we must make sure that they never get created.

Doing this out in the command layer is not the best, but this is currently
the only layer that has enough information to make this decision and so
this simple solution was preferred over a more disruptive refactoring,
under the assumption that this taint functionality eventually gets
reworked in terms of StateFilter anyway.
2016-05-14 08:26:37 -07:00
Martin Atkins 718cdda77b config: Parsing of data.TYPE.NAME.FIELD variables
This allows ${data.TYPE.NAME.FIELD} interpolation syntax at the
configuration level, though since there is no special handling of them
in the core package this currently just acts as an alias for
${TYPE.NAME.FIELD}.
2016-05-14 08:26:35 -07:00
Martin Atkins 860140074f config: Data source loading
This allows the config loader to read "data" blocks from the config and
turn them into DataSource objects.

This just reads the data from the config file. It doesn't validate the
data nor do anything useful with it.
2016-05-14 08:26:35 -07:00
Martin Atkins fc4fa10981 config: "ResourceMode" concept for resources
Previously resources were assumed to always support the full set of
create, read, update and delete operations, and Terraform's resource
management lifecycle.

Data sources introduce a new kind of resource that only supports the
"read" operation. To support this, a new "Mode" field is added to
the Resource concept within the config layer, which can be set to
ManagedResourceMode (to indicate the only mode previously possible) or
DataResourceMode (to indicate that only "read" is supported).

To support both managed and data resources in the tests, the
stringification of resources in config_string.go is adjusted slightly
to use the Id() method rather than the unusual type[name] serialization
from before, causing a simple mechanical adjustment to the loader tests'
expected result strings.
2016-05-14 08:26:35 -07:00
Mitchell Hashimoto 27452f0043
terraform: Module option to Import to add module to graph 2016-05-11 13:02:37 -07:00
Mitchell Hashimoto 3c9a92e04a
command: Context buliding allows empty module trees 2016-05-11 13:02:34 -07:00
James Nugent f1d0fc46aa core: Fix go vet issues shown by Travis 2016-05-10 16:00:28 -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
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
James Nugent a0cc7115b3 deps: Update call sites of hil.Eval from update
hil.Eval() now returns (hil.EvaluationResult, error) instead of (value,
type, error). This commit updates the call sites, but retains all
previous behaviour. Tests are also updated.
2016-04-18 16:37:12 -07:00
James Nugent d7d39702c0 Type check variables between modules (#6185)
These tests demonstrates a problem where the types to a module input are 
not checked. For example, if a module - inner - defines a variable
"should_be_a_map" as a map, or with a default variable of map, we do not
fail if the user sets the variable value in the outer module to a string
value. This is also a problem in nested modules.

The implementation changes add a type checking step into the graph
evaluation process to ensure invalid types are not passed.
2016-04-15 12:07:54 -07:00
David Glasser 6cf06bb3ab config: new interpolation function jsonencode 2016-03-29 07:38:58 -07:00
Paul Hinze 293c6ca68c Revert "Revert "core: Add uuid() interpolate function.""
This reverts commit 661be01d9b.
2016-03-21 15:14:30 -05:00
Paul Hinze 567a9b9e06 config: remove missing equals test to fix build
This is behavior that's covered in the parser now - and the error
message is nicer to boot!
2016-03-21 10:39:20 -05:00
James Nugent 87550b2b72 Merge pull request #5263 from uber/b-element-negative
Error out on negative indices in element()
2016-03-16 09:39:35 +00:00
Paul Hinze 661be01d9b Revert "core: Add uuid() interpolate function." 2016-03-15 18:39:34 -05:00
Paul Hinze 1e0b8ea478 core: Add uuid() interpolate function.
Utilizes hashicorp's go-uuid library for proper random seeding setup.
2016-03-10 18:39:07 -06:00
Radek Simko 664ba5f5a6 config: Add new interpolation function - md5 2016-02-24 13:01:05 +00:00
Radek Simko 573d3bd7ab config: Sort functions mapping alphabetically 2016-02-24 13:01:05 +00:00
Bill Fumerola c0034e672b Error out on negative indices in element() 2016-02-22 15:58:47 -08:00
Jeff Zohrab 33d30761dd Add hint to download modules for new users. 2016-02-17 11:32:44 -05:00
Paul Hinze 9a00675262 Merge pull request #5026 from hashicorp/phinze/destroy-node-copies
core: Make copies when creating destroy nodes
2016-02-09 11:12:01 -06:00
Paul Hinze 3f72837f4b core: Make copies when creating destroy nodes
Fixes an interpolation race that was occurring when a tainted destroy
node and a primary destroy node both tried to interpolate a computed
count in their config. Since they were sharing a pointer to the _same_
config, depending on how the race played out one of them could catch the
config uninterpolated and would then throw a syntax error.

The `Copy()` tree implemented for this fix can probably be used
elsewhere - basically we should copy the config whenever we drop nodes
into the graph - but for now I'm just applying it to the place that
fixes this bug.

Fixes #4982 - Includes a test covering that race condition.
2016-02-09 09:25:16 -06:00
Radek Simko 4edf782260 Merge pull request #4854 from jfromaniello/add_signum_interpolation
Add signum interpolation function
2016-02-07 19:44:16 +00:00
Mitchell Hashimoto 5f3de02fa9 remove config/lang, use hashicorp/hil 2016-02-03 13:24:04 -05:00
Radek Simko ecedcd0032 config: Add base64sha256() function 2016-01-30 13:19:10 +01:00
Colin Hebert 61a40dce13 Update the test file 2016-01-30 20:52:45 +11:00
Colin Hebert d92d205dd9 rename trim to trimspace 2016-01-30 20:51:28 +11:00
Colin Hebert d45b7b2ddc Fix name from strip to trim 2016-01-30 10:32:18 +11:00
Colin Hebert f5074cd521 Add the trim() interpolation function 2016-01-30 10:28:04 +11:00
José F. Romaniello c8795b8565 Add signum interpolation function
This function returns -1 for negative numbers, 0 for 0 and 1 for positive numbers.

Useful when you need to set a value for the first resource and a different value for the rest of the resources.

Example: `${element(split(",", var.r53_failover_policy), signum(count.index))}`
2016-01-27 12:49:52 -03:00
James Nugent 3bdd1ac8b3 core: Display invalid type in error message
If a variable type which is invalid (e.g. "stringg") is declared, we now
include the invalid type description in the error message to make it
easier to track down the source of the error in the source file.
2016-01-25 10:21:12 -06:00
James Nugent cb6cb8b96a core: Support explicit variable type declaration
This commit adds support for declaring variable types in Terraform
configuration. Historically, the type has been inferred from the default
value, defaulting to string if no default was supplied. This has caused
users to devise workarounds if they wanted to declare a map but provide
values from a .tfvars file (for example).

The new syntax adds the "type" key to variable blocks:

```
variable "i_am_a_string" {
    type = "string"
}

variable "i_am_a_map" {
    type = "map"
}
```

This commit does _not_ extend the type system to include bools, integers
or floats - the only two types available are maps and strings.

Validation is performed if a default value is provided in order to
ensure that the default value type matches the declared type.

In the case that a type is not declared, the old logic is used for
determining the type. This allows backwards compatiblity with previous
Terraform configuration.
2016-01-24 11:40:02 -06:00
Paul Hinze 87a9701f91 config: validation error when output is missing value field
Also lists out invalid keys in errmsg when they are present

Closes #4398
2016-01-20 14:00:36 -06:00
Paul Hinze 47b521ebaf Merge pull request #4745 from hashicorp/b-lifecycle-keys
config: validate lifecycle keys [GH-4413]
2016-01-19 18:24:54 -06:00
Paul Hinze 911575b7d6 Merge pull request #4747 from hashicorp/b-escaped
Literals with escaped interpolations work
2016-01-19 18:23:08 -06:00
Mitchell Hashimoto 693736b52a config: fix tests 2016-01-19 13:17:47 -08:00
Mitchell Hashimoto f223be15cd config: eval HEL as long as the result changes [GH-2909] 2016-01-19 12:51:56 -08:00
Mitchell Hashimoto 8e7b0d90e3 config: detect provisioner-only resource in JSON and error [GH-4385] 2016-01-19 12:19:32 -08:00
Mitchell Hashimoto 99fbb91ba2 config: validate lifecycle keys [GH-4413] 2016-01-19 11:28:45 -08:00
Matt Moyer c17a6ceb2a Add a sha256(...) interpolation function. 2016-01-16 23:54:04 +00:00
Paul Hinze 0739cf2348 provider/template: fix race causing panic in template_file
The render code path in `template_file` was doing unsynchronized access
to a shared mapping of functions in `config.Func`.

This caused a race condition that was most often triggered when a
`template_file` had a `count` of more than one, and expressed itself as
a panic in the plugin followed by a cascade of "unexpected EOF" errors
through the plugin system.

Here, we simply turn the FuncMap from shared state into a generated
value, which avoids the race. We do more re-initialization of the data
structure, but the performance implications are minimal, and we can
always revisit with a perf pass later now that the race is fixed.
2016-01-15 16:34:46 -05:00
Joseph Kordish e1b62c76ad add sha1 interpolation 2016-01-06 15:10:43 -06:00
Jesse Szwedko 41f9ebc667 Add support for unary operators + and -
This adds support to the configuration interpolation syntax for + and -
as unary operators, specifically to represent negative numbers.
2015-12-18 18:05:25 +00:00
Paul Hinze b6626eed57 config: friendlier error message on resource arity mismatch
closes #2072
2015-12-09 18:05:49 -06:00
James Nugent 5ea25363a1 Add regression test for #4069
This may be brittle as it makes use of .gitattributes to override the
autocrlf setting in order to have an input file with Windows line
endings across multiple platforms.
2015-12-01 13:37:18 -05:00
Paul Hinze d90eb2d88e config: test replicating #4079
Should help cover terraform against regression once
https://github.com/hashicorp/hcl/pull/70 lands.
2015-12-01 10:31:05 -06:00
James Nugent 7f5f8d300d Add failing test replicating #4065 2015-11-26 15:08:48 +02:00
Paul Hinze afb5136ac2 Merge pull request #3986 from hashicorp/phinze/hcl-escaped-quotes
config: test covering escaped quotes syntax error
2015-11-19 12:32:30 -06:00
Paul Hinze 15e7927009 config: test covering escaped quotes syntax error
This was never intended to be valid syntax, but it worked in the old HCL
parser, and we've found a decent number of examples of it in the wild.

Fixed in https://github.com/hashicorp/hcl/pull/62 and we'll keep this
test in Terraform to cover the behavior.
2015-11-19 12:11:42 -06:00
James Nugent 6ae3218f8a Add failing tests for JSON configuration parsing
Reproduces the issue reported by @svanharmelen in #3964.
2015-11-19 16:06:30 +02:00
Paul Hinze 928f534cfc template_file: source contents instead of path
Building on the work of #3846, deprecate `filename` in favor of a
`template` attribute that accepts file contents instead of a path.

Required a bit of work in the interpolation code to prevent Terraform
from assuming that template interpolations were resource variables that
needed to be resolved. Leaving them as "Unknown Variables" prevents
interpolation from happening early and lets the `template_file` resource
do its thing.
2015-11-13 11:24:20 -06:00
James Nugent f4164b5322 Add resource with heredoc to config load tests
This test reproduces the issue which is likely the root cause of #3840.
Test is currently failing with an "illegal character" message
corresponding with the location of the heredoc, which is also seen in
various acceptance tests for providers.
2015-11-10 18:12:21 -05:00
Mitchell Hashimoto deb17b90eb Merge pull request #3813 from hashicorp/b-new-hcl
Use new HCL API
2015-11-09 10:34:48 -08:00
Martin Atkins 988baa584b Merge #3814: 'coalesce' interpolation func 2015-11-09 09:31:18 -08: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
Matt Morrison 6ecec7fe83 Add coalesce func 2015-11-08 19:34:56 +13:00
Mitchell Hashimoto 13c5fdb154 config: remove debug line 2015-11-07 16:55:07 -08:00
Mitchell Hashimoto 02f512d4bd config: new HCL API 2015-11-07 16:53:42 -08:00
Paul Hinze c56245ce34 Merge pull request #2973 from bobtfish/length_empty_split_zero
Split of "" should be empty. Length of empty array should be 0
2015-10-29 14:58:36 -05:00
Paul Hinze af04321723 config: return to the go1.5 generated lang/y.go
It has improvements to error messaging that we want.

We'll use this occasion begin developing / building with Go 1.5 from
here on out. Build times will be slower, but we have core development
plans that will help mitigate that.

/cc @hashicorp/terraform-committers
2015-10-28 12:20:18 -04:00
Tomas Doran 96275ee66a Add an explicit test for PR #2973 2015-10-25 18:55:21 +00:00
Martin Atkins ef161e1c1b Various interpolation functions for CIDR range manipulation.
These new functions allow Terraform to be used for network address space
planning tasks, and make it easier to produce reusable modules that
contain or depend on network infrastructure.

For example:
- cidrsubnet allows an aws_subnet to derive its
  CIDR prefix from its parent aws_vpc.
- cidrhost allows a fixed IP address for a resource to be assigned within
  an address range defined elsewhere.
- cidrnetmask provides the dotted-decimal form of a prefix length that is
  accepted by some systems such as routing tables and static network
  interface configuration files.

The bulk of the work here is done by an external library I authored called
go-cidr. It is MIT licensed and was implemented primarily for the purpose
of using it within Terraform. It has its own unit tests and so the unit
tests within this change focus on simple success cases and on the correct
handling of the various error cases.
2015-10-22 08:10:52 -07:00
Matt Morrison cccc5d03e3 Add lower / upper interpolation functions 2015-10-21 08:16:24 -07:00
Paul Hinze 77847b1572 config/lang: restore go1.4.3 generated code
my theory is that @mitchellh checked in a go1.5 generated file in
344e7c26b5
2015-10-21 09:49:23 -05:00
Mitchell Hashimoto 344e7c26b5 fix a bunch of tests from go-getter import 2015-10-15 13:48:58 -07:00
Mitchell Hashimoto 06f4ac8166 config/module: use go-getter 2015-10-15 13:36:58 -07:00
Rob Zienert a1939e70f7 Adding ignore_changes lifecycle meta property 2015-10-14 16:34:27 -05:00
Martin Atkins 3c939f9b26 Merge #3239: "compact" interpolation function 2015-10-10 15:18:10 -07:00
Martin Atkins 16b11e443d go fmt the "compact" function changes. 2015-10-10 15:17:25 -07:00
Svend Sorensen 73b51698ad Replace simple case with if 2015-10-08 17:58:19 +02:00
Svend Sorensen 8e4a313f17 Return an empty slice for empty string lists 2015-10-08 17:37:13 +02:00
Svend Sorensen 53f44878ff Add tests for empty string lists 2015-10-08 17:32:54 +02:00
Anthony Stanton f2f4ded970 Initialize list as an empty slice 2015-10-08 16:59:57 +02:00
Panagiotis Moustafellos e4845f75cc removed extra parentheses 2015-10-08 15:48:04 +03:00
Anthony Stanton aed3f98703 Rename func which is now a method. 2015-10-08 10:01:21 +02:00
Anthony Stanton 95b2a60b29 Use {a,b} instead of {b,c}
How does the alphabet even?
2015-10-08 10:01:21 +02:00
Anthony Stanton ef2b0a0b71 Order functions alphabetically 2015-10-08 10:01:21 +02:00
Anthony Stanton 735803ef09 Test cases for compact() 2015-10-08 10:00:32 +02:00
Anthony Stanton 7610874264 Initial implementation of compact() interpolation function 2015-10-08 10:00:32 +02:00
Martin Atkins 3fde993978 Merge #3336: Remove local multierror package.
Instead, use ``github.com/hashicorp/go-multierror``.
2015-10-03 17:53:36 -07:00
Martin Atkins 0b85d35e87 Rename base64enc/dec to encode/decode.
There isn't any precedent for abbreviating words in the interpolation
function names, and it may not be clear to all users what "enc" and "dec"
are short for, so instead we'll prefer to spell out the whole words for
improved readability.
2015-10-03 15:12:51 -07:00
Sander van Harmelen 2ba8dc38fa Switch to go-multierror
It seems there are 4 locations left that use the `helper/multierror`
package, where the rest is TF settled on the `hashicorp/go-multierror`
package.

Functionally this doesn’t change anything, so I suggest to delete the
builtin version as it can only cause confusion (both packages have the
same name, but are still different types according to Go’s type system.
2015-09-27 18:58:48 -07:00
Gorka Lerchundi Osa 70522fb770 implements base64{enc,dec} interpolation funcs
fixes #3320

Signed-off-by: Gorka Lerchundi Osa <glertxundi@gmail.com>
2015-09-25 09:23:36 +02:00
Anthony Scalisi 198e1a5186 remove various typos 2015-09-11 11:56:20 -07:00
Radek Simko 563fd3872b Add a few tests for string_list 2015-08-27 13:02:02 +01:00
Jason Gedge cf5926ddad Add a function to find the index of an element in a list. 2015-07-13 14:11:30 -04:00
Mitchell Hashimoto 89d44e5088 Merge pull request #2505 from hashicorp/b-var-splat
config/lang: don't see * as part of var name [GH-2046]
2015-06-26 08:20:25 -07:00
Mitchell Hashimoto 97d2c4a6de config/lang: don't see * as part of var name [GH-2046] 2015-06-25 19:52:50 -07:00
Paul Hinze c95f21cec1 config: make formatlist work on lists of length 1
removes treat-lists-as-scalar special casing for formatlist

/cc @radeksimko

fixes #2240
2015-06-25 18:55:28 -05:00
Paul Hinze e88aeede9b core: allow distinguishing between empty lists and strings
Had to handle a lot of implicit leaning on a few properties of the old
representation:

 * Old representation allowed plain strings to be treated as lists
   without problem (i.e. shoved into strings.Split), now strings need to
   be checked whether they are a list before they are treated as one
   (i.e. shoved into StringList(s).Slice()).
 * Tested behavior of 0 and 1 length lists in formatlist() was a side
   effect of the representation. Needs to be special cased now to
   maintain the behavior.
 * Found a pretty old context test failure that was wrong in several
   different ways. It's covered by TestContext2Apply_multiVar so I
   removed it.
2015-06-25 18:53:35 -05:00
Paul Hinze 7238b3b4af core: encapsulate representation of StringList
Now the only code that cares about how StringLists are represented lives
inside string_list.go

...which gives us the ability to change it! :)
2015-06-25 17:55:57 -05:00
Paul Hinze 10b3abf405 config: introduce StringList to abstract over list hack
This is the initial pure "all tests passing without a diff" stage. The
plan is to change the internal representation of StringList to include a
suffix delimiter, which will allow us to recognize empty and
single-element lists.
2015-06-25 17:55:56 -05:00
Mitchell Hashimoto 29eadb8194 terraform: missing provider should add missing aliases [GH-2023] 2015-06-24 20:58:52 -07:00
Mitchell Hashimoto 461f6557c7 config: fix test error 2015-06-23 22:30:41 -07:00
Mitchell Hashimoto fafc32b183 Merge branch 'b-prevent-destroy-type' 2015-06-23 22:29:54 -07:00
Paul Hinze c154ef9558 Merge pull request #1790 from TimeIncOSS/combine-func
config: Add support for lists to concat
2015-06-23 15:41:59 -05: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
Radek Simko 6a60fa4bfe config: concat function supports lists (combines more lists into one) 2015-06-13 08:54:01 +01:00
Radek Simko e9e41dfd05 Improve test error messages 2015-06-13 08:54:01 +01:00
Radek Simko 841a1f08da Sort functions by name alphabetically 2015-06-13 08:54:01 +01:00
Mitchell Hashimoto aa1e66c16c config: parse lifecycle block with mapstructure for weak decode 2015-06-07 22:04:23 -07:00
Paul Hinze b781c6c446 core: keys() and values() funcs for map variables
they work on maps with both keys and values that are string types, which
AFAICT are the only types of maps we have right now.

closes #1915
2015-06-02 16:49:51 -05:00
Sam Boyer b82bd0c280 Condense switch fallthroughs into expr lists 2015-05-26 21:52:36 -04:00
Josh Bleecher Snyder 02e751e356 config: add formatlist
formatlist distributes formatting over lists.
See the docs for details.

As a colleague commented:

"It happens all the time that we want a set of
outputs, but in a slightly different way than
just simple joining or concatting."

formatlist (combined with join)
makes it easy to satisfy those needs.
2015-05-12 16:11:42 -07:00
Josh Bleecher Snyder a3f79cd790 config: fix minor comment errors 2015-05-12 16:11:19 -07:00
Mitchell Hashimoto 1099e3f59f config: add module raw configs to InterpolatedConfigs [GH-1448] 2015-04-29 17:12:28 -07:00
Mitchell Hashimoto cca4964552 config: error in validation if module has self variable 2015-04-22 10:39:07 +02:00
Mitchell Hashimoto d0a6d78b97 config: test that resources reference good providers 2015-04-20 14:47:31 -07:00
Mitchell Hashimoto 8ee18e2e14 config: happy case test for multiple providers 2015-04-20 14:27:44 -07:00
Mitchell Hashimoto a599d5f224 config: validate that a multi provider is only configured once each 2015-04-20 14:25:33 -07: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
Paul Hinze afe4abb637 core: add prevent_destroy lifecycle flag
When the `prevent_destroy` flag is set on a resource, any plan that
would destroy that resource instead returns an error. This has the
effect of preventing the resource from being unexpectedly destroyed by
Terraform until the flag is removed from the config.
2015-04-17 10:40:04 -05:00
Paul Hinze 5874fa06ff Merge pull request #1495 from TimeIncOSS/length-func
config: Add length to built-in functions
2015-04-15 11:54:46 -05:00
Paul Hinze 975a96f271 core: protect against count.index in modules
Modules should get a validation error just like outputs do.

refs #1528
2015-04-15 10:41:56 -05:00
Paul Hinze 347690a73e core: don't crash when count.index is used in the wrong context
It's bad manners! :)

Also adds a validation error up at the configuration layer so the user
sees the case from #1528 as an error message.

fixes #1528
2015-04-15 10:23:53 -05:00
Radek Simko 6a720d087c length added to built-in functions 2015-04-15 16:20:11 +01:00
Mitchell Hashimoto 0ff39a3773 config/lang: support math on variables through implicits 2015-04-14 09:09:18 -07:00
Radek Simko 8eb6984a89 Test helpers to print expected output 2015-04-13 14:12:43 +01:00
Mitchell Hashimoto 6514bf5f25 config: clarify unknown variable error [GH-1480] 2015-04-10 16:45:15 -07:00
Mitchell Hashimoto 06beab6fd8 config: copy the key on Copy 2015-04-09 09:31:04 -07:00
Mitchell Hashimoto b201983304 terraform: copy RawConfigs 2015-04-09 09:21:38 -07:00
Mitchell Hashimoto aab7bc0da5 config/module: rename parameters 2015-04-07 17:07:50 -07:00
Mitchell Hashimoto 2378160803 config/module: determine storage folder by path 2015-04-07 16:44:24 -07:00
Mitchell Hashimoto f084d8d932 config/module: store the path with the module 2015-04-07 16:37:46 -07:00
Paul Hinze 766b4902d4 remove extraneous var declaration
just a go nitpick :)
2015-03-30 19:03:01 -05:00
7heo a6411626bf config: interprets '~' as the current user home dir in file() 2015-03-31 01:52:39 +02:00
Mitchell Hashimoto 44fce5ce60 config/module: remove debug 2015-03-26 09:31:58 -07:00
Mitchell Hashimoto 2e11ca68df config/module: go back to the original folder when doing parent
references
2015-03-26 09:30:32 -07:00
Mitchell Hashimoto bd4aaac71a config/module: failing unit test for GH-1232 2015-03-26 09:11:32 -07:00
Mitchell Hashimoto fdded8ca14 config: allow atlas block 2015-03-24 13:30:22 -07:00
Mitchell Hashimoto f84ae29cf8 config: isTemporaryFile -> isIgnoredFile 2015-03-19 09:51:14 +01:00
Radek Simko f794f30b7d Ignore hidden files per Unix conventions 2015-03-18 07:50:33 +00:00
Mitchell Hashimoto 23609a7af5 Merge pull request #1096 from hashicorp/f-sprintf
config: add "format' function [GH-758]
2015-03-04 16:05:25 -08:00
Mitchell Hashimoto 9e50bf76c7 config/lang: test case for multiline lang 2015-03-02 23:31:49 -08:00
Mitchell Hashimoto b39ddc7d47 config: add format function 2015-03-02 10:26:06 -08:00
Mitchell Hashimoto 63ee4c83ab config: only regexp if at least two characters in replace search 2015-03-02 09:46:46 -08:00
Mitchell Hashimoto 5895494897 config: test bad regexp for replace 2015-03-02 09:44:45 -08:00
Mitchell Hashimoto 2f33a24385 config: add replace function 2015-03-02 09:37:40 -08:00
Mitchell Hashimoto 5e25dc54a7 config: if any var is computed, the entire interpolation is computed 2015-02-27 22:47:43 -08:00
Mitchell Hashimoto 2feaebdca5 config: substring containing computed value replaces element 2015-02-27 21:51:14 -08:00
Mitchell Hashimoto 5848cba6ad config/lang: add modulo 2015-02-26 15:17:37 -08:00
Mitchell Hashimoto 3c4a036fb5 config/lang: add (expr) for order of ops 2015-02-26 14:39:04 -08:00
Mitchell Hashimoto 6750318bb5 config/lang: add test with expressions 2015-02-26 14:34:45 -08:00
Mitchell Hashimoto 9ddcaf15eb config/lang: fix shift/reduce conflict 2015-02-26 14:33:56 -08:00
Mitchell Hashimoto 07b78fdf84 config/lang: math operations 2015-02-26 14:26:14 -08:00
Mitchell Hashimoto 684228e371 config/lang: add math operations for ints 2015-02-26 11:32:39 -08:00
Mitchell Hashimoto cab2e408d2 config/module: retry bitbucket test a few times [GH-1027] 2015-02-23 15:24:24 -08:00
Mitchell Hashimoto 965fe45b9e config: self var validation 2015-02-23 14:43:14 -08:00
Mitchell Hashimoto 9c612964d8 config: self variables 2015-02-23 14:34:25 -08:00
Mitchell Hashimoto a31f2a276b Merge pull request #1015 from hashicorp/b-depends-on-var
config: depends on cannot contain interpolations [GH-985]
2015-02-23 13:49:34 -08:00
Mitchell Hashimoto 87ecf4f40d Merge pull request #1016 from hashicorp/b-splat-validate
config: provisioner splat vars can only reference other resources
2015-02-23 13:48:40 -08:00
Mitchell Hashimoto 45a267111b Merge pull request #885 from brycekahle/split-func
config: add split function
2015-02-20 13:45:01 -08:00
Mitchell Hashimoto c14e84a657 config: validate provisioner splats can only reference others 2015-02-20 09:21:29 -08:00
Mitchell Hashimoto f156d0d1bd config: test we can ref splat of other resources 2015-02-20 09:19:13 -08:00
Mitchell Hashimoto 90a6a627ed config: validate configuration doens't contain splats to ourselves 2015-02-20 09:18:08 -08:00
Mitchell Hashimoto 0e7b150c5b config: depends on cannot contain interpolations [GH-985] 2015-02-20 09:07:41 -08:00
Mitchell Hashimoto 0a68576746 config: add RawConfig.Merge 2015-02-19 12:07:59 -08:00
Mitchell Hashimoto 4bcf6cf6b2 config: bare splat variables should not be allowed in provisioners
[GH-636]
2015-02-17 13:32:45 -08:00
Emil Hessman e7bbbfb098 helper/url: add Windows 'safe' URL Parse wrapper
Pull out the urlParse function, which was introduced in config/module,
into a helper package.
2015-02-05 11:16:54 +01:00
Emil Hessman a8db835a44 config/module: fix HgGetter test failures on Windows
HgGetter tests failed on windows/amd64 using Mercurial version 3.2.4:

--- FAIL: TestHgGetter (0.11s)
        get_hg_test.go:35: err: C:\Program Files\Mercurial\hg.exe exited with 255: abort: file:// URLs can only refer to localhost
--- FAIL: TestHgGetter_branch (0.11s)
        get_hg_test.go:62: err: C:\Program Files\Mercurial\hg.exe exited with 255: abort: file:// URLs can only refer to localhost
FAIL
FAIL    github.com/hashicorp/terraform/config/module    5.615s

This commit fixes the failures by adjusting the file:// URL to a form that
Mercurial expects.
2015-02-02 19:49:57 +01:00
Emil Hessman 5bbfc0d4e2 config/module: fix URL file path handling on Windows
Only adjust the URL Scheme when parsing drive letter file paths on
Windows, don't add a file scheme prefix.
FileDetector is responsible for adding the file scheme prefix.
2015-02-02 12:19:34 +01:00
Mitchell Hashimoto 2d9dd25493 config/module: fix regression of ignoring forced type if valid URL
/cc @ceh - Does this break Windows at all? This regressed with your
commit (we didn't have test coverage on it). I added a test now, though.
2015-02-01 20:17:56 +01:00
Bryce Kahle adccaad252 Add split function 2015-01-28 16:59:16 -05:00
Emil Hessman 97227a5c70 config/module: fix detection of file paths on Windows
Absolute file paths were not correctly detected by module.Detect
when using url.Parse to parse the source URL. Wrap the detection
with urlParse to properly handle file path detections on Windows.

Fixes command test failures on Windows.
2015-01-28 10:40:32 +01:00
Emil Hessman 65177edd1e config/module: fix test failures on Windows
When parsing URLs on Windows, assume it is a drive letter path
if the second element is a ':' character. Format the drive letter
path as a "file:///"-path prior to parsing the URL.

Fixes test failures of the following form in command on Windows:

=== RUN TestApply_plan
--- FAIL: TestApply_plan (0.00s)
        apply_test.go:379: bad: 1

		module download not supported for scheme 'c'
2015-01-28 08:19:04 +01:00
Emil Hessman d5a49363d7 config/module: handle absolute file paths on Windows
Using url.Parse to parse an absolute file path on Windows yields
a URL type where the Path element is prefixed by a slash.

For example, parsing "file:///C:/Users/user" gives a URL type
with Path:"/C:/Users/user".

According to golang.org/issue/6027, the parsing is correct as is.

The leading slash on the Path must be eliminated before any file
operations.

This commit introduces a urlParse function which wraps the url.Parse
functionality and removes the leading slash in Path for absolute file
paths on Windows.

Fixes config/module test failures on Windows.
2015-01-27 23:18:47 +01:00
Emil Hessman 78d1fc742f config/module: adjust HttpGetter test to fix Windows test failure
Specify laddr on the form host:port in the call to net.Listen as
documented for net.Dial, see godoc.org/net#Dial

Fixes the following test failures on Windows:

> go test -run=TestHttpGetter
--- FAIL: TestHttpGetter_header (0.00s)
        get_http_test.go:31: err: Get http://[::]:52101/header?terraform-get=1: dial tcp [::]:52101: ConnectEx tcp: The requested address is not valid in its context.
--- FAIL: TestHttpGetter_meta (0.00s)
        get_http_test.go:55: err: Get http://[::]:52103/meta?terraform-get=1: dial tcp [::]:52103: ConnectEx tcp: The requested address is not valid in its context.
--- FAIL: TestHttpGetter_metaSubdir (0.00s)
        get_http_test.go:79: err: Get http://[::]:52105/meta-subdir?terraform-get=1: dial tcp [::]:52105: ConnectEx tcp: The requested address is not valid in its context.
FAIL
exit status 1
FAIL github.com/hashicorp/terraform/config/module    0.054s
2015-01-27 23:18:46 +01:00
Emil Hessman 74cf8fcabd config/module: adjust FileDetector tests for Windows
"/foo" is not an absolute path on Windows. Adjust the FileDetector
tests to take that into account when verifying the results.

Fixes FileDetector test failures on Windows.
2015-01-27 23:18:46 +01:00
Emil Hessman 160e4f926e config/module: fix panic on Windows when running tests
On Windows, Go returns paths with the `\` path separator.
Make sure we are using `/` even on Windows since URLs are `/`-based.
2015-01-27 07:52:51 +01:00
Mitchell Hashimoto 63344a37c6 config/lang: verify single quotes syntax error [GH-613] 2015-01-16 10:28:00 -08:00
Mitchell Hashimoto 91a3405e88 config: understand provisioner blocks in JSON [GH-807] 2015-01-16 10:14:48 -08:00
Mitchell Hashimoto 7f9abbb99c config/lang; missed file 2015-01-15 09:40:36 -08:00
Mitchell Hashimoto a2e40ad731 config: multi-variable access in slice validation fixed [GH-798] 2015-01-15 09:40:13 -08:00
Mitchell Hashimoto 2abeb2d9ac config: use new API 2015-01-14 22:03:15 -08:00
Mitchell Hashimoto 61ee63d842 config/lang/ast: remove unused Eval 2015-01-14 21:49:39 -08:00
Mitchell Hashimoto 8d2c60a8af config/lang: eval 2015-01-14 21:48:20 -08:00
Mitchell Hashimoto 4302dbaf2a config/lang: make TypeCheck implementable by other nodes 2015-01-14 21:18:22 -08:00
Mitchell Hashimoto 57adfe53f6 config/lang: use the new AST stuff 2015-01-14 20:58:46 -08:00
Mitchell Hashimoto c96b3b9ddc config/lang/ast: Eval 2015-01-14 20:37:16 -08:00
Mitchell Hashimoto c4273974de config/lang/ast: introduce Type 2015-01-14 20:13:35 -08:00
Mitchell Hashimoto 342b4d2d9f config/lang: proper filename 2015-01-14 16:36:42 -08:00
Mitchell Hashimoto 1e79861b84 config/lang/ast: AST transforms are built-in 2015-01-14 16:36:01 -08:00
Mitchell Hashimoto d3c0543bf3 Merge pull request #797 from hashicorp/f-stronger-types
Force variables to be typed (internally)
2015-01-14 15:30:38 -08:00
Emil Hessman 482460c4c8 config/lang: address vet reports
Fixes the following vet reports:

config/lang/check_types.go:98: arg n for printf verb %d of wrong type: *github.com/hashicorp/terraform/config/lang/ast.Concat
config/lang/lex.go:80: arg x.mode for printf verb %s of wrong type: lang.parserMode
2015-01-14 22:04:28 +01:00
Mitchell Hashimoto 6e29ea0366 config/lang: some hoops to get the types to work 2015-01-14 12:18:51 -08:00
Mitchell Hashimoto 591610deea config/lang: string to int 2015-01-14 12:02:26 -08:00
Mitchell Hashimoto d12bf66403 config/lang: implicit builtins are coming in 2015-01-14 11:59:06 -08:00
Mitchell Hashimoto 36b6601baf config/lang: implicit type conversions 2015-01-14 11:47:20 -08:00
Mitchell Hashimoto 8ae14f06b3 config: variables must be typed 2015-01-14 10:40:43 -08:00
Mitchell Hashimoto dd456871e9 config/lang: remove unused code 2015-01-14 10:11:29 -08:00
Mitchell Hashimoto 92af4801a1 config: reintroduce concat 2015-01-13 12:47:54 -08:00
Mitchell Hashimoto 8d51b6b1d4 config/lang: variadic functions 2015-01-13 12:40:47 -08:00
Mitchell Hashimoto 4af4c9e16c config: add lookup function back 2015-01-13 12:06:04 -08:00
Mitchell Hashimoto 49fe0d5c7f config: remove a lot of unused stuff 2015-01-13 11:54:30 -08:00
Mitchell Hashimoto 1ccad4d729 config: convert fucntions, put functions into Scope 2015-01-13 11:50:44 -08:00
Mitchell Hashimoto 4ba7de17a9 config/lang: call the proper functions on Scope 2015-01-13 11:27:10 -08:00
Mitchell Hashimoto 2b679572b4 config/lang: TypeCheck 2015-01-13 11:25:46 -08:00
Mitchell Hashimoto 8ce7ef6188 config/lang: implement identifier semantic check 2015-01-13 11:24:42 -08:00
Mitchell Hashimoto 5abbde3ac9 config: remove unused files 2015-01-13 10:32:03 -08:00
Mitchell Hashimoto 740c25d4ea config: convert to config/lang 2015-01-13 10:27:57 -08:00
Mitchell Hashimoto e68fbceebc config/lang: fix bug parsing empty strings 2015-01-13 10:27:31 -08:00
Mitchell Hashimoto c424a8a815 config/lang: FixedValueTransform 2015-01-13 10:10:33 -08:00
Mitchell Hashimoto d1a0ea9d9b config/lang: make formal Stack object 2015-01-13 09:46:13 -08:00
Mitchell Hashimoto 6d9db3139c config/lang: AST String() methods 2015-01-13 08:50:28 -08:00
Mitchell Hashimoto abca82a84e config: another test 2015-01-12 12:13:30 -08:00
Mitchell Hashimoto aa2c7b2764 config: DetectVariables to detect interpolated variables in an AST 2015-01-12 12:09:43 -08:00
Mitchell Hashimoto c05d7a6acd config/lang: escaping interpolations with double dollar signs 2015-01-12 11:00:56 -08:00
Mitchell Hashimoto c15c17dfe9 config/lang: remove unused file 2015-01-12 10:48:20 -08:00
Mitchell Hashimoto f836397d8d config/lang: enable type checking in execution 2015-01-12 10:21:18 -08:00
Mitchell Hashimoto ec3b5f3886 config/lang: implement type lookup 2015-01-12 09:57:16 -08:00
Mitchell Hashimoto 25a2fbc902 config/lang: integer and float types 2015-01-12 08:53:27 -08:00
Mitchell Hashimoto a0926de4a9 config/lang: completed type checking 2015-01-12 00:35:43 -08:00
Mitchell Hashimoto 662760da11 config/lang: have position in AST 2015-01-12 00:28:47 -08:00
Mitchell Hashimoto d3b1010444 config/lang: start implementing type checking 2015-01-11 23:38:21 -08:00
Mitchell Hashimoto 8f925b93e0 config/lang: function calls work 2015-01-11 15:33:24 -08:00
Mitchell Hashimoto 4ae8cae9e7 config/lang: execution 2015-01-11 15:26:54 -08:00
Mitchell Hashimoto fa7891d182 config/lang/ast: use stringer to generate enums 2015-01-11 14:35:14 -08:00
Mitchell Hashimoto 1ff5a838a4 config/lang: can parse nested interpolations 2015-01-11 13:59:24 -08:00
Mitchell Hashimoto 669bdc61f9 config/lang: more implemented 2015-01-11 13:03:37 -08:00
Mitchell Hashimoto fcdcf117f0 config/lang: initial work 2015-01-11 12:38:45 -08:00
Armon Dadgar 69ca9efeea Merge pull request #700 from Banno/fix-interpolated-func-with-colon
Adding colon to interpolated regex so they can be used in concats
2015-01-05 11:42:46 -08:00
Mitchell Hashimoto 6b7dfb4c8f config: some extra comments 2014-12-26 09:05:24 +05:30
Luke Amdor e970eea3cd adding literal colon to interpolated regex 2014-12-21 14:13:41 -06:00
Mitchell Hashimoto d24082da1e config: validate that module variables can go to ints, convert [GH-624] 2014-12-15 22:10:16 -08:00
Kushal Pisavadia b40b7ce01a Do not read temporary editor files, fixes #548
This fixes a bug where Terraform would error with the following:

```
Error loading config: Error reading
/Users/rhenrichs/work/example/.#example.tf: open
/Users/rhenrichs/work/example/.#example.tf: no such file or directory
```

The solution implemented here ignores the common emacs and vim
temporary file formats.

Note: the potential danger with merging this is that Terraform could
quickly have requests to ignore other file formats.
2014-12-09 13:15:00 +00:00