Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Move ¶
type Move struct { // The module the resource is being moved from. SourceModule string // The module the resource is being moved to. This is equal to SourceModule // when the resource is being moved within the same module. DestinationModule string // The resource's address before the move. SourceAddress string // The resource's address after the move. DestinationAddress string }
A Move represents a Terraform resource that we should move from one address to another. A resource can be moved within the same module or to a different module.
func DetermineMoves ¶
func DetermineMoves(comparisons []ResourceComparison) []Move
type Plan ¶
type Plan struct { // The resources Terraform plans to create. ToCreate []Resource // The resources Terraform plans to delete. ToDelete []Resource }
A Plan represents a Terraform plan. It contains the resources Terraform plans to create and the resources Terraform plans to delete.
func MergePlans ¶
MergePlans merges the given plans into a single plan. This works because the engine only cares about the resources Terraform plans to create and the resources Terraform plans to delete. The module the resource is from is part of the resource itself, not part of the plan.
func SummarizeJSONPlan ¶
SummarizeJSONPlan takes the JSON representation of a Terraform plan, as returned by the Terraform CLI, and condenses it into a Plan containing all the information the tfautomv engine needs.
The moduleID argument can be any string, but must be unique for each Plan passed to the engine. Typically, it is the path to the module's directory.
type Resource ¶
type Resource struct { // The module where the resource is defined. ModuleID string // The resource's type. Type string // The resource's address within the module's state. Terraform uses the // address to map a module's source code to resources it manages. Address string // The resource's known attributes. In Terraform's state, attributes are // complex objects. We flatten them to make them easier to work with. // // For example, the following Terraform resource: // // resource "aws_instance" "web" { // ami = "ami-a1b2c3d4" // instance_type = "t2.micro" // // tags = { // Name = "HelloWorld" // Environment = "Production" // } // } // // Would be represented as the following Attributes: // // Attributes{ // "ami": "ami-a1b2c3d4", // "instance_type": "t2.micro", // "tags.Name": "HelloWorld", // "tags.Environment": "Production", // } // // Note that the "tags" attribute is flattened into "tags.Name" and // "tags.Environment". // // A value in the flattened map is either a string, a number, a boolean, or // nil. The nil value is used to represent null values in Terraform. Attributes map[string]any }
A Resource represents a Terraform resource. Whether Terraform plans to create or delete the resource does not matter; the resource is modeled in the same way in both cases.
type ResourceComparison ¶
type ResourceComparison struct { // The resource Terraform plans to create. ToCreate Resource // The resource Terraform plans to delete. ToDelete Resource // Keys of attributes that have the same value in both resources. MatchingAttributes []string // Keys of attributes that have different values in both resources. MismatchingAttributes []string // Keys of attributes that would normally be mismatching, but where the user // provided a rule that says to ignore that particular difference. IgnoredAttributes []string }
A ResourceComparison represents a pair of Terraform resources of the same type: one that Terraform plans to create and another that Terraform plans to delete. By comparing these resources, we can determine whether we should move the existing resource's state to the new resource's address.
An attribute is considered matching when both resources have the same value for that attribute. An attribute is considered mismatching when both resources have different values for that attribute. An attribute is considered ignored when both resources have different values for that attribute, but a rule says to ignore the difference between those values.
A ResourceComparison is considered a match when no attributes are mismatching.
func CompareAll ¶
func CompareAll(plan Plan, rules []Rule) []ResourceComparison
CompareAll compares each resource Terraform plans to create to each resource Terraform plans to delete of the same type. For each resource pair, it returns a ResourceComparison containing the result of the comparison.
By default, the comparison checks whether the resources' attributes are equal. This behavior can be tweeked by passing in engine rules that allow certain differences to be ignored.
func CompareResources ¶
func CompareResources(create, delete Resource, rules []Rule) ResourceComparison
CompareResources compares the attributes of two Terraform resources: one that Terraform plans to create and another that Terraform plans to delete.
func (ResourceComparison) IsMatch ¶
func (rc ResourceComparison) IsMatch() bool
IsMatch returns whether the two resources are a match.
type Rule ¶
type Rule interface { // Each rule has a unique string representation. This representation is how // users provides rules to tfautomv. String() string // Whether the rule applies to the given resource type and attribute. AppliesTo(resourceType, attribute string) bool // Whether the rule equates the two values. Equates(a, b interface{}) bool }
A Rule allows tfautomv to equate certains attribute values that would normally be considered different.