Created
June 13, 2019 15:07
-
-
Save alex-harvey-z3q/123d5bfdce3eaf4e0dccc760669bb0b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Code for my blog post at: | |
# https://alexharv074.github.io/2019/06/09/adventures-in-the-terraform-dsl-part-v-conditional-logic.html | |
t011=/usr/local/bin/terraform | |
t012=/usr/local/bin/terraform012 | |
data() { | |
cat <<EOF | |
"1" | |
"0" | |
true | |
false | |
"true" | |
"false" | |
1 | |
0 | |
"2" | |
"hello" | |
"" | |
true == true | |
false == false | |
true == "true" | |
false == "false" | |
true != "true" | |
false != "false" | |
"1" == true | |
"0" == false | |
"1" == "true" | |
"0" == false | |
"x" == "x" | |
"x" == "y" | |
!true | |
!false | |
!!true | |
!!false | |
EOF | |
} | |
filter() { | |
awk ' | |
# Written this way to deal with unprintable | |
# characters in the input. | |
# | |
/truthiness/ { ++f } | |
/truthiness.*truthy/ { print "truthy" } | |
/truthiness.*falsey/ { print "falsey" ; next } | |
/truthiness.*true/ { print "true" } | |
/truthiness.*false/ { print "false" } | |
/invalid syntax in/ { ++f; print "-" } | |
/must be type bool/ { ++f; print "-" } | |
/must be of type bool/ { ++f; print "-" } # Message changed in 0.12. | |
END { | |
if (!f) print "-" | |
} | |
' | |
} | |
echo "|Value|Terraform 0.11|Terraform 0.12| | |
|=====|=============|==============|" | |
data | while read i ; do | |
t='truthy' ; f='falsey' | |
if [[ $i =~ = ]] || [[ $i =~ ! ]] ; then | |
t='true' ; f='false' | |
fi | |
cat > "test.tf" <<EOF | |
output "truthiness" { | |
value = "\${$i ? "$t" : "$f"}" | |
} | |
EOF | |
row="|$i" | |
for j in 11 12 ; do | |
rm -f terraform.tfstate* | |
ter="\$t0$j" | |
val=$(eval "echo \$($ter apply 2>&1 | filter)") | |
row="$row|$val" | |
done | |
row="$row|" | |
echo "$row" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment