Assistance with upgrading from 0.11.x to 0.12.x

I’m getting a lot of errors like this

Error: Missing item separator
on <value for var.diskspace_status> line 1:
(source code not available)
Expected a comma to mark the beginning of the next item.

When trying to run terraform apply/install my project.
I pass it into terraform like this
-var diskspace_status=$(extract_tf_list_value $check_tfstate_path diskspace_status)

I pass this variable

variable "diskspace_status" {
description = "Diskspace pre requisite"
type        = list(string)
default     = []
}

Into the checker module like this

module "registry_validate_prerequisites" {
source = "./../../common/checkers/prerequisites/validate"
diskspace_status  = var.diskspace_status

And from there this is the contents of the main.tf for this resource

resource "null_resource" "prerequisite_diskspace" {

  count = "${var.enable == "true" && contains(var.diskspace_status, "not_pass") ? 1 : 0}"
}

Hi @nicks1993,

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.

Thank you so much man, this was the most helpful reply I’ve ever received when I asked for help on any technical subject.

I did some deep investigating using the advice you provided and found the issues

before the upgrade we’d get this

cat temp.tfvars
diskspace_status = ["pass"]

now we get this

cat temp.tfvars
diskspace_status = ["[","[",""pass"","]","]"]

So I think the rest is just on us parsing the new statefile.

Thanks a lot.

If you have tips on extracting variables with bash/terraform let me know!