diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 04197b97d..0ad2f3148 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -8069,3 +8069,33 @@ func TestContext2Apply_dataDependsOn(t *testing.T) { t.Fatalf("bad:\n%s", strings.TrimSpace(state.String())) } } + +func TestContext2Apply_terraformEnv(t *testing.T) { + m := testModule(t, "apply-terraform-env") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + + ctx := testContext2(t, &ContextOpts{ + Meta: &ContextMeta{Env: "foo"}, + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := state.RootModule().Outputs["output"] + expected := "foo" + if actual == nil || actual.Value != expected { + t.Fatalf("bad: \n%s", actual) + } +} diff --git a/terraform/graph_walk_context.go b/terraform/graph_walk_context.go index 19fd47ceb..e63b46035 100644 --- a/terraform/graph_walk_context.go +++ b/terraform/graph_walk_context.go @@ -84,6 +84,7 @@ func (w *ContextGraphWalker) EnterPath(path []string) EvalContext { StateLock: &w.Context.stateLock, Interpolater: &Interpolater{ Operation: w.Operation, + Meta: w.Context.meta, Module: w.Context.module, State: w.Context.state, StateLock: &w.Context.stateLock, diff --git a/terraform/shadow_context.go b/terraform/shadow_context.go index 5f7914328..5588af252 100644 --- a/terraform/shadow_context.go +++ b/terraform/shadow_context.go @@ -46,6 +46,7 @@ func newShadowContext(c *Context) (*Context, *Context, Shadow) { destroy: c.destroy, diff: c.diff.DeepCopy(), hooks: nil, + meta: c.meta, module: c.module, state: c.state.DeepCopy(), targets: targetRaw.([]string), @@ -77,6 +78,7 @@ func newShadowContext(c *Context) (*Context, *Context, Shadow) { diff: c.diff, // diffLock - no copy hooks: c.hooks, + meta: c.meta, module: c.module, sh: c.sh, state: c.state, diff --git a/terraform/test-fixtures/apply-terraform-env/main.tf b/terraform/test-fixtures/apply-terraform-env/main.tf new file mode 100644 index 000000000..a5ab88617 --- /dev/null +++ b/terraform/test-fixtures/apply-terraform-env/main.tf @@ -0,0 +1,3 @@ +output "output" { + value = "${terraform.env}" +}