6 "github.com/hashicorp/terraform/config"
9 // EvalBuildProviderConfig outputs a *ResourceConfig that is properly
10 // merged with parents and inputs on top of what is configured in the file.
11 type EvalBuildProviderConfig struct {
13 Config **ResourceConfig
14 Output **ResourceConfig
17 func (n *EvalBuildProviderConfig) Eval(ctx EvalContext) (interface{}, error) {
20 // If we have an Input configuration set, then merge that in
21 if input := ctx.ProviderInput(n.Provider); input != nil {
22 // "input" is a map of the subset of config values that were known
23 // during the input walk, set by EvalInputProvider. Note that
24 // in particular it does *not* include attributes that had
25 // computed values at input time; those appear *only* in
27 rc, err := config.NewRawConfig(input)
32 merged := rc.Merge(cfg.raw)
33 cfg = NewResourceConfig(merged)
40 // EvalConfigProvider is an EvalNode implementation that configures
41 // a provider that is already initialized and retrieved.
42 type EvalConfigProvider struct {
44 Config **ResourceConfig
47 func (n *EvalConfigProvider) Eval(ctx EvalContext) (interface{}, error) {
48 return nil, ctx.ConfigureProvider(n.Provider, *n.Config)
51 // EvalInitProvider is an EvalNode implementation that initializes a provider
52 // and returns nothing. The provider can be retrieved again with the
53 // EvalGetProvider node.
54 type EvalInitProvider struct {
59 func (n *EvalInitProvider) Eval(ctx EvalContext) (interface{}, error) {
60 return ctx.InitProvider(n.TypeName, n.Name)
63 // EvalCloseProvider is an EvalNode implementation that closes provider
64 // connections that aren't needed anymore.
65 type EvalCloseProvider struct {
69 func (n *EvalCloseProvider) Eval(ctx EvalContext) (interface{}, error) {
70 ctx.CloseProvider(n.Name)
74 // EvalGetProvider is an EvalNode implementation that retrieves an already
75 // initialized provider instance for the given name.
76 type EvalGetProvider struct {
78 Output *ResourceProvider
81 func (n *EvalGetProvider) Eval(ctx EvalContext) (interface{}, error) {
82 result := ctx.Provider(n.Name)
84 return nil, fmt.Errorf("provider %s not initialized", n.Name)
94 // EvalInputProvider is an EvalNode implementation that asks for input
95 // for the given provider configurations.
96 type EvalInputProvider struct {
98 Provider *ResourceProvider
99 Config **ResourceConfig
102 func (n *EvalInputProvider) Eval(ctx EvalContext) (interface{}, error) {
104 orig := rc.DeepCopy()
106 // Wrap the input into a namespace
107 input := &PrefixUIInput{
108 IdPrefix: fmt.Sprintf("provider.%s", n.Name),
109 QueryPrefix: fmt.Sprintf("provider.%s.", n.Name),
110 UIInput: ctx.Input(),
113 // Go through each provider and capture the input necessary
115 config, err := (*n.Provider).Input(input, rc)
117 return nil, fmt.Errorf(
118 "Error configuring %s: %s", n.Name, err)
121 // We only store values that have changed through Input.
122 // The goal is to cache cache input responses, not to provide a complete
123 // config for other providers.
124 confMap := make(map[string]interface{})
125 if config != nil && len(config.Config) > 0 {
126 // any values that weren't in the original ResourcConfig will be cached
127 for k, v := range config.Config {
128 if _, ok := orig.Config[k]; !ok {
134 ctx.SetProviderInput(n.Name, confMap)