This error seems to be saying that the result of
$(extract_tf_list_value $check_tfstate_path diskspace_status) is not producing valid Terraform value syntax. Unfortunately because that value is on the command line rather than in a file, the error message isn’t able to show in detail the location of the error.
One potential problem that I see here is that the
$( ... ) substitution is not in quotes, and so it’s subject to more shell parsing before it is passed on to Terraform. Without seeing the result of that command I’m not sure exactly what problem that would cause, but maybe you could try putting it in quotes to tell the shell that it should pass the result to Terraform literally, without further shell parsing:
-var diskspace_status="$(extract_tf_list_value $check_tfstate_path diskspace_status)"
If that doesn’t work, my next debugging step would be to temporary switch to using a
.tfvars file instead of a direct command line option, because that should allow Terraform’s error message to point to an exact location in the file where the syntax error appeared. For example:
# TEMP: Generate a .tfvars file for diskspace_status
# so that Terraform can use the file contents in the
# error message.
echo >temp.tfvars "diskspace_status = $(extract_tf_list_value $check_tfstate_path diskspace_status)"
terraform apply -var-file=temp.tfvars
If you then run this script in a context where terminal escape sequences are available, Terraform will show the portion of
temp.tfvars that produced the error and will mark with an underline the specific token that was incorrect. If you want to share that error message to continue the discussion, please be sure to mention in your command which token was underlined, because unfortunately the formatting characters get lost when copying the messages into the forum.