github.com/justnom/terraform@v0.5.4-0.20180524223219-170a1530d1ca/state/testdata/lockstate.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"log"
     6  	"os"
     7  
     8  	"github.com/hashicorp/terraform/state"
     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 := &state.LocalState{
    19  		Path: os.Args[1],
    20  	}
    21  
    22  	info := state.NewLockInfo()
    23  	info.Operation = "test"
    24  	info.Info = "state locker"
    25  
    26  	_, err := s.Lock(info)
    27  	if err != nil {
    28  		io.WriteString(os.Stderr, "lock failed")
    29  
    30  	}
    31  
    32  	return
    33  }