Skip to content

Commit e31a2da

Browse files
CCM-8994: Handle missing tfvars files
1 parent 3636f18 commit e31a2da

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

infrastructure/terraform/bin/terraform.sh

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -539,24 +539,26 @@ fi;
539539
[ -f "${dynamic_file_path}" ] && tf_var_file_paths+=("${dynamic_file_path}");
540540

541541
# Warn on duplication
542-
duplicate_variables="$(cat "${tf_var_file_paths[@]}" | sed -n -e 's/\(^[a-zA-Z0-9_\-]\+\)\s*=.*$/\1/p' | sort | uniq -d)";
543-
[ -n "${duplicate_variables}" ] \
544-
&& echo -e "
545-
###################################################################
546-
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING #
547-
###################################################################
548-
The following input variables appear to be duplicated:
549-
550-
${duplicate_variables}
551-
552-
This could lead to unexpected behaviour. Overriding of variables
553-
has previously been unpredictable and is not currently supported,
554-
but it may work.
555-
556-
Recent changes to terraform might give you useful overriding and
557-
map-merging functionality, please use with caution and report back
558-
on your successes & failures.
559-
###################################################################";
542+
if [ ${#tf_var_file_paths[@]} -gt 0 ]; then
543+
duplicate_variables="$(cat "${tf_var_file_paths[@]}" | sed -n -e 's/\(^[a-zA-Z0-9_\-]\+\)\s*=.*$/\1/p' | sort | uniq -d)";
544+
[ -n "${duplicate_variables}" ] \
545+
&& echo -e "
546+
###################################################################
547+
# WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING #
548+
###################################################################
549+
The following input variables appear to be duplicated:
550+
551+
${duplicate_variables}
552+
553+
This could lead to unexpected behaviour. Overriding of variables
554+
has previously been unpredictable and is not currently supported,
555+
but it may work.
556+
557+
Recent changes to terraform might give you useful overriding and
558+
map-merging functionality, please use with caution and report back
559+
on your successes & failures.
560+
###################################################################";
561+
fi
560562

561563
# Build up the tfvars arguments for terraform command line
562564
for file_path in "${tf_var_file_paths[@]}"; do

0 commit comments

Comments
 (0)