From 756ae621bd97a8b776fefb15e5e7e2292f98ee45 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 9 Jul 2026 00:14:33 +0300 Subject: dependencies --- internal/resource/multi.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/resource/multi.go') 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 -- cgit v1.2.3