mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
772ac1fc35
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
32 lines
557 B
Go
32 lines
557 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/opentofu/opentofu/internal/states/statemgr"
|
|
)
|
|
|
|
// Attempt to open and lock a tofu state file.
|
|
// Lock failure exits with 0 and writes "lock failed" to stderr.
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
log.Fatal(os.Args[0], "statefile")
|
|
}
|
|
|
|
s := statemgr.NewFilesystem(os.Args[1])
|
|
|
|
info := statemgr.NewLockInfo()
|
|
info.Operation = "test"
|
|
info.Info = "state locker"
|
|
|
|
ctx := context.Background()
|
|
|
|
_, err := s.Lock(ctx, info)
|
|
if err != nil {
|
|
io.WriteString(os.Stderr, "lock failed")
|
|
}
|
|
}
|