github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/plan_file.go (about)

     1  package ots
     2  
     3  const (
     4  	CreateAction ChangeAction = "create"
     5  	UpdateAction ChangeAction = "update"
     6  	DeleteAction ChangeAction = "delete"
     7  )
     8  
     9  // PlanFile represents the schema of a plan file
    10  type PlanFile struct {
    11  	ResourcesChanges []ResourceChange `json:"resource_changes"`
    12  }
    13  
    14  // ResourceChange represents a proposed change to a resource in a plan file
    15  type ResourceChange struct {
    16  	Change Change
    17  }
    18  
    19  // Change represents the type of change being made
    20  type Change struct {
    21  	Actions []ChangeAction
    22  }
    23  
    24  type ChangeAction string
    25  
    26  // Changes provides a tally of the types of changes proposed in the plan file.
    27  func (pf *PlanFile) Changes() (adds int, updates int, deletes int) {
    28  	for _, rc := range pf.ResourcesChanges {
    29  		for _, action := range rc.Change.Actions {
    30  			switch action {
    31  			case CreateAction:
    32  				adds++
    33  			case UpdateAction:
    34  				updates++
    35  			case DeleteAction:
    36  				deletes++
    37  			}
    38  		}
    39  	}
    40  
    41  	return
    42  }