Commit Graph

32 Commits

Author SHA1 Message Date
Martin Atkins eaac9fbca3 provider/template: template_dir explicitly create dest dir
Previously we were letting it get implicitly created as part of making
the structure for copying in each file, but that isn't sufficient if the
source directory is empty.

By explicitly creating the directory first we ensure that it will complete
successfully even in the case of an empty directory.
2017-04-25 10:48:26 -07:00
Martin Atkins eda2550074 provider/template: template_dir: don't crash if source dir nonexistent
When an error is passed, the FileInfo can be nil, which was previously
causing a crash on trying to evaluate f.IsDir(). By checking for an error
first we avoid this crash.
2017-04-25 10:48:26 -07:00
Quentin Machu f721608e4e provider/template: Add a 'dir' resource to template entire directories
When TerraForm is used to configure and deploy infrastructure
applications that require dozens templated files, such as Kubernetes, it
becomes extremely burdensome to template them individually: each of them
requires a data source block as well as an upload/export (file
provisioner, AWS S3, ...).

Instead, this commit introduces a mean to template an entire folder of
files (recursively), that can then be treated as a whole by any provider
or provisioner that support directory inputs (such as the
file provisioner, the archive provider, ...).

This does not intend to make TerraForm a full-fledged templating system
as the templating grammar and capabilities are left unchanged. This only
aims at improving the user-experience of the existing templating
provider by significantly reducing the overhead when several files are
to be generated - without forcing the users to rely on external tools
when these templates stay simple and that their generation in TerraForm
is justified.
2017-04-25 10:48:26 -07:00
Devin Lundberg 081121d29b Fix invalid MIME formatting in multipart cloudinit userdata (#13752)
* Fix invalid MIME formatting in multipart cloudinit userdata 

Per https://tools.ietf.org/html/rfc822#appendix-B.2, MIME headers and Body need to be separated by two new lines (or CRLFs in this case). 

The email parser in python can handle this which is what cloud-init uses but this bug causes problems if you try to parse the multipart message by languages other than python.

* Fix test cases
2017-04-21 08:30:09 +02:00
Jake Champlin 82a7d4b4a5
cleanup imports 2017-04-12 10:49:52 -04:00
Jake Champlin 53fe7c2293
provider/template: Fix panic in cloudinit config
Fixes an uncaught panic during an interface cast in the `template_cloudinit_config` data source.

Fixes: #13572

```
$ make test TEST=./builtin/providers/template TESTARGS="-v -run=TestRender_handlePanic"
==> Checking that code complies with gofmt requirements...
==> Checking AWS provider for unchecked errors...
==> NOTE: at this time we only look for uncheck errors in the AWS package
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/04/12 10:46:33 Generated command/internal_plugin_list.go
go test -i ./builtin/providers/template || exit 1
echo ./builtin/providers/template | \
                xargs -t -n4 go test -v -run=TestRender_handlePanic -timeout=60s -parallel=4
go test -v -run=TestRender_handlePanic -timeout=60s -parallel=4 ./builtin/providers/template
=== RUN   TestRender_handlePanic
--- PASS: TestRender_handlePanic (0.00s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/template       0.028s
```
2017-04-12 10:48:53 -04:00
Mitchell Hashimoto 485455b2f2
providers/template: disallow file paths in `template`
Fixes #8660

This disallows file paths in `template`. This already had a deprecation
warning so we're just removing that.
2016-11-22 10:23:58 -08:00
Simon Thulbourn 1ca1f86713 Remove sthulb/mine/multipart
This dep was meant as a stopgap for a patch in the stdlib of Go which I
wrote.

The patch was released in Go 1.7. We can now remove my fork and go back
to the stdlib
2016-11-04 11:23:21 +00:00
Paul Hinze c5647dc046 Revert "providers/template: template_file supports floating point math" 2016-09-02 15:20:03 -05:00
Mitchell Hashimoto c6ad7f80e8
providers/template: template_file supports floating point math 2016-08-31 17:25:11 -07:00
James Bardin bb84dc75b7 Fix improper wait group usage in test 2016-08-04 11:20:11 -04:00
Clint a9aaf44a87 fix make issues (supersedes #7868) (#7876)
* Fixing the make error or invalid data type for errorf and printf

* fix make errors
2016-07-29 21:05:57 +01:00
Paul Hinze b7e854fa8b
provider/template: validate vars are primitives
Closes #7160 by returning a proper error.
2016-07-11 16:01:05 -05:00
Martin Atkins 861ac536dd provider/template: convert resources to data sources
The template resources don't actually need to retain any state, so they
are good candidates to be data sources.

This includes a few tweaks to the acceptance tests -- now configured to
run as unit tests -- since it seems that they have been slightly broken
for a while now. In particular, the "update" cases are no longer tested
because updating is not a meaningful operation for a data source.
2016-07-08 17:11:17 +01:00
James Nugent 3ea3c657b5 core: Use OutputState in JSON instead of map
This commit forward ports the changes made for 0.6.17, in order to store
the type and sensitive flag against outputs.

It also refactors the logic of the import for V0 to V1 state, and
fixes up the call sites of the new format for outputs in V2 state.

Finally we fix up tests which did not previously set a state version
where one is required.
2016-05-18 13:25:20 -05: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
Paul Hinze 0036db8f82 provider/template: warn when template specified as path
Turns out the BC code allowed users to move from `filename` to
`template` to squash the warning without having to switch from template
paths to template contents.

Here we warn when `template` is specified as a path so we can remove the
functionality in the future and remove this source of confusion.

refs #3732
2016-03-10 12:34:56 -06:00
Mitchell Hashimoto aaf1302ce8 providers/template: don't use config/lang 2016-02-03 13:24:04 -05:00
Simon Thulbourn 548136c050 Remove mime type validation
Remove the mime type validation since the part handler type allows for
custom types.

http://cloudinit.readthedocs.org/en/latest/topics/format.html#part-handler

The docs specify that if a part handler type is specified, one could use
custom mime types

Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
2016-01-28 11:36:18 +00:00
James Nugent b0f9eb5c13 provider/template: Allow update in `template_cloudinit_config` 2016-01-20 09:58:20 -05: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
Simon Thulbourn 3701342716 Alters template provider to use a fork of multipart.
Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
2015-12-21 13:32:26 -05:00
Simon Thulbourn 33d2afc26d Add headers to output
The original implmentation was missing headers to denote mime version &
content transfer encoding, this caused issues with EC2.

Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
2015-12-21 13:32:26 -05:00
James Nugent ba9c7323a9 Remove unnecessary commented imports 2015-12-21 13:32:26 -05:00
James Nugent abffa67a49 Rename resource.go -> resource_template_file.go
This is necessitated by new resources being added to the template
provider.
2015-12-21 13:32:26 -05:00
James Nugent a926fa6fdd Adds template_cloudinit_config resource to template
This adds a new resource to template to generate multipart cloudinit
configurations to be used with other providers/resources.

The resource has the ability gzip and base64 encode the parts.
2015-12-21 13:32:26 -05: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
Paul Hinze 385b17d679 provider/template: don't error when rendering fails in Exists
The Exists function can run in a context where the contents of the
template have changed, but it uses the old set of variables from the
state. This means that when the set of variables changes, rendering will
fail in Exists. This was returning an error, but really it just needs to
be treated as a scenario where the template needs re-rendering.

fixes #2344 and possibly a few other template issues floating around
2015-06-17 15:33:07 -05:00
Paul Hinze 06eb388c3f provider/template: store relative path in state
This makes template_file usage in modules portable.
2015-05-21 15:03:03 -05:00
Paul Hinze a96a3372c6 provider/template: don't diff when there's no diff
This reworks the template lifecycle a bit such that we get nicer diff
behavior.

First, we tick ForceNew on for both filename and vars, so that the diff
indicates that the template will be "replaced" on change. This is mostly
cosmetic, but it also tracks conceptually with the fact that the
identifier we use is a hash of the contents, so any change essentially
makes a "new resource".

Second, we change the Exists implementation to only return `false` when
there has been a change in the rendered template. This lets descendent
resources see the computed value changing so that they'll properly
trigger in the plan.

Fixes #1898
Refs #1866 (but does not fix, there's another deeper issue there)
2015-05-11 10:38:19 -05:00
Josh Bleecher Snyder 76bcac3031 providers/template: add tests, address review comments
Do directory expansion on filenames.

Add basic acceptance tests. Code coverage is 72.5%.
Uncovered code is uninteresting and/or impossible error cases.

Note that this required adding a knob to
helper/resource.TestStep to allow transient
resources.
2015-05-04 10:26:17 -07:00
Josh Bleecher Snyder 745d83a995 providers: add template provider
Fixes #215.
2015-05-01 16:59:49 -07:00