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.
This commit is contained in:
Mitchell Hashimoto 2017-01-31 11:50:37 -08:00
parent 5dc3fb4776
commit 068b2b2dec
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 10 additions and 0 deletions

View File

@ -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() }

View File

@ -31,6 +31,10 @@ func TestReadWritePlan(t *testing.T) {
RequiresNew: true,
},
},
Meta: map[string]interface{}{
"foo": []interface{}{1, 2, 3},
},
},
},
},