opentofu/internal/command/views/json/change_summary.go
Martin Atkins ffe056bacb Move command/ to internal/command/
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.
2021-05-17 14:09:07 -07:00

35 lines
1.1 KiB
Go

package json
import "fmt"
type Operation string
const (
OperationApplied Operation = "apply"
OperationDestroyed Operation = "destroy"
OperationPlanned Operation = "plan"
)
type ChangeSummary struct {
Add int `json:"add"`
Change int `json:"change"`
Remove int `json:"remove"`
Operation Operation `json:"operation"`
}
// The summary strings for apply and plan are accidentally a public interface
// used by Terraform Cloud and Terraform Enterprise, so the exact formats of
// these strings are important.
func (cs *ChangeSummary) String() string {
switch cs.Operation {
case OperationApplied:
return fmt.Sprintf("Apply complete! Resources: %d added, %d changed, %d destroyed.", cs.Add, cs.Change, cs.Remove)
case OperationDestroyed:
return fmt.Sprintf("Destroy complete! Resources: %d destroyed.", cs.Remove)
case OperationPlanned:
return fmt.Sprintf("Plan: %d to add, %d to change, %d to destroy.", cs.Add, cs.Change, cs.Remove)
default:
return fmt.Sprintf("%s: %d add, %d change, %d destroy", cs.Operation, cs.Add, cs.Change, cs.Remove)
}
}