github.com/databricks/cli@v0.203.0/bundle/deploy/terraform/util.go (about)

     1  package terraform
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  )
     7  
     8  type state struct {
     9  	Serial int `json:"serial"`
    10  }
    11  
    12  func IsLocalStateStale(local io.Reader, remote io.Reader) bool {
    13  	localState, err := loadState(local)
    14  	if err != nil {
    15  		return true
    16  	}
    17  
    18  	remoteState, err := loadState(remote)
    19  	if err != nil {
    20  		return false
    21  	}
    22  
    23  	return localState.Serial < remoteState.Serial
    24  }
    25  
    26  func loadState(input io.Reader) (*state, error) {
    27  	content, err := io.ReadAll(input)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	var s state
    32  	err = json.Unmarshal(content, &s)
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	return &s, nil
    38  }