github.com/opentofu/opentofu@v1.7.1/internal/command/views/json/change_summary.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package json 7 8 import "fmt" 9 10 type Operation string 11 12 const ( 13 OperationApplied Operation = "apply" 14 OperationDestroyed Operation = "destroy" 15 OperationPlanned Operation = "plan" 16 ) 17 18 type ChangeSummary struct { 19 Add int `json:"add"` 20 Change int `json:"change"` 21 Import int `json:"import"` 22 Remove int `json:"remove"` 23 Operation Operation `json:"operation"` 24 } 25 26 // The summary strings for apply and plan are accidentally a public interface 27 // used by Terraform Cloud and Terraform Enterprise, so the exact formats of 28 // these strings are important. 29 func (cs *ChangeSummary) String() string { 30 switch cs.Operation { 31 case OperationApplied: 32 if cs.Import > 0 { 33 return fmt.Sprintf("Apply complete! Resources: %d imported, %d added, %d changed, %d destroyed.", cs.Import, cs.Add, cs.Change, cs.Remove) 34 } 35 return fmt.Sprintf("Apply complete! Resources: %d added, %d changed, %d destroyed.", cs.Add, cs.Change, cs.Remove) 36 case OperationDestroyed: 37 return fmt.Sprintf("Destroy complete! Resources: %d destroyed.", cs.Remove) 38 case OperationPlanned: 39 if cs.Import > 0 { 40 return fmt.Sprintf("Plan: %d to import, %d to add, %d to change, %d to destroy.", cs.Import, cs.Add, cs.Change, cs.Remove) 41 } 42 return fmt.Sprintf("Plan: %d to add, %d to change, %d to destroy.", cs.Add, cs.Change, cs.Remove) 43 default: 44 return fmt.Sprintf("%s: %d add, %d change, %d destroy", cs.Operation, cs.Add, cs.Change, cs.Remove) 45 } 46 }