]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/terraform/eval_output.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / eval_output.go
index cf61781e5b919bf3a6189912a8f923cd56b89c54..a8346276f35e2db1b8a728d529ac0fce27681aad 100644 (file)
@@ -41,15 +41,16 @@ type EvalWriteOutput struct {
        Name      string
        Sensitive bool
        Value     *config.RawConfig
+       // ContinueOnErr allows interpolation to fail during Input
+       ContinueOnErr bool
 }
 
 // TODO: test
 func (n *EvalWriteOutput) Eval(ctx EvalContext) (interface{}, error) {
+       // This has to run before we have a state lock, since interpolation also
+       // reads the state
        cfg, err := ctx.Interpolate(n.Value, nil)
-       if err != nil {
-               // Log error but continue anyway
-               log.Printf("[WARN] Output interpolation %q failed: %s", n.Name, err)
-       }
+       // handle the error after we have the module from the state
 
        state, lock := ctx.State()
        if state == nil {
@@ -59,13 +60,27 @@ func (n *EvalWriteOutput) Eval(ctx EvalContext) (interface{}, error) {
        // Get a write lock so we can access this instance
        lock.Lock()
        defer lock.Unlock()
-
        // Look for the module state. If we don't have one, create it.
        mod := state.ModuleByPath(ctx.Path())
        if mod == nil {
                mod = state.AddModule(ctx.Path())
        }
 
+       // handling the interpolation error
+       if err != nil {
+               if n.ContinueOnErr || flagWarnOutputErrors {
+                       log.Printf("[ERROR] Output interpolation %q failed: %s", n.Name, err)
+                       // if we're continuing, make sure the output is included, and
+                       // marked as unknown
+                       mod.Outputs[n.Name] = &OutputState{
+                               Type:  "string",
+                               Value: config.UnknownVariableValue,
+                       }
+                       return nil, EvalEarlyExitError{}
+               }
+               return nil, err
+       }
+
        // Get the value from the config
        var valueRaw interface{} = config.UnknownVariableValue
        if cfg != nil {