2017-01-10 00:15:48 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/state"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Attempt to open and lock a terraform 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 := &state.LocalState{
|
|
|
|
Path: os.Args[1],
|
|
|
|
}
|
|
|
|
|
2017-02-15 16:25:04 +01:00
|
|
|
info := state.NewLockInfo()
|
|
|
|
info.Operation = "test"
|
|
|
|
info.Info = "state locker"
|
|
|
|
|
|
|
|
_, err := s.Lock(info)
|
2017-01-10 00:15:48 +01:00
|
|
|
if err != nil {
|
|
|
|
io.WriteString(os.Stderr, "lock failed")
|
|
|
|
|
|
|
|
}
|
2017-02-15 01:00:36 +01:00
|
|
|
|
2017-01-10 00:15:48 +01:00
|
|
|
return
|
|
|
|
}
|