mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
034e944070
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package objchange
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/internal/plans"
|
|
)
|
|
|
|
// ActionForChange determines which plans.Action value best describes a
|
|
// change from the value given in before to the value given in after.
|
|
//
|
|
// Because it has no context aside from the values, it can only return the
|
|
// basic actions NoOp, Create, Update, and Delete. Other codepaths with
|
|
// additional information might make this decision differently, such as by
|
|
// using the Replace action instead of the Update action where that makes
|
|
// sense.
|
|
//
|
|
// If the after value is unknown then the action can't be properly decided, and
|
|
// so ActionForChange will conservatively return either Create or Update
|
|
// depending on whether the before value is null. The before value must always
|
|
// be fully known; ActionForChange will panic if it contains any unknown values.
|
|
func ActionForChange(before, after cty.Value) plans.Action {
|
|
switch {
|
|
case !after.IsKnown():
|
|
if before.IsNull() {
|
|
return plans.Create
|
|
}
|
|
return plans.Update
|
|
case after.IsNull() && before.IsNull():
|
|
return plans.NoOp
|
|
case after.IsNull() && !before.IsNull():
|
|
return plans.Delete
|
|
case before.IsNull() && !after.IsNull():
|
|
return plans.Create
|
|
case after.RawEquals(before):
|
|
return plans.NoOp
|
|
default:
|
|
return plans.Update
|
|
}
|
|
}
|