Yet another Terraform error-related post. For any other Terraform-related issues, browse by category here.
Prerequisites
- Terraform
The error
╷
│ Error: Invalid character
│
│ on providers.tf line 1:
│ 1: ��provider "azurerm" {
│
│ This character is not used within the language.
╵
Solution
There are three things that comes to my mind you could try.
UTF-8 encoding
Make sure that the encoding is set to UTF-8
. Just google how to set the encoding on your IDE tool of choice. This works 100% though if you receive the following errors as well:
╷
│ Error: Invalid character encoding
│
│ on providers.tf line 1:
│ 1: ��provider "azurerm" {
│
│ All input files must be UTF-8 encoded. Ensure that UTF-8 encoding is selected in your editor.
╵
╷
│ Error: Argument or block definition required
│
│ on providers.tf line 1:
│ 1: ��provider "azurerm" {
│
│ An argument or block definition is required here.
╵
Related posts:
- Invalid character encoding character error in Terraform
- Argument or block definition required error in Terraform
ASCII
Next thing you might want to do is check for non-ASCII characters. ASCII simply put is a subset of the UTF-8 encoding. There are a dozen of ASCII validation tools, utilities and scripts available online tho but, if you need a one-liner:
- Find non-ASCII characters in Linux
- Find non-ASCII characters in macOS
- Find non-ASCII characters in Windows
plan.tf
What also could happen is, running terraform plan -out=plan.tf
. Since the output is generated as a binary file, instead of saving the plan to a file ending with tf extension, e.g. plan.tf save it as tfplan, tfplan.out or even plan.tfplan. For instance, the command would be: terraform plan -out=tfplan
.
Related post: terraform plan the right way.
Note(s): If terraform plan -out=tfplan
throws Error: Too many command line arguments, try replacing the equal sign (=) with a space e.g. terraform plan -out tfplan
.
Conclusion
If you have any questions, thoughts or opinions, feel free to leave a comment below. On a side note, follow our official channel on Telegram.