in ec/internal/planmodifiers/use_state_unless_template_changed.go [64:119]
func (m useStateForUnknownUnlessMigrationIsRequired) UseState(ctx context.Context, configValue attr.Value, plan tfsdk.Plan, state tfsdk.State, planValue attr.Value, stateValue attr.Value) (bool, diag.Diagnostics) {
var diags diag.Diagnostics
var parentResState attr.Value
if d := state.GetAttribute(ctx, path.Root(m.resourceKind), &parentResState); d.HasError() {
return false, d
}
resourceIsBeingCreated := parentResState.IsNull()
if resourceIsBeingCreated {
return false, nil
}
if stateValue.IsNull() && !m.isNullable {
return false, nil
}
if !planValue.IsUnknown() {
return false, nil
}
// if the config is the unknown value, use the unknown value otherwise, interpolation gets messed up
if configValue.IsUnknown() {
return false, nil
}
templateChanged, d := AttributeChanged(ctx, path.Root("deployment_template_id"), plan, state)
diags.Append(d...)
// If template changed, we won't use state
if templateChanged {
return false, diags
}
var migrateToLatestHw bool
plan.GetAttribute(ctx, path.Root("migrate_to_latest_hardware"), &migrateToLatestHw)
// If migrate_to_latest_hardware isn't set, we want to use state
if !migrateToLatestHw {
return true, diags
}
isMigrationAvailable, d := CheckAvailableMigration(ctx, plan, state, path.Root(m.resourceKind))
diags.Append(d...)
if diags.HasError() {
return false, diags
}
if isMigrationAvailable {
return false, diags
}
return true, diags
}