-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatten modules into main graph #1781
Changes from 27 commits
1152ff5
90cfade
15ca84a
5e767f6
12c30fe
3bfef7c
e542d6e
dd14ce9
7e838df
a0d9bc0
f24a153
7d28e98
e544e1d
9a54ddd
f2e7f50
86d07d3
416e7a2
94e1bab
c207bed
7fd432b
8f58367
1f10dfe
23b6acc
bbb065d
542ddb8
6afc149
cc0c208
2f3f680
13f3daa
c3ce23c
803348d
6d4969f
d503cc2
8c34e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ import ( | |
type BuiltinEvalContext struct { | ||
PathValue []string | ||
Interpolater *Interpolater | ||
InterpolaterVars map[string]map[string]string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love a quick high level explanation for the Interp vars stuff. I can see the pieces but it'd be helpful to hear the overall story. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added a comment on the new diff. |
||
InterpolaterVarLock *sync.Mutex | ||
Hooks []Hook | ||
InputValue UIInput | ||
Providers map[string]ResourceProviderFactory | ||
|
@@ -237,9 +239,23 @@ func (ctx *BuiltinEvalContext) Path() []string { | |
return ctx.PathValue | ||
} | ||
|
||
func (ctx *BuiltinEvalContext) SetVariables(vs map[string]string) { | ||
func (ctx *BuiltinEvalContext) SetVariables(n string, vs map[string]string) { | ||
ctx.InterpolaterVarLock.Lock() | ||
defer ctx.InterpolaterVarLock.Unlock() | ||
|
||
path := make([]string, len(ctx.Path())+1) | ||
copy(path, ctx.Path()) | ||
path[len(path)-1] = n | ||
key := PathCacheKey(path) | ||
|
||
vars := ctx.InterpolaterVars[key] | ||
if vars == nil { | ||
vars = make(map[string]string) | ||
ctx.InterpolaterVars[key] = vars | ||
} | ||
|
||
for k, v := range vs { | ||
ctx.Interpolater.Variables[k] = v | ||
vars[k] = v | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ type BuiltinGraphBuilder struct { | |
// Build builds the graph according to the steps returned by Steps. | ||
func (b *BuiltinGraphBuilder) Build(path []string) (*Graph, error) { | ||
basic := &BasicGraphBuilder{ | ||
Steps: b.Steps(), | ||
Steps: b.Steps(path), | ||
Validate: b.Validate, | ||
} | ||
|
||
|
@@ -100,7 +100,7 @@ func (b *BuiltinGraphBuilder) Build(path []string) (*Graph, error) { | |
|
||
// Steps returns the ordered list of GraphTransformers that must be executed | ||
// to build a complete graph. | ||
func (b *BuiltinGraphBuilder) Steps() []GraphTransformer { | ||
func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed this too for module targeting. I'll rebase on top of this. |
||
steps := []GraphTransformer{ | ||
// Create all our resources from the configuration and state | ||
&ConfigTransformer{Module: b.Root}, | ||
|
@@ -134,24 +134,41 @@ func (b *BuiltinGraphBuilder) Steps() []GraphTransformer { | |
}, | ||
}, | ||
|
||
// Flatten stuff | ||
&FlattenTransformer{}, | ||
|
||
// Make sure all the connections that are proxies are connected through | ||
&ProxyTransformer{}, | ||
|
||
// Optionally reduces the graph to a user-specified list of targets and | ||
// their dependencies. | ||
&TargetsTransformer{Targets: b.Targets, Destroy: b.Destroy}, | ||
|
||
// Create the destruction nodes | ||
&DestroyTransformer{}, | ||
&CreateBeforeDestroyTransformer{}, | ||
b.conditional(&conditionalOpts{ | ||
If: func() bool { return !b.Verbose }, | ||
Then: &PruneDestroyTransformer{Diff: b.Diff, State: b.State}, | ||
}), | ||
|
||
// Make sure we create one root | ||
// Make sure we have a single root | ||
&RootTransformer{}, | ||
} | ||
|
||
// Perform the transitive reduction to make our graph a bit | ||
// more sane if possible (it usually is possible). | ||
&TransitiveReductionTransformer{}, | ||
// If we're on the root path, then we do a bunch of other stuff. | ||
// We don't do the following for modules. | ||
if len(path) <= 1 { | ||
steps = append(steps, | ||
// Create the destruction nodes | ||
&DestroyTransformer{}, | ||
&CreateBeforeDestroyTransformer{}, | ||
b.conditional(&conditionalOpts{ | ||
If: func() bool { return !b.Verbose }, | ||
Then: &PruneDestroyTransformer{Diff: b.Diff, State: b.State}, | ||
}), | ||
|
||
// Make sure we have a single root after the above changes. | ||
// This is the 2nd root transformer. In practice this shouldn't | ||
// actually matter as the RootTransformer is idempotent. | ||
&RootTransformer{}, | ||
|
||
// Perform the transitive reduction to make our graph a bit | ||
// more sane if possible (it usually is possible). | ||
&TransitiveReductionTransformer{}, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah this is funky, but agreed with top-level description that it's better to land it working and then refactor. |
||
} | ||
|
||
// Remove nils | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love how the big overarching test comes first in the diff. 😄
"WE GON' MAKE THIS WORK!"