github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/states/statemgr/testdata/lockstate.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"log"
     6  	"os"
     7  
     8  	"github.com/hashicorp/terraform/states/statemgr"
     9  )
    10  
    11  // Attempt to open and lock a terraform state file.
    12  // Lock failure exits with 0 and writes "lock failed" to stderr.
    13  func main() {
    14  	if len(os.Args) != 2 {
    15  		log.Fatal(os.Args[0], "statefile")
    16  	}
    17  
    18  	s := statemgr.NewFilesystem(os.Args[1])
    19  
    20  	info := statemgr.NewLockInfo()
    21  	info.Operation = "test"
    22  	info.Info = "state locker"
    23  
    24  	_, err := s.Lock(info)
    25  	if err != nil {
    26  		io.WriteString(os.Stderr, "lock failed")
    27  	}
    28  }