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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
package tfjson
// Action is a valid action type for a resource change.
//
// Note that a singular Action is not telling of a full resource
// change operation. Certain resource actions, such as replacement,
// are a composite of more than one type. See the Actions type and
// its helpers for more information.
type Action string
const (
// ActionNoop denotes a no-op operation.
ActionNoop Action = "no-op"
// ActionCreate denotes a create operation.
ActionCreate Action = "create"
// ActionRead denotes a read operation.
ActionRead Action = "read"
// ActionUpdate denotes an update operation.
ActionUpdate Action = "update"
// ActionDelete denotes a delete operation.
ActionDelete Action = "delete"
)
// Actions denotes a valid change type.
type Actions []Action
// NoOp is true if this set of Actions denotes a no-op.
func (a Actions) NoOp() bool {
if len(a) != 1 {
return false
}
return a[0] == ActionNoop
}
// Create is true if this set of Actions denotes creation of a new
// resource.
func (a Actions) Create() bool {
if len(a) != 1 {
return false
}
return a[0] == ActionCreate
}
// Read is true if this set of Actions denotes a read operation only.
func (a Actions) Read() bool {
if len(a) != 1 {
return false
}
return a[0] == ActionRead
}
// Update is true if this set of Actions denotes an update operation.
func (a Actions) Update() bool {
if len(a) != 1 {
return false
}
return a[0] == ActionUpdate
}
// Delete is true if this set of Actions denotes resource removal.
func (a Actions) Delete() bool {
if len(a) != 1 {
return false
}
return a[0] == ActionDelete
}
// DestroyBeforeCreate is true if this set of Actions denotes a
// destroy-before-create operation. This is the standard resource
// replacement method.
func (a Actions) DestroyBeforeCreate() bool {
if len(a) != 2 {
return false
}
return a[0] == ActionDelete && a[1] == ActionCreate
}
// CreateBeforeDestroy is true if this set of Actions denotes a
// create-before-destroy operation, usually the result of replacement
// to a resource that has the create_before_destroy lifecycle option
// set.
func (a Actions) CreateBeforeDestroy() bool {
if len(a) != 2 {
return false
}
return a[0] == ActionCreate && a[1] == ActionDelete
}
// Replace is true if this set of Actions denotes a valid replacement
// operation.
func (a Actions) Replace() bool {
return a.DestroyBeforeCreate() || a.CreateBeforeDestroy()
}
|