pulumi/pkg/compiler/context.go
joeduffy c1b5239667 Detect target cloud earlier on
This change detects the target cloud earlier on in the compilation process.
Prior to this change, we didn't know this information until the backend code-generation.
Clearly we need to know this at least by then, however, templates can specialize on this
information, so we actually need it sooner.  This change moves it into the frontend part.

Note that to support this we now eliminate the ability to specify target clusters in
the Mufile alone.  That "feels" right to me anyway, since Mufiles are supposed to be
agnostic to their deployment environment, other than template specialization.  Instead,
this information can come from the CLI and/or the workspace settings file.
2016-11-29 13:42:39 -08:00

43 lines
1.2 KiB
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package compiler
import (
"github.com/marapongo/mu/pkg/ast"
"github.com/marapongo/mu/pkg/compiler/backends"
"github.com/marapongo/mu/pkg/util"
)
// Context holds all state available to any templates or code evaluated at compile-time.
type Context struct {
Cluster *ast.Cluster // the cluster that we will deploy to.
Arch backends.Arch // the target cloud architecture.
Properties ast.PropertyBag // properties supplied at stack construction time.
}
// NewContext returns a new, empty context.
func NewContext() *Context {
return &Context{
Properties: make(ast.PropertyBag),
}
}
// WithClusterArch returns a clone of this Context with the given cluster and architecture attached to it.
func (c *Context) WithClusterArch(cl *ast.Cluster, a backends.Arch) *Context {
util.Assert(cl != nil)
return &Context{
Cluster: cl,
Arch: a,
Properties: c.Properties,
}
}
// WithProps returns a clone of this Context with the given properties attached to it.
func (c *Context) WithProps(props ast.PropertyBag) *Context {
util.Assert(props != nil)
return &Context{
Cluster: c.Cluster,
Arch: c.Arch,
Properties: props,
}
}