github.com/opentofu/opentofu@v1.7.1/internal/states/statemgr/lineage.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package statemgr
     7  
     8  import (
     9  	"fmt"
    10  
    11  	"github.com/hashicorp/go-uuid"
    12  )
    13  
    14  // NewLineage generates a new lineage identifier string. A lineage identifier
    15  // is an opaque string that is intended to be unique in space and time, chosen
    16  // when state is recorded at a location for the first time and then preserved
    17  // afterwards to allow OpenTofu to recognize when one state snapshot is a
    18  // predecessor or successor of another.
    19  func NewLineage() string {
    20  	lineage, err := uuid.GenerateUUID()
    21  	if err != nil {
    22  		panic(fmt.Errorf("Failed to generate lineage: %w", err))
    23  	}
    24  	return lineage
    25  }