Commit Graph

608 Commits

Author SHA1 Message Date
Pradeep Bhadani 2c39887706 Add fail test - one parameter, non-numeric parameter 2017-05-18 14:30:10 +00:00
Pradeep Bhadani 47b1aaea3a Add pow function 2017-05-17 21:46:33 +00:00
Patrick Decat 392166faea Typo: now => no (#14493)
> This validation checks that there are now splat variables referencing ourself. This currently is not allowed.

=> 

> This validation checks that there are no splat variables referencing ourself. This currently is not allowed.
2017-05-15 15:39:55 +03:00
Joshua Spence 38d4d2f9d4 Add a logarithm function
Fixes #9498. Adds a `log` function for calculating logarithms.
2017-05-05 17:06:53 +10:00
Martins Sipenko c7fb9808ef config: sha512 hash functions (#14100) 2017-05-02 16:35:23 -07:00
Martin Atkins 81b0c4b28d config: generate errors for unnamed blocks of various sources
We've been incorrectly validating (or not validating at all) the
requirement that certain blocks be followed by a name string, to prohibit
e.g. this:

    variable {}

and:

    variable = ""

Before this change we were catching this for most constructs only if
there were no _valid_ blocks of the same name in the same file. For
modules in particular, we were not catching this at all.

Now we detect this for all kinds of block (resources had a pre-existing
check, so aren't touched here) and produce a different error message
depending on which of the above incorrect forms are used.

This fixes #13575.
2017-05-02 16:29:57 -07:00
Martin Atkins b1763e262a Restore stringer-generated files back to new version
stringer has changed the boilerplate it generates in a recent version.
We'd previously updated to the new format but accientally rolled back
to the old while merging a long-running feature branch.

This restores us back to the new format again.
2017-04-21 14:49:18 -07:00
Jake Champlin 70bc1e1dcc Merge pull request #12537 from Pryz/coalescelist
Add coalescelist interpolation function
2017-04-21 15:23:21 -04:00
Pavel Khusainov f9fb6010ee config: "matchkeys" interpolation function
This new function allows using a search within one list to filter another list. For example, it can be used to find the ids of EC2 instances in a particular AZ.

The interface is made slightly awkward by the constraints of HIL's featureset.

#13847
2017-04-21 10:04:49 -07:00
Jasmin Gacic 61499cfcf0 Provider Oneandone (#13633)
* Terraform Provider 1&1

* Addressing pull request remarks

* Fixed imports

* Fixing remarks

* Test optimiziation
2017-04-21 17:19:10 +03:00
Justin Campbell c1c3127d8e config: Generate error copy from valid types map
Renders as:

```
Variable 'invalid_type' type must be one of [string, map, list] - 'not_a_type' is not a valid type
```
2017-04-20 13:30:22 -07:00
Justin Campbell cf775ded0e config: Add 'list' to variable type error message 2017-04-20 13:30:22 -07:00
tmshn 86d7c47c0a Change cidrhost() to get IP from end of the range when negative number given
Ref: https://github.com/apparentlymart/go-cidr/pull/2
2017-04-19 09:41:41 -07:00
Joern Barthel 9622b49c45 Support for Windows newlines. 2017-04-07 10:41:55 +02:00
Joern Barthel 059a1b2c0f Added chomp interpolation function. 2017-04-06 13:17:25 +02:00
James Bardin ff2d753062 add Rehash to terraform.BackendState
This method mirrors that of config.Backend, so we can compare the
configration of a backend read from a config vs that of a backend read
from a state. This will prevent init from reinitializing when using
`-backend-config` options that match the existing state.
2017-03-29 15:53:42 -04:00
Martin Atkins 76dca009e0 Allow escaped interpolation-like sequences in variable defaults
The variable validator assumes that any AST node it gets from an
interpolation walk is an indicator of an interpolation. Unfortunately,
back in f223be15 we changed the interpolation walker to emit a LiteralNode
as a way to signal that the result is a literal but not identical to the
input due to escapes.

The existence of this issue suggests a bit of a design smell in that the
interpolation walker interface at first glance appears to skip over all
literals, but it actually emits them in this one situation. In the long
run we should perhaps think about whether the abstraction is right here,
but this is a shallow, tactical change that fixes #13001.
2017-03-29 09:25:57 -07:00
Martin Atkins 21cd5595e2 Update stringer-generated files to new boilerplate
golang/tools commit 23ca8a263 changed the format of the leading comment
to comply with some new standards discussed here:
https://golang.org/issue/13560

This is the result of running generate with the latest version of
stringer. Everyone working on Terraform will need to update stringer
after this is merged, to avoid reverting this:
    go get -u golang.org/x/tools/cmd/stringer
2017-03-29 08:07:06 -07:00
Joshua Spence af2c84de5a Add `basename` and `dirname` functions
Adds `basename` and `dirname` interpolation. I want to add a `stack` tag to our infrastructure, the value of which is set to `${basename(path.cwd)}`. We currently use `${replace(path.cwd, "/^.+\\//", "")}` instead, but this is extremeley unreadable. The existance of a `basename` function would be very useful for this use case.

I don't have an immediate use case for a `dirname` function, but it seemed reasonable to add it as well.
2017-03-28 09:29:26 -07:00
Joshua Spence e71d6d92ad Add a substring interpolation function (#12870)
Adds a new `substr` interpolation function which can be used to truncate a string.
2017-03-22 11:30:39 -04:00
James Bardin 579e15c97c Merge pull request #12942 from hashicorp/jbardin/GH-12905
merge config.Terraform fields in config.Append
2017-03-22 09:11:42 -04:00
James Bardin bcbcc65f7d add terraform config merge logic to config.Merge 2017-03-22 09:01:54 -04:00
James Bardin 8bcb9e19ca restructure JSON terraform config block AST
When configuration is read out of JSON, HCL assumes that empty levels of
objects can be flattened, but this removes too much to decode into a
config.Terraform struct.

Reconstruct the appropriate AST to decode the config struct.
2017-03-21 18:15:58 -04:00
James Bardin b38e620b2f merge config.Terraform fields in config.Append
Ensure that fields set in an earlier Terraform config block aren't
removed by Append when encountering another Terraform block. When
multiple blocks contain the same field, the later one still wins.
2017-03-21 15:43:55 -04:00
Benjamin Boudreau 073fa873ac Fix receive typo (#12881) 2017-03-20 13:15:27 -04:00
Mitchell Hashimoto 68ee4e0480
config/module: don't panic when referencing undefined module
Fixes #12788

We would panic when referencing an output from an undefined module. The
panic above this is correct but in this case Load will not catch
interpolated variables that _reference_ an unloaded/undefined module.
Test included.
2017-03-16 20:14:20 -07:00
Mitchell Hashimoto f7da5d323c
config: test that JSON loading terraform backend info works 2017-03-16 14:51:26 -07:00
James Bardin 2e3579b058 Merge pull request #12383 from hashicorp/jbardin/multi-var-errs
report all errors from module validation
2017-03-14 15:36:32 -04:00
Mitchell Hashimoto e2ca2c5911
config: allow TerraformVars in count 2017-03-13 16:38:54 -07:00
Mitchell Hashimoto 786334b643
config: parse TerraformVariables 2017-03-13 16:09:06 -07:00
Pryz 733f1ca1e7 Add coalescelist interpolation function 2017-03-08 12:38:08 -08:00
James Bardin a111635908 Fix panic in interpolate_walk
Verify that we have enough containers in the stack to look for a map in
replaceCurrent.
2017-03-07 15:35:40 -05:00
James Bardin 3c41a7ca1e Add test for Validate crash
Crash during Validate walk with nested variable default.
2017-03-07 15:01:29 -05:00
James Bardin 2a949093ed report all errors from module validation
It can be tedious fixing a new module with many errors when Terraform
only outputs the first random error it encounters.

Accumulate all errors from validation, and format them for the user.
2017-03-02 15:16:05 -05:00
Mitchell Hashimoto b502643863 Merge pull request #12067 from hashicorp/b-backend-interp
config: validate backend configuration can't contain interpolations
2017-02-26 21:44:45 -08:00
John Murphy 628d46ac53 Fixed broken build for netbsd 2017-02-22 00:30:18 +08:00
Mitchell Hashimoto 6b4c007894
config: validate backend configuration can't contain interpolations 2017-02-17 16:27:01 -08:00
Kit Ewbank 549cff56d0 Add 'slice' interpolation function. (#9729) 2017-02-13 21:20:02 +00:00
Mitchell Hashimoto b6bfc4798d
config: Resource.Count should type check
Fixes #11800

Type check the value of count so we don't panic on the conversion.

I wondered "why didn't we do this before?" There is no excuse for NOT
doing it at all but the reasoning was beacuse prior to the list/map work
in 0.7, the value couldn't be anything other than a string since any
primitive can turn into a string.

Regardless, we should've always done this.
2017-02-10 10:41:41 -08:00
Mitchell Hashimoto cf46e1c3e0
terraform: don't validate computed values in validate
This disables the computed value check for `count` during the validation
pass. This enables partial support for #3888 or #1497: as long as the
value is non-computed during the plan, complex values will work in
counts.

**Notably, this allows data source values to be present in counts!**

The "count" value can be disabled during validation safely because we
can treat it as if any field that uses `count.index` is computed for
validation. We then validate a single instance (as if `count = 1`) just
to make sure all required fields are set.
2017-01-27 21:15:43 -08:00
Mitchell Hashimoto 7b342100d0
config: add "backend" loading to the Terraform section 2017-01-26 14:33:49 -08:00
Mitchell Hashimoto 928fce71f7
config: parse "when" and "on_failure" on provisioners 2017-01-19 18:10:21 -08:00
Jake Champlin 0b73b92830
core: Add pathexpand interpolation function
Adds the `pathexpand` interpolation function to allow users to expand `~` to the home directory in filepath strings.
2017-01-18 16:11:19 -05:00
Mitchell Hashimoto 095b7e7831
config/module: disallow root modules named "root"
Fixes #11038

This is a **short term fix**.

Terraform core doesn't currently handle root modules named "root" well
because the prefix `[]string{"root"}` has special meaning and Terraform
core [currently] can't disambiguate between the root module and a module
named "root" in the root module.

This PR introduces a short term fix by simply disallowing root modules
named "root". This shouldn't break any BC because since 0.8.0 this
didn't work at all in many broken ways (including crashes).

Longer term, this should be fixed by removing the special prefix at all
and having empty paths be root. I started down this path but the core
changes necessary are far too scary for a patch release. We can aim for
0.9.
2017-01-08 15:39:57 -08:00
Mitchell Hashimoto 0c30caec7d
config: smarter provider alias usage validation
Fixes #4789

This improves the validation that valid provider aliases are used.

Previously, we required that provider aliases be defined in every module
they're used. This isn't correct because the alias may be used in a
parent module and inherited.

This removes that validation and creates the validation that a provider
alias must be defined in the used module or _any parent_. This allows
inheritance to work properly.

We've always had this type of validation for aliases because we believe
its a good UX tradeoff: typo-ing an alias is really painful, so we
require declaration of alias usage. It may add a small burden to
declare, but since relatively few aliases are used, it improves the
scenario where a user fat-fingers an alias name.
2016-12-16 16:47:32 -08:00
Mitchell Hashimoto c2c5668a8d
config: Append supports `terraform` 2016-12-13 21:53:02 -08:00
Mitchell Hashimoto 3878b8b093
config: Merge respects Terraform blocks, provider aliases, and more
Fixes #10715

`config.Merge` was not updated to support a number of new features. This
updates the codepath to merge various fields, including the `terraform`
block which was the issue in #10715.

The `Merge` API is called when an `_override` file is present to _merge_
configurations. Normally configurations are _appended_. Only an override
file triggers a _merge_.

I started working on a generic library to do this automatically awhile
back but never finished it. This might motivate me to do so. In the
interest of getting a fix out though, we'll continue the manual
approach.
2016-12-13 21:48:59 -08:00
Mitchell Hashimoto 8a102799c2 Merge pull request #10658 from hashicorp/b-var-keys
config: validate invalid variable keys
2016-12-12 10:53:07 -08:00
Mitchell Hashimoto 3ba9720b3e
config: validate invalid variable keys
Fixes #9416

A simple change to verify that only valid keys for `variable` blocks are
used.
2016-12-10 19:27:01 -05:00
Mitchell Hashimoto 5d684b399c
config: error when loading multiple lifecycle blocks
Fixes #8776

This introduces an error when multiple `lifecycle` blocks exist on a
resource in the configuration.
2016-12-10 18:52:13 -05:00