Common Terraform errors and possible solution

Dipesh Majumdar
2 min readFeb 5, 2021

--

  1. When you get this error…
Error: error configuring S3 Backend: no valid credential sources for S3 Backend found.

That possibly means you are not correctly logged into your AWS account

2. When you do a terraform plan terraform throws the below error —

Acquiring state lock. This may take a few moments...Error: Error acquiring the state lock│ Error message: 2 errors occurred:│  * ResourceNotFoundException: Requested resource not found│  * ResourceNotFoundException: Requested resource not found│ Terraform acquires a state lock to protect the state from being written│ by multiple users at the same time. Please resolve the issue above and try│ again. For most commands, you can disable locking with the "-lock=false"│ flag, but this is not recommended.

How to fix this error?

You can enable TF_LOG to DEBUG to get more messages.

export TF_LOG=DEBUG

One of the messages i found is dynamo db table insertion is an issue.

2021-08-04T12:54:22.712+0200 [DEBUG] [aws-sdk-go] DEBUG: Response dynamodb/PutItem Details:---[ RESPONSE ]--------------------------------------HTTP/1.1 400 Bad RequestConnection: closeContent-Length: 112Content-Type: application/x-amz-json-1.0Date: Wed, 04 Aug 2021 10:54:22 GMTServer: Server

so i created the dynamo db table with the correct name and with partition_key: LockID and the error was solved.

3. Now while working with modules this may pop up —

Error: Variables not allowed│   on main.tf line 17, in module "eks_environment":│   17:   source                    = var.source

And this took me quite some time to find out,

you need to keep 2 copies of variables.tf and blahblah.tfvars — one under the root directory which has main.tf and where the referencing to path of module takes place, and the second at module directory. Which is really annoying.

--

--