From 2ed77c8a6f6d1ea2b17567451c76318a4de04914 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 11 Jul 2014 12:00:41 -0700 Subject: [PATCH] terraform: remove output diffs attributes from the Apply call --- terraform/context.go | 7 ++++++ terraform/context_test.go | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/terraform/context.go b/terraform/context.go index 2575155c0..30c8beac5 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -453,6 +453,13 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc { // TODO(mitchellh): we need to verify the diff doesn't change // anything and that the diff has no computed values (pre-computed) + // Remove any output values from the diff + for k, ad := range diff.Attributes { + if ad.Type == DiffAttrOutput { + delete(diff.Attributes, k) + } + } + for _, h := range c.hooks { handleHook(h.PreApply(r.Id, r.State, diff)) } diff --git a/terraform/context_test.go b/terraform/context_test.go index c785ce39c..8051ac4b2 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -433,6 +433,58 @@ func TestContextApply_Provisioner_compute(t *testing.T) { } } +func TestContextApply_outputDiffVars(t *testing.T) { + c := testConfig(t, "apply-good") + p := testProvider("aws") + s := &State{ + Resources: map[string]*ResourceState{ + "aws_instance.baz": &ResourceState{ + ID: "bar", + Type: "aws_instance", + }, + }, + } + ctx := testContext(t, &ContextOpts{ + Config: c, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: s, + }) + + p.ApplyFn = func(s *ResourceState, d *ResourceDiff) (*ResourceState, error) { + for k, ad := range d.Attributes { + if ad.NewComputed { + return nil, fmt.Errorf("%s: computed", k) + } + } + + result := s.MergeDiff(d) + result.ID = "foo" + return result, nil + } + p.DiffFn = func(*ResourceState, *ResourceConfig) (*ResourceDiff, error) { + return &ResourceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + NewComputed: true, + Type: DiffAttrOutput, + }, + "bar": &ResourceAttrDiff{ + New: "baz", + }, + }, + }, nil + } + + if _, err := ctx.Plan(nil); err != nil { + t.Fatalf("err: %s", err) + } + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } +} + func TestContextApply_destroy(t *testing.T) { c := testConfig(t, "apply-destroy") h := new(HookRecordApplyOrder)