QT-DevOps / DevOpsIssues

This Repo will be used to demonstrate the Skills & Questions in DevOps
Apache License 2.0
27 stars 130 forks source link

Unable to create state file in backend using terraform apply command #974

Closed prrohith closed 3 years ago

prrohith commented 3 years ago

Hi,

I wrote the below code for backend and created the required s3 bucket and dynamodb table for the terraform statefile. But I get the following error.

terraform { backend "s3" { bucket= "rohithterraformstate" key="global/ntier/terraform.tfstate" region="us-west-2"

    dynamodb_table="terraformlocktable"

}

}

PS E:\Devops Job\Terraform_Packer\ntier_code> terraform apply . Acquiring state lock. This may take a few moments...

Error: Error locking state: Error acquiring the state lock: 2 errors occurred:

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.

santhoshd402 commented 3 years ago

make sure that your request mapping template structure matches the Amazon DynamoDB key structure...

and also run terraform init before apply.

Meanwhile i will check and update you ... Reach me @7893532934

check LockID in dynamoDB table

prrohith commented 3 years ago

Hi,

I checked the template. It is correct as explained in the class. Also I ran the init command before I ran the apply command.

Kind regards, Rohith

On Thu., Oct. 29, 2020, 3:38 a.m. santhoshd402, notifications@github.com wrote:

make sure that your request mapping template structure matches the Amazon DynamoDB key structure...

and also run terraform init before apply.

Meanwhile i will check and update you

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/QT-DevOps/DevOpsIssues/issues/974#issuecomment-718428450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMGGX6HNPDV7VJTE7HXL2B3SNELWLANCNFSM4TDCSU4Q .

santhoshd402 commented 3 years ago

Hi rohith,

The script what you shared is perfectly working. i tried that with my credentials its absolutely working fine. Crosscheck your work . if you got same issue . plz cal me @7893532934 we will discuss more about this.

prrohith commented 3 years ago

Earlier I created LockID as "lockid", which cause the issue. After checking with Santhosh, I changed the name to "LockID" again. It fixed the issue.