Read state lock info and lock holder info from environment variables #34265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The defult
LockInfo
object created by terraform duirng state locking does not use theInfo
field present inLockInfo
object which is useful for storing metadata. Neither does the it effectively set theWho
field. Currently theWho
field default touser@host
. Which isn't useful when the lock is being created from inside a docker image or in a CI/CD pipeline. In those cases, the user might find it useful if theWho
field was instead configurable.This PR adds the feature of reading
Info
andWho
fields for theLockInfo
object from theTF_LOCK_METADATA
andTF_LOCK_OWNER_ID
environment variables if present from thestatemgr.NewLockInfo
method which is used as the defaultLockInfo
factory in all backends in this repo. If the environment variables are not present, the code defaults to the old behavior and thus wouldn't change anything.As a rationale for the usages of this feature, consider the case where terraform plans are ran from a CI/CD pipeline like in Jenkins. One might want to know which build of which job caused the plan to lock. Then setting
TF_LOCK_OWNER_ID=${JOB_NAME}-${JOB_NUMBER}
will resolve the issue.Fixes #
Target Release
1.5.x
Draft CHANGELOG entry
ENHANCEMENTS
TF_LOCK_METADATA
environment variable.LockInfo
by exporting theTF_LOCK_OWNER_ID
environment variable.Info
field won't be present, and theWho
field will default touser@host
i.e this PR only adds on top of existing features are keeps it backward compatible.