opentofu/terraform/eval_interpolate.go

57 lines
1.3 KiB
Go
Raw Normal View History

2015-02-03 03:43:18 -06:00
package terraform
import (
"log"
"github.com/hashicorp/terraform/config"
)
2015-02-03 03:43:18 -06:00
// EvalInterpolate is an EvalNode implementation that takes a raw
// configuration and interpolates it.
type EvalInterpolate struct {
Config *config.RawConfig
Resource *Resource
Output **ResourceConfig
ContinueOnErr bool
2015-02-03 03:43:18 -06:00
}
2015-02-14 00:58:41 -06:00
func (n *EvalInterpolate) Eval(ctx EvalContext) (interface{}, error) {
rc, err := ctx.Interpolate(n.Config, n.Resource)
if err != nil {
if n.ContinueOnErr {
log.Printf("[WARN] Interpolation %q failed: %s", n.Config.Key, err)
return nil, EvalEarlyExitError{}
}
2015-02-14 00:58:41 -06:00
return nil, err
}
2015-02-03 03:43:18 -06:00
2015-02-14 00:58:41 -06:00
if n.Output != nil {
*n.Output = rc
}
2015-02-03 03:43:18 -06:00
2015-02-14 00:58:41 -06:00
return nil, nil
2015-02-03 03:43:18 -06:00
}
// EvalInterpolateProvider is an EvalNode implementation that takes a
// ProviderConfig and interpolates it. Provider configurations are the only
// "inherited" type of configuration we have, and the original raw config may
// have a different interpolation scope.
type EvalInterpolateProvider struct {
Config *config.ProviderConfig
Resource *Resource
Output **ResourceConfig
}
func (n *EvalInterpolateProvider) Eval(ctx EvalContext) (interface{}, error) {
rc, err := ctx.InterpolateProvider(n.Config, n.Resource)
if err != nil {
return nil, err
}
if n.Output != nil {
*n.Output = rc
}
return nil, nil
}