summaryrefslogtreecommitdiff
path: root/internal/resource/multi.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/resource/multi.go')
-rw-r--r--internal/resource/multi.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/resource/multi.go b/internal/resource/multi.go
index 1694814..3916287 100644
--- a/internal/resource/multi.go
+++ b/internal/resource/multi.go
@@ -5,6 +5,13 @@ import (
"strings"
)
+// Dependency is implemented by anything that can be depended upon. It returns
+// the flattened list of individual resource IDs, so that depending on a Multi
+// expands into a dependency on each of its members individually.
+type Dependency interface {
+ Dependencies() []string
+}
+
// Multi is a collection of resources that satisfies the api.Resource interface.
type Multi []Resource
@@ -28,6 +35,19 @@ func (m Multi) ID() string {
return strings.Join(ids, "+")
}
+// Dependencies flattens the Multi into the IDs of each of its members, so a
+// dependency on a Multi becomes an individual dependency on every resource it
+// contains.
+func (m Multi) Dependencies() []string {
+ ids := make([]string, 0, len(m))
+
+ for _, res := range m {
+ ids = append(ids, res.Dependencies()...)
+ }
+
+ return ids
+}
+
func (m Multi) Apply() error {
var errs []error