'Invalid character encoding' error in Terraform

Jun 19, 2022 · 1 min read · Post a comment

Another ez solution as part of the Terraform issue series. This time being the following one:

│ Error: Invalid character encoding
│   on providers.tf line 1:
│    1: ��provider "aws" {
│ All input files must be UTF-8 encoded. Ensure that UTF-8 encoding is selected in your editor.


  • Terraform


Since you are having non-UTF-8 encoded character(s), it’s kind of a straight to the point solution. If you are working in VS Code, there is an Encoding option located in the bottom bar – the Status Bar.

Step 1. Copy the code from whatever encoding it is right now and make sure to paste it in a new UTF-8 encoded tab.

Step 2. Clear any code from the previous non-UTF-8 encoding tab.

Step 3. Click on the bottom Status Bar encoding option. vscode status bar

Note(s): As you could see the current encoding is UTF-16 LE.

Step 4. Click Reopen with Encoding.
vscode reopen encoding

Step 5. Select UTF-8 from the list.
vscode encoding list

Step 6. Remove any weird leftover character, copy and paste the code back from the UTF-8 encoding tab and save the file.

If you are working with any other IDE besides VSCode, just google on how to update the encoding.

On a side note, check for any non-ASCII chars.


You might also want to check out Invalid character error in Terraform. If you have any related unresolved issues, feel free to share them in the comment section below. On a side note, follow our official channel on Telegram.