File tree Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
set -uo pipefail;
4
4
5
+ function realpath-relative-to() {
6
+ # A basic implementation of GNU `realpath --relative-to=$1 $2`
7
+ # that can also be used on macOS.
8
+
9
+ # http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
10
+ readlink_f () {
11
+ local target_file=" ${1} " ;
12
+ local file_name;
13
+
14
+ while [ " ${target_file} " != " " ]; do
15
+ cd " $( dirname " $target_file " ) " || early_death " Failed to 'cd \$ (${target_file%/* } )'" ;
16
+ file_name=" ${target_file##*/ } " || early_death " Failed to '\" ${target_file##*/ } \" '" ;
17
+ target_file=" $( readlink " ${file_name} " ) " ;
18
+ done ;
19
+
20
+ echo " $( pwd -P) /${file_name} " ;
21
+ };
22
+
23
+ local relative_to=" $( readlink_f " ${1} " ) " ;
24
+ local path=" $( readlink_f " ${2} " ) " ;
25
+
26
+ echo " ${path# " ${relative_to} /" } " ;
27
+ return 0;
28
+ }
29
+ export -f realpath-relative-to;
30
+
5
31
function tfenv-exec() {
6
32
for _arg in ${@: 1} ; do
7
33
if [[ " ${_arg} " == -c hdir= * ]]; then
8
- log ' debug' " Found -chdir arg. Setting TFENV_DIR to: ${_arg# -chdir=} " ;
9
- export TFENV_DIR=" ${PWD} /${_arg# -chdir=} " ;
34
+ chdir=" ${_arg# -chdir=} " ;
35
+ log ' debug' " Found -chdir arg: ${chdir} " ;
36
+ export TFENV_DIR=" ${PWD} /$( realpath-relative-to " ${PWD} " " ${chdir} " ) " ;
37
+ log ' debug' " Setting TFENV_DIR to: ${TFENV_DIR} " ;
10
38
fi ;
11
39
done ;
12
40
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ echo 'min-required' > .terraform-version;
80
80
cleanup || log ' error' ' Cleanup failed?!' ;
81
81
82
82
83
- log ' info' ' ### Install min-required with TFENV_AUTO_INSTALL & -chdir' ;
83
+ log ' info' ' ### Install min-required with TFENV_AUTO_INSTALL & -chdir with rel path ' ;
84
84
85
85
minv=' 1.1.0' ;
86
86
@@ -97,6 +97,24 @@ echo 'min-required' > chdir-dir/.terraform-version
97
97
98
98
cleanup || log ' error' ' Cleanup failed?!' ;
99
99
100
+
101
+ log ' info' ' ### Install min-required with TFENV_AUTO_INSTALL & -chdir with abs path' ;
102
+
103
+ minv=' 1.2.3' ;
104
+
105
+ mkdir -p chdir-dir
106
+ echo " terraform {
107
+ required_version = \" >=${minv} \"
108
+ }" >> chdir-dir/min_required.tf;
109
+ echo ' min-required' > chdir-dir/.terraform-version
110
+
111
+ (
112
+ TFENV_AUTO_INSTALL=true terraform -chdir=" ${PWD} /chdir-dir" version;
113
+ check_active_version " ${minv} " chdir-dir;
114
+ ) || error_and_proceed ' Min required version from -chdir does not match' ;
115
+
116
+ cleanup || log ' error' ' Cleanup failed?!' ;
117
+
100
118
if [ " ${# errors[@]} " -gt 0 ]; then
101
119
log ' warn' ' ===== The following use_minrequired tests failed =====' ;
102
120
for error in " ${errors[@]} " ; do
You can’t perform that action at this time.
0 commit comments