2015-02-11 19:01:08 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EvalSetVariables is an EvalNode implementation that sets the variables
|
|
|
|
// explicitly for interpolation later.
|
|
|
|
type EvalSetVariables struct {
|
|
|
|
Variables map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: test
|
2015-02-14 00:58:41 -06:00
|
|
|
func (n *EvalSetVariables) Eval(ctx EvalContext) (interface{}, error) {
|
2015-02-11 19:01:08 -06:00
|
|
|
ctx.SetVariables(n.Variables)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EvalVariableBlock is an EvalNode implementation that evaluates the
|
|
|
|
// given configuration, and uses the final values as a way to set the
|
|
|
|
// mapping.
|
|
|
|
type EvalVariableBlock struct {
|
2015-02-14 00:58:41 -06:00
|
|
|
Config **ResourceConfig
|
2015-02-11 19:01:08 -06:00
|
|
|
Variables map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: test
|
2015-02-14 00:58:41 -06:00
|
|
|
func (n *EvalVariableBlock) Eval(ctx EvalContext) (interface{}, error) {
|
2015-02-11 19:01:08 -06:00
|
|
|
// Clear out the existing mapping
|
|
|
|
for k, _ := range n.Variables {
|
|
|
|
delete(n.Variables, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get our configuration
|
2015-02-14 00:58:41 -06:00
|
|
|
rc := *n.Config
|
2015-02-11 19:01:08 -06:00
|
|
|
for k, v := range rc.Config {
|
|
|
|
n.Variables[k] = v.(string)
|
|
|
|
}
|
|
|
|
for k, _ := range rc.Raw {
|
|
|
|
if _, ok := n.Variables[k]; !ok {
|
|
|
|
n.Variables[k] = config.UnknownVariableValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|