Fix & improve state locking of OSS backend#24149
Fix & improve state locking of OSS backend#24149jbardin merged 7 commits intohashicorp:masterfrom mlafeldt:fix-oss-state-locking
Conversation
So that is shows up in lock errors, etc.
To allow using the same Tablestore table with multiple OSS buckets. e.g. instead of env:/some/path/terraform.tfstate the LockID now becomes some-bucket/env:/some/path/terraform.tfstate
|
I also added a test that shows the buggy behavior fixed by the PR. PTAL. |
|
@apparentlymart @pselle Is there anything I can do to move this forward? |
|
HI @mlafeldt Thanks for your contribution and I have a question that what do you mean "this breaks backward compatibility since the schema of the Tablestore table is different. I tried to fix the backend without having to change the schema, but couldn't make it work, even with additional row conditions/filters." ? Does it effect the existing state and lock? |
Yes, that's what I meant with breaking backward compatibility. Users have to create a new |
|
@mlafeldt Ok. Thanks for you feedback. |
|
@mlafeldt I wanted to check in here as the Terraform Core engineering manager. Thank you for contributing this improvement! @pkolyvas, our product manager, prompted @xiaozhu36 for review after you reached out, because he's the original author of the backend. I'm going to prompt the core team to review this now that he's approved it. |
|
Thanks for the contribution @mlafeldt, and the review @xiaozhu36 ! The master branch is the in-progress work for the 0.13 release, and this will be included in the next major release. This PR cannot be backported to the 0.12 release branch due to the backwards incompatible change. Thanks! |
Fix & improve state locking of OSS backend
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
While using the OSS backend with Terragrunt, which can execute many Terraform modules in parallel, I found multiple bugs in the way the backend handles state locking via Tablestore.
Current behavior
Currently, the locking works as follows:
This won't work when having more than one lock in the table at a time. What the backend actually does is provide a global lock for Terraform, not per-module locking.
For the same reason, MD5 hashing is broken as there can only be one hash at a time.
New behavior
This PR changes the logic to follow the more obvious data model of DynamoDB, which requires users to create a Tablestore table with a primary key named
LockID:Note that this breaks backward compatibility since the schema of the Tablestore table is different. I tried to fix the backend without having to change the schema, but couldn't make it work, even with additional row conditions/filters.
Tests are passing too:
cc @arafato @xiaozhu36