-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
change_summary.go
44 lines (38 loc) · 1.49 KB
/
change_summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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"`
Import int `json:"import"`
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:
if cs.Import > 0 {
return fmt.Sprintf("Apply complete! Resources: %d imported, %d added, %d changed, %d destroyed.", cs.Import, cs.Add, cs.Change, cs.Remove)
}
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:
if cs.Import > 0 {
return fmt.Sprintf("Plan: %d to import, %d to add, %d to change, %d to destroy.", cs.Import, cs.Add, cs.Change, cs.Remove)
}
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)
}
}