Normalization of configuration paths #19708
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes two adjustments to how we normalize configuration paths.
The first is general and applies both to the paths we show in diagnostic messages and the paths we return from
path.root
andpath.module
: previously we were normalizing these to relative paths in some commands but not others, which is both cosmetically weird and potentially problematic sincepath.module
might return something different depending on which Terraform command you are running. We will now normalize these to be relative paths in all cases.The second applies only to the
path.
references in configuration, making them always use forward slashes even on Windows systems. This addresses #14986 by relying on the fact that Windows supports both slash types as long as they are used consistently within a path. This means that moving forward all constructed paths in Terraform configurations should use forward slashes, like"${path.module}/foo/bar"
, which will produce correct results on all supported platforms.These two changes compliment each other by allowing paths to remain consistent across platforms. Making
path.module
andpath.root
appear relative avoids them ending up containing platform-specific prefixes likec:\
or/home
that would cause churn when applying the same configuration on different hosts.Since the slash normalization behavior applies only to Windows and we run our tests on Unix there's no direct unit testing of that behavior, but I added tests for the more general behavior of
path.module
andpath.root
nonetheless, to show that they still work as before on Unix systems.