Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions bundle/deployplan/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,38 @@ type Action struct {

func (a Action) String() string {
typ, _ := strings.CutSuffix(a.Group, "s")
return fmt.Sprintf(" %s %s %s", a.ActionType, typ, a.Key)
return fmt.Sprintf(" %s %s %s", a.ActionType.String(), typ, a.Key)
}

// Implements cmdio.Event for cmdio.Log
func (a Action) IsInplaceSupported() bool {
return false
}

// These enum values are superset to action types defined in the tfjson library.
// "recreate" maps to the tfjson.Actions.Replace() function.
// "update" and "update_with_id" maps to tfjson.Actions.Update() and so on. source:
// https://github.com/hashicorp/terraform-json/blob/0104004301ca8e7046d089cdc2e2db2179d225be/action.go#L14
type ActionType string
type ActionType int

// Actions are ordered in increasing severity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: After looking at https://github.com/databricks/cli/pull/3595/files, this should be priority, not severity.

// If case of several options, action with highest severity wins.
// Note, Create/Delete are handled explicitly and never compared.
const (
ActionTypeUnset ActionType = ""
ActionTypeNoop ActionType = "noop"
ActionTypeCreate ActionType = "create"
ActionTypeDelete ActionType = "delete"
ActionTypeUpdate ActionType = "update"
ActionTypeUpdateWithID ActionType = "update_with_id"
ActionTypeRecreate ActionType = "recreate"
ActionTypeUnset ActionType = iota
ActionTypeNoop
ActionTypeResize
ActionTypeUpdate
ActionTypeUpdateWithID
ActionTypeCreate
ActionTypeRecreate
ActionTypeDelete
)

var ShortName = map[ActionType]ActionType{
ActionTypeUpdateWithID: ActionTypeUpdate,
var ShortName = map[ActionType]string{
ActionTypeNoop: "noop",
ActionTypeResize: "resize",
ActionTypeUpdate: "update",
ActionTypeUpdateWithID: "update",
ActionTypeCreate: "create",
ActionTypeRecreate: "recreate",
ActionTypeDelete: "delete",
}

func (a ActionType) IsNoop() bool {
Expand All @@ -47,23 +53,15 @@ func (a ActionType) IsNoop() bool {

func (a ActionType) KeepsID() bool {
switch a {
case ActionTypeCreate:
return false
case ActionTypeUpdateWithID:
return false
case ActionTypeRecreate:
case ActionTypeCreate, ActionTypeUpdateWithID, ActionTypeRecreate:
return false
default:
return true
}
}

func (a ActionType) String() string {
shortAction := ShortName[a]
if shortAction != "" {
return string(shortAction)
}
return string(a)
return ShortName[a]
}

// Filter returns actions that match the specified action type
Expand Down
12 changes: 6 additions & 6 deletions bundle/terranova/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ func (d *DeploymentUnit) plan(ctx context.Context, client *databricks.WorkspaceC
return deployplan.ActionTypeCreate, nil
}
if entry.ID == "" {
return "", errors.New("invalid state: empty id")
return deployplan.ActionTypeUnset, errors.New("invalid state: empty id")
}

newState, err := d.Adapter.PrepareState(inputConfig)
if err != nil {
return "", fmt.Errorf("reading config: %w", err)
return deployplan.ActionTypeUnset, fmt.Errorf("reading config: %w", err)
}

savedState, err := typeConvert(d.Adapter.StateType(), entry.State)
if err != nil {
return "", fmt.Errorf("interpreting state: %w", err)
return deployplan.ActionTypeUnset, fmt.Errorf("interpreting state: %w", err)
}

// Note, currently we're diffing static structs, not dynamic value.
Expand Down Expand Up @@ -200,7 +200,7 @@ func (d *DeploymentUnit) ReadRemoteStateField(ctx context.Context, db *tnstate.T
func calcDiff(adapter *tnresources.Adapter, savedState, config any) (deployplan.ActionType, error) {
localDiff, err := structdiff.GetStructDiff(savedState, config)
if err != nil {
return "", err
return deployplan.ActionTypeUnset, err
}

if len(localDiff) == 0 {
Expand All @@ -214,11 +214,11 @@ func calcDiff(adapter *tnresources.Adapter, savedState, config any) (deployplan.
if adapter.HasClassifyChanges() {
result, err := adapter.ClassifyChanges(localDiff)
if err != nil {
return "", err
return deployplan.ActionTypeUnset, err
}

if result == deployplan.ActionTypeUpdateWithID && !adapter.HasDoUpdateWithID() {
return "", errors.New("internal error: unexpected plan='update_with_id'")
return deployplan.ActionTypeUnset, errors.New("internal error: unexpected plan='update_with_id'")
}

return result, nil
Expand Down
4 changes: 2 additions & 2 deletions bundle/terranova/tnresources/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ func (a *Adapter) MustRecreate(changes []structdiff.Change) bool {
// ClassifyChanges calls the resource's ClassifyChanges method if implemented.
func (a *Adapter) ClassifyChanges(changes []structdiff.Change) (deployplan.ActionType, error) {
if a.classifyChanges == nil {
return "", errors.New("internal error: ClassifyChanges not implemented")
return deployplan.ActionTypeUnset, errors.New("internal error: ClassifyChanges not implemented")
}
outs, err := a.classifyChanges.Call(changes)
if err != nil {
return "", err
return deployplan.ActionTypeUnset, err
}
result := outs[0].(deployplan.ActionType)
return result, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/bundle/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newPlanCommand() *cobra.Command {
changes := phases.Diff(ctx, b)

for _, change := range changes {
cmdio.LogString(ctx, fmt.Sprintf("%s %s.%s", change.ActionType, change.Group, change.Key))
cmdio.LogString(ctx, fmt.Sprintf("%s %s.%s", change.ActionType.String(), change.Group, change.Key))
}

if logdiag.HasError(ctx) {
Expand Down
Loading