5 // ResourceInstancePhase is a special kind of reference used only internally
6 // during graph building to represent resource instances that are in a
9 // Graph nodes can declare themselves referenceable via an instance phase
10 // or can declare that they reference an instance phase in order to accomodate
11 // secondary graph nodes dealing with, for example, destroy actions.
13 // This special reference type cannot be accessed directly by end-users, and
14 // should never be shown in the UI.
15 type ResourceInstancePhase struct {
17 ResourceInstance ResourceInstance
18 Phase ResourceInstancePhaseType
21 var _ Referenceable = ResourceInstancePhase{}
23 // Phase returns a special "phase address" for the receving instance. See the
24 // documentation of ResourceInstancePhase for the limited situations where this
25 // is intended to be used.
26 func (r ResourceInstance) Phase(rpt ResourceInstancePhaseType) ResourceInstancePhase {
27 return ResourceInstancePhase{
33 // ContainingResource returns an address for the same phase of the resource
34 // that this instance belongs to.
35 func (rp ResourceInstancePhase) ContainingResource() ResourcePhase {
36 return rp.ResourceInstance.Resource.Phase(rp.Phase)
39 func (rp ResourceInstancePhase) String() string {
40 // We use a different separator here than usual to ensure that we'll
41 // never conflict with any non-phased resource instance string. This
42 // is intentionally something that would fail parsing with ParseRef,
43 // because this special address type should never be exposed in the UI.
44 return fmt.Sprintf("%s#%s", rp.ResourceInstance, rp.Phase)
47 // ResourceInstancePhaseType is an enumeration used with ResourceInstancePhase.
48 type ResourceInstancePhaseType string
51 // ResourceInstancePhaseDestroy represents the "destroy" phase of a
53 ResourceInstancePhaseDestroy ResourceInstancePhaseType = "destroy"
55 // ResourceInstancePhaseDestroyCBD is similar to ResourceInstancePhaseDestroy
56 // but is used for resources that have "create_before_destroy" set, thus
57 // requiring a different dependency ordering.
58 ResourceInstancePhaseDestroyCBD ResourceInstancePhaseType = "destroy-cbd"
61 func (rpt ResourceInstancePhaseType) String() string {
65 // ResourcePhase is a special kind of reference used only internally
66 // during graph building to represent resources that are in a
69 // Graph nodes can declare themselves referenceable via a resource phase
70 // or can declare that they reference a resource phase in order to accomodate
71 // secondary graph nodes dealing with, for example, destroy actions.
73 // Since resources (as opposed to instances) aren't actually phased, this
74 // address type is used only as an approximation during initial construction
75 // of the resource-oriented plan graph, under the assumption that resource
76 // instances with ResourceInstancePhase addresses will be created in dynamic
77 // subgraphs during the graph walk.
79 // This special reference type cannot be accessed directly by end-users, and
80 // should never be shown in the UI.
81 type ResourcePhase struct {
84 Phase ResourceInstancePhaseType
87 var _ Referenceable = ResourcePhase{}
89 // Phase returns a special "phase address" for the receving instance. See the
90 // documentation of ResourceInstancePhase for the limited situations where this
91 // is intended to be used.
92 func (r Resource) Phase(rpt ResourceInstancePhaseType) ResourcePhase {
99 func (rp ResourcePhase) String() string {
100 // We use a different separator here than usual to ensure that we'll
101 // never conflict with any non-phased resource instance string. This
102 // is intentionally something that would fail parsing with ParseRef,
103 // because this special address type should never be exposed in the UI.
104 return fmt.Sprintf("%s#%s", rp.Resource, rp.Phase)