From 068b2b2deceee2f2aa8718981f15716431d34837 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 31 Jan 2017 11:50:37 -0800 Subject: [PATCH] terraform: add Meta field to diffs This adds a Meta field (similar to InstanceState.Meta) to InstanceDiff. This allows providers to store arbitrary k/v data as part of a diff and have it persist through to the Apply. This will be used by helper/schema for timeout storage being done by @catsby. The type here is `map[string]interface{}`. A couple notes: * **Not using `string`**: The Meta field of InstanceState is a string value. We've learned that forcing things to strings is bad. Let's just allow types. * **Primitives only**: Even though it is type `interface{}`, it must be able to cleanly pass the go-plugin RPC barrier as well as be encoded to a file as Gob. Given these constraints, the value must only comprise of primitive types and collections. No structs, functions, channels, etc. --- terraform/diff.go | 6 ++++++ terraform/plan_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/terraform/diff.go b/terraform/diff.go index c50d3cedb3..d50ec5b10a 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -364,6 +364,12 @@ type InstanceDiff struct { Destroy bool DestroyDeposed bool DestroyTainted bool + + // Meta is a simple K/V map that is stored in a diff and persisted to + // plans but otherwise is completely ignored by Terraform core. It is + // mean to be used for additional data a resource may want to pass through. + // The value here must only contain Go primitives and collections. + Meta map[string]interface{} } func (d *InstanceDiff) Lock() { d.mu.Lock() } diff --git a/terraform/plan_test.go b/terraform/plan_test.go index 02331558a9..9515efbaaa 100644 --- a/terraform/plan_test.go +++ b/terraform/plan_test.go @@ -31,6 +31,10 @@ func TestReadWritePlan(t *testing.T) { RequiresNew: true, }, }, + + Meta: map[string]interface{}{ + "foo": []interface{}{1, 2, 3}, + }, }, }, },