Commit Graph

82 Commits

Author SHA1 Message Date
Mitchell Hashimoto 6b458160b9
config: disallow names starting with ints
Fixes #10597

This disallows any names for variables, modules, etc. starting with
ints. This causes parse errors with the new HIL parser and actually
causes long term ambiguities if we allow this.

I've also updated the upgrade guide to note this as a backwards
compatibility and how people can fix this going forward.
2016-12-08 23:01:51 -05:00
Mitchell Hashimoto 9cc52d83de
config: test that null characters show up as errors in parse 2016-11-21 18:11:11 -08:00
Mitchell Hashimoto 25d19ef3d0 Merge pull request #10080 from hashicorp/f-tf-version
terraform: support version requirement in configuration
2016-11-14 11:53:30 -08:00
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 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 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
James Bardin e2b6ccad8a Failing test for GH-8820 2016-09-15 16:51:12 -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 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
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
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
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
Mitchell Hashimoto 99fbb91ba2 config: validate lifecycle keys [GH-4413] 2016-01-19 11:28:45 -08: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
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
Rob Zienert a1939e70f7 Adding ignore_changes lifecycle meta property 2015-10-14 16:34:27 -05: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
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
Mitchell Hashimoto aa1e66c16c config: parse lifecycle block with mapstructure for weak decode 2015-06-07 22:04:23 -07:00
Mitchell Hashimoto fdded8ca14 config: allow atlas block 2015-03-24 13:30:22 -07:00
Mitchell Hashimoto 91a3405e88 config: understand provisioner blocks in JSON [GH-807] 2015-01-16 10:14:48 -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
Armon Dadgar 1aaddafba0 terraform: Adding lifecycle config block 2014-09-29 15:20:02 -07:00
Armon Dadgar a14ea76c84 config: Support create_before_destroy config 2014-09-29 15:18:49 -07:00
Mitchell Hashimoto 6cbadf14df config: IsEmptyDir is true if dir doesn't exist 2014-09-26 16:28:18 -07:00
Mitchell Hashimoto 57c1a8dada config: add IsEmptyDir 2014-09-26 16:04:09 -07:00
Mitchell Hashimoto c0a30d3337 config: TestString 2014-09-15 15:43:12 -07:00
Mitchell Hashimoto b60da29d48 config: validate that variables reference valid modules 2014-09-15 11:45:41 -07:00
Mitchell Hashimoto 4fdb6d1b52 config: add test for empty file 2014-09-15 09:41:00 -07:00
Mitchell Hashimoto e96fe43814 config: dir on Config should be an absolute path 2014-09-14 19:55:38 -07:00
Mitchell Hashimoto f8836290da config: not directory that config was loaded from 2014-09-14 19:35:38 -07:00
Mitchell Hashimoto 8dc8eac4bf config: change module syntax 2014-09-14 14:43:54 -07:00
Mitchell Hashimoto 2a6990e2b9 config: `module` structures parse 2014-09-11 15:58:30 -07:00
Mitchell Hashimoto 038cca291e config: HCL loader 2014-08-11 09:58:53 -07:00
Mitchell Hashimoto 99a4439359 config: nicer error if dir isn't a dir 2014-07-28 08:34:43 -07:00
Mitchell Hashimoto fa175113fe config: case sensitive templates 2014-07-23 08:38:43 -07:00