terraform/internal
Martin Atkins 4e74a7a4f1 initwd: Error message for local paths escaping module packages
Our module installer has a somewhat-informal idea of a "module package",
which is some external thing we can go fetch in order to add one or more
modules to the current configuration. Our documentation doesn't talk much
about it because most users seem to have found the distinction between
external and local modules pretty intuitive without us throwing a lot of
funny terminology at them, but there are some situations where the
distinction between a module and a module package are material to the
end-user.

One such situation is when using an absolute rather than relative
filesystem path: we treat that as an external package in order to make the
resulting working directory theoretically "portable" (although users can
do various other things to defeat that), and so Terraform will copy the
directory into .terraform/modules in the same way as it would download and
extract a remote archive package or clone a git repository.

A consequence of this, though, is that any relative paths called from
inside a module loaded from an absolute path will fail if they try to
traverse upward into the parent directory, because at runtime we're
actually running from a copy of the directory that's been taking out of
its original context.

A similar sort of situation can occur in a truly remote module package if
the author accidentally writes a "../" source path that traverses up out
of the package root, and so this commit introduces a special error message
for both situations that tries to be a bit clearer about there being a
package boundary and use that to explain why installation failed.

We would ideally have made escaping local references like that illegal in
the first place, but sadly we did not and so when we rebuilt the module
installer for Terraform v0.12 we ended up keeping the previous behavior of
just trying it and letting it succeed if there happened to somehow be a
matching directory at the given path, in order to remain compatible with
situations that had worked by coincidence rather than intention. For that
same reason, I've implemented this as a replacement error message we will
return only if local module installation was going to fail anyway, and
thus it only modifies the error message for some existing error situations
rather than introducing new error situations.

This also includes some light updates to the documentation to say a little
more about how Terraform treats absolute paths, though aiming not to get
too much into the weeds about module packages since it's something that
most users can get away with never knowing.
2021-05-27 11:00:43 -07:00
..
addrs Move addrs/ to internal/addrs/ 2021-05-17 14:09:07 -07:00
backend Merge pull request #28820 from hashicorp/radditude/refresh-error-message 2021-05-27 07:21:37 -07:00
builtin return diagnostics from provisioners 2021-05-19 11:24:54 -04:00
command command/views: Remove unused drift summary message 2021-05-25 15:54:57 -04:00
communicator Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
configs Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
copy deprecate helper/copy 2020-10-08 08:42:16 -04:00
dag Move tfdiags/ to internal/tfdiags/ 2021-05-17 14:09:07 -07:00
depsfile Move addrs/ to internal/addrs/ 2021-05-17 14:09:07 -07:00
didyoumean didyoumean: move from "helper" to "internal" 2020-10-02 13:35:07 -07:00
e2e Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
earlyconfig Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
experiments Move experiments/ to internal/experiments/ 2021-05-17 14:09:07 -07:00
getproviders providers subcommand tests (#28744) 2021-05-19 12:56:16 -04:00
grpcwrap Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
helper Grammar nit: "setup" as a verb should be spelled "set up" 2021-01-26 20:39:11 +01:00
httpclient Move httpclient/ to internal/httpclient/ 2021-05-17 14:09:07 -07:00
initwd initwd: Error message for local paths escaping module packages 2021-05-27 11:00:43 -07:00
instances Move addrs/ to internal/addrs/ 2021-05-17 14:09:07 -07:00
lang Move lang/ to internal/lang/ 2021-05-17 14:09:07 -07:00
legacy Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
logging monitor plugin std outputs for unexpected data 2021-05-13 16:57:36 -04:00
modsdir Move addrs/ to internal/addrs/ 2021-05-17 14:09:07 -07:00
moduledeps Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
moduletest Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
plans Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
plugin Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
plugin6 Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provider-simple Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provider-simple-v6 Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provider-terraform/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
providercache Move addrs/ to internal/addrs/ 2021-05-17 14:09:07 -07:00
providers Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
provisioner-local-exec/main Move plugin/ and plugin6/ to internal/plugin{,6}/ 2021-05-17 14:09:07 -07:00
provisioners Move configs/ to internal/configs/ 2021-05-17 14:09:07 -07:00
registry Move httpclient/ to internal/httpclient/ 2021-05-17 14:09:07 -07:00
repl Move terraform/ to internal/terraform/ 2021-05-17 14:09:07 -07:00
replacefile replacefile: don't create the temporary file in TMPDIR 2020-10-20 16:29:59 -07:00
states Move states/ to internal/states/ 2021-05-17 14:09:07 -07:00
terminal terminal: Helpers for doing fmt-ish operations on the streams 2021-02-12 11:24:13 -08:00
terraform return error for invalid resource import 2021-05-25 17:13:49 -04:00
tfdiags Move tfdiags/ to internal/tfdiags/ 2021-05-17 14:09:07 -07:00
tfplugin5 update to match new default branch name (#27909) 2021-02-24 13:36:47 -05:00
tfplugin6 update to match new default branch name (#27909) 2021-02-24 13:36:47 -05:00
typeexpr internal/typeexpr: staticcheck 2020-12-02 13:59:19 -05:00