mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-03-23 04:00:32 -04:00
We've now accumulated a whole bunch of places where we pass around addrs.AbsResourceInstance and states.DeposedKey fields together to represent a resource instance object. It's easier for different subsystems to collaborate on a concept if we have a single address type to use when "talking about it", so this establishes an address type for absolute resource instance objects that carries both fields together. This also includes an addrs.UniqueKeyer implementation so that addresses of this type can be used as keys in addrs.Set and addrs.Map collections, and a default string representation we can use when mentioning resource instance objects in error messages, etc. The main reason we didn't do this sooner is that the "deposed key" type was in package states rather than in package addrs, and states already depends on addrs. Therefore this also moves DeposedKey into package addrs, leaving behind an alias at the old name so we can defer updating existing code until we'd next be making significant changes to it for another reason. Unfortunately DeposedKey is also part of the legacy "Generation" concept that parts of the main language runtime still depend on. That was originally something more complicated but these days is really just a less efficient way of representing exactly the same information that DeposedKey can already represent. It's preserved here for now as addrs.ResourceInstanceObjectGeneration with an alias at the old name, but hopefully over time we can replace all uses of it with direct use of addrs.DeposedKey. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
26 lines
1.1 KiB
Go
26 lines
1.1 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package states
|
|
|
|
import "github.com/opentofu/opentofu/internal/addrs"
|
|
|
|
// Generation is used to represent multiple objects in a succession of objects
|
|
// represented by a single resource instance address. A resource instance can
|
|
// have multiple generations over its lifetime due to object replacement
|
|
// (when a change can't be applied without destroying and re-creating), and
|
|
// multiple generations can exist at the same time when create_before_destroy
|
|
// is used.
|
|
//
|
|
// A Generation value can either be the value of the variable "CurrentGen" or
|
|
// a value of type DeposedKey. Generation values can be compared for equality
|
|
// using "==" and used as map keys. The zero value of Generation (nil) is not
|
|
// a valid generation and must not be used.
|
|
type Generation = addrs.ResourceInstanceObjectGeneration
|
|
|
|
// CurrentGen is the Generation representing the currently-active object for
|
|
// a resource instance.
|
|
var CurrentGen = addrs.CurrentResourceInstanceObjectGeneration
|