{"id":18789049,"url":"https://github.com/artemmkin/terraform-statelock","last_synced_at":"2025-07-27T04:08:20.791Z","repository":{"id":133973584,"uuid":"123103043","full_name":"Artemmkin/terraform-statelock","owner":"Artemmkin","description":"A quick demo of using Terraform state file locking feature in AWS","archived":false,"fork":false,"pushed_at":"2018-02-27T22:57:36.000Z","size":5,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T14:18:29.520Z","etag":null,"topics":["aws","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Artemmkin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-27T09:10:51.000Z","updated_at":"2023-04-29T11:02:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"318ae24d-1ca9-4fb1-80e3-cfd53d2fb676","html_url":"https://github.com/Artemmkin/terraform-statelock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Artemmkin/terraform-statelock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-statelock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-statelock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-statelock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-statelock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Artemmkin","download_url":"https://codeload.github.com/Artemmkin/terraform-statelock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Artemmkin%2Fterraform-statelock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267298756,"owners_count":24065889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","terraform"],"created_at":"2024-11-07T21:06:31.502Z","updated_at":"2025-07-27T04:08:20.786Z","avatar_url":"https://github.com/Artemmkin.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Terraform state file locking demo\n\n1. Create an S3 bucket to store state file and DynamoDB table to enable state file locking.\n\n```bash\n$ cd ./terraform-required\n$ terraform init\n$ terraform apply\n```\n2. Grab the name of the bucket created from terraform output. It will be the last part of ARN.\n\nFor example, if you got an output like this:\n```\nbucket_name = arn:aws:s3:::terraform-state-960\n```\n\nThe name of the bucket is `terraform-state-960`.\n\n3. Move back to the root directory. Change the name of the bucket in `remote-backend.tf` file:\n\n```\nterraform {\n  backend \"s3\" {\n    bucket = \"terraform-state-960\" # \u003c= change this to the name of your bucket\n    key    = \"dev\"\n    region = \"us-east-1\"\n    dynamodb_table = \"terraform-statelock\"\n  }\n}\n```\n\n4. Launch instance to check how state locking works. The instance resource uses a `local-exec` provisioner to delay the creation of a resource:\n```\nprovisioner \"local-exec\" {\n  command = \"sleep 90\"\n}\n```\n\nTo launch instance, run:\n\n```bash\n$ terraform init\n$ terraform apply\n```\n\n5. While instance is creating, open another terminal and try to run terraform apply again in the same directory. The apply should fail because of the enabled state file locking:\n```bash\n$ terraform apply\nAcquiring state lock. This may take a few moments...\n\nError: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed\n...\n```\n6. You may also be interested in opening a AWS Management Console and checking the contents of DynamoDB table `terraform-statelock` used for locking.\n\n7. Destroy the playground:\n* Run terraform destroy in the root directory \n* Remove the state files from the bucket:\n```\n$ aws --region us-east-1 s3 rm s3://terraform-state-960 --recursive # use the name of your bucket\n```\n* Run terraform destroy in `terraform-required` directory \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemmkin%2Fterraform-statelock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartemmkin%2Fterraform-statelock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartemmkin%2Fterraform-statelock/lists"}