VERY strange format being applied

Hi All - very much learning how to use Terraform so forgive the newbie. I doubt very much if my issue is related to terraform - could well be Visual Studio Code that I’m using to deploy so I’ll be pasting this in their forums too, but thought I’d drop it here to see if any of you have this happen…

I have VSC deployed on a MacBook. It’s connected to my Azure tenant OK and I can write and deploy resources just fine. Occasionally - about 1 in 10 times - when I run a PLAN then an APPLY - the apply spits out errors and the format of my code goes so indescribable that I’ve had to attach a photo. I am not sure how to describe it so finding it hard to search what may be the problem.

From within the editor, I simply CTRL-Z / COMMAND-Z to ‘undo’ what ever just happened to my code. The code then presents itself just fine. I always save my code after each change - so I can get ‘around’ it - but it’s driving me insane! Any ideas? Thank you.

It appears something is corrupting the configuration with non-utf8 characters. The binary output might just be invalid utf8, or it could be interpreted by the terminal as control characters and altering the state of the terminal itself.

The most common way this happens is by trying to interpret a binary file (like a zip file for example) as utf8 data in the configuration, but other than that it’s hard to guess what’s going on.

This particular case looks like what would happen if you ran a command like this:

terraform plan -out=anything.tf

That would cause Terraform to write the saved plan to a file named anything.tf, which subsequent commands would then assume is intended to be part of the configuration. Since a saved plan file is not a valid configuration file, that causes parsing to fail like this.

When saving a plan file you need to choose a name that doesn’t collide with a naming convention that Terraform uses for something else. A typical filename for a saved plan file is tfplan, created with terraform plan -out=tfplan.

(My reason for this guess is that the big string of binary garbage in the error message includes the strings tfplan, tfstate, tfstate-prev, .terraform.lock.hcl and various strings starting with tfconfig/, which matches the names of the plan elements included in a saved plan file.)