I have gce resource being created and bootstrapped with a startup script but seeing some weird issues with variables.
Created TF resources as per:
data "template_file" "init" {
template = "${file("../../../Boomi/linux/test.sh")}"
vars = {
platform = var.platform
}
}
resource "google_compute_instance" "atom_instance" {
machine_type = var.machine_type
metadata_startup_script = "${data.template_file.init.rendered}"
...
test.sh script
#!/bin/bash
#set -e
echo "platform:${platform}"
if [ -z $platform ] ; then
echo "parameter needed!"
if [ -n $platform ] ; then
echo "parameter provided!"
fi
echo "completed"
In the Serial Console output I got the following after the bash script was run:
Jan 15 20:44:25 debian google_metadata_script_runner[471]: startup-script: platform:gcp
Jan 15 20:44:25 debian google_metadata_script_runner[471]: startup-script: parameter needed!
Jan 15 20:44:25 debian google_metadata_script_runner[471]: startup-script: parameter provided!
Jan 15 20:44:25 debian google_metadata_script_runner[471]: startup-script: completed
Jan 15 20:44:25 debian google_metadata_script_runner[471]: startup-script exit status 0
This makes no sense as $platform variable is set so wouldn’t expect “parameter needed!” in the output.
It seems like the null check is not working?
if [ -z $platform ] ; then
Any ideas?