Open Morodar opened 4 years ago
For now, I stick with this hack but it will not work on Linux because of the leading slash.
I replace the :
in C:/
with ` nothing. I've also added a leading
/`.
So C:/absolute/root/path
results in /C/absolute/root/path
.
locals {
// TODO: Windows only Workaround - not recommended!
root_path = "/${replace(abspath(path.root), ":", "")}"
}
resource "docker_container" "reverse_proxy" {
image = docker_image.nginx_alpine.latest
name = "reverse_proxy"
volumes {
container_path = "/etc/nginx/conf.d"
host_path = "${local.root_path}/generated/nginx"
read_only = true
}
[...]
}
To take this even further (and to achieve Linux compatibility) I changed it to
locals {
root_path_tmp = "/${replace(abspath(path.root), ":", "")}"
root_path = "${replace(local.root_path_tmp, "////", "/")}"
}
We need to use ////
because the first and the last slash indicate the start and the end of a regex.
Terraform Version
v0.12.28 on Windows 10 Pro Build 18363
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
What should have happened?
Actual Behavior
Steps to Reproduce
terraform apply
Important Factoids
On windows:
abspath(path.root)
returnsC:/path/to/root
which is an absolute path on Windows and Terraform but not for the docker_container resource.Am I missing something or is this a bug?
I try to write terraform code which should run both on Windows and Linux.
But I fail to handle absolute paths on Windows correctly.
References