Terraform validate command not working

Hi, terraform -v command not properly working on my pc.
+ provider registry.terraform.io/hashicorp/local v2.5.1 this part is missing.
I have tested it on VPS and it works exactly. But not works on my local.
I just followed this simple article. But after terraform validate command not respond.


Please help me.

Hi @aitechguy0105,

Referring to the article, which step is failing as you are referring to both terraform -v and terraform validate

Is it the

  • “Setting up Terraform - Verify Installation” step (no number)
    or is it
  • “Step 5 - Validate”

It would also be helpful if you could paste in exactly what you have on your terminal, including as much as you can. When you paste it into your reply be sure to surround it with 3x back-tick characters ``` on an empty line before and after the code/output that you paste in so it is formatted properly in your post.

D:\work\company\pivot-al\terraform-demo>terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/local...
- Installing hashicorp/local v2.5.1...
- Installed hashicorp/local v2.5.1 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

D:\work\company\pivot-al\terraform-demo>terraform validate

On my local:

C:\Users\Pioneer>terraform -v
Terraform v1.8.5
on windows_amd64


Terraform v1.8.5
on windows_amd64
+ provider registry.terraform.io/hashicorp/local v2.5.1

I will respond to this first and go back to the other reply:

The likely reason you’re getting different output here is:

  • On the VPS the terraform -v is likely being run in the working directory of your module. This means that terraform -v provides the version output for the terraform binary and the modules that have been downloaded by terraform init
  • I can see on your local you are running terraform -v in C:\Users\Pioneer> whereas your earlier reply shows that your module’s working directory is D:\work\company\pivot-al\terraform-demo>

To get the same output on your local, change into your module’s working directory and run terraform -v there.

Yes, It works in case terraform -v but not work terraform validate still no respond

The first thing I would do as part of troubleshooting is to remove the main.tf from your module working directory and retry the terraform validate in that directory.
This should return a

Success! The configuration is valid.

If it does not then it indicates something strange with your terraform install or its execution on your local pc. If it does return success then it indicates there may be something strange with your module files. In which case recreate your main.tf but I would recommend doing it directly in a text/code editor rather than following the command-line step as per the tutorial. Leave the main.tf empty and re-run terraform validate and check if you still get a success. Then add back in the code, etc.

Enabling some of the terraform logging is an option if you still see strange issues - but they are somewhat verbose and difficult to interpret.

See how you get on. Good luck!

Understood. with empty main.tf file terraform validate return success
but after edit main.tf

resource "local_file" "hello" {
    content  = "Hello, Terraform!"
    filename = "${path.module}/hello.txt"

no response

I am totally newbie on terraform :frowning:

I cant still understand. It works exactly on VPS and other PC. but only not works here.

D:\work\company\pivot-al\terraform-demo>set TF_LOG=INFO

D:\work\company\pivot-al\terraform-demo>terraform validate
2024-06-27T01:46:50.344+0800 [INFO]  Terraform version: 1.8.5
2024-06-27T01:46:50.344+0800 [INFO]  Go runtime version: go1.22.1
2024-06-27T01:46:50.344+0800 [INFO]  CLI args: []string{"terraform", "validate"}
2024-06-27T01:46:50.348+0800 [INFO]  CLI command args: []string{"validate"}
2024-06-27T01:46:50.360+0800 [INFO]  provider: configuring client automatic mTLS
2024-06-27T01:46:50.381+0800 [INFO]  provider.terraform-provider-local_v2.5.1_x5.exe: configuring server automatic mTLS: timestamp="2024-06-27T01:46:50.381+0800"

OK - so we’ve ruled out the terraform binary/install itself being the likely issue and directed ourselves to the content of the file.

The terraform validate command looks at the content of your module files and tries to determine if it is syntactically valid and consistent. Other than this it doesn’t really do anything.

A few more ‘troubleshooting’ steps I would try:

  1. ensure that the main.tf file is not open when running terraform validate
  2. Delete the .terraform folder and .terraform.lock.hcl file from your module’s working directory (Basically every file and folder except the mian.tf file and re-run terraform init
  3. recreate a new main.tf file and type (don’t copy and paste) the code in a line at a time. Saving the file and running terraform validate after typing each line. I would expect you to get an error each time you run terraform validate until you have saved the 4th line (the closing })

On the face of it this seems to be more of an ‘environmental’ or ‘system’ realted issue than anything fundamentally wrong with what you’re doing.

Don’t worry about it - we all started in the same place :upside_down_face:

Interesting. And here is an issue logged previously by someone with a very similar problem (Hanging during plan but with a very basic module using local file same as yours): Windows 10 Terraform plan hangs · Issue #30347 · hashicorp/terraform (github.com)

So it may be related to some protection software on the PC causing the issue. Possibly blocking a process from accessing something and causing it to hang. I have also done a quick search for similar and seen some posts of people having hanging terraform commands (init works ok, plan etc. don’t) where they have a network block occurring.

The local provider appears to want to create RPC elements, which may be getting blocked.

More verbose logging may provide some further insight. But if it is related to some protection software or network restrictions it may be that, unless you have control over their operation, you may not be able to resolve it. Furthermore, you might spend so long trying to find the issue that just using another machine may be a more efficient approach.

Yeah, I have test it on other’s pc. It works well, but not on my local.
Maybe sth wrong on my local. I cant find it.

Anyway, I will do this work on remote. Thanks @ExtelligenceIT