From 318bbfebb5e1eeea09765b1edb1aec303f75a268 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 8 May 2024 17:55:39 -0700 Subject: hcldec: Allow body-derived values to be marked Similar to the previously-added UnknownBody, the new optional interface MarkedBody allows hcl.Body implementations to suggest a set of marks that ought to be applied to any value that's generated to represent the content of that body. The dynblock extension then uses this to get hcldec to mark the whole object representing any block that was generated by a dynamic block whose for_each was marked, for a better representation of the fact that a block's existence was decided based on a marked value. --- ext/dynblock/expand_body.go | 5 +++++ ext/dynblock/expand_body_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/dynblock/expand_body.go b/ext/dynblock/expand_body.go index e630f18..2cafae5 100644 --- a/ext/dynblock/expand_body.go +++ b/ext/dynblock/expand_body.go @@ -270,3 +270,8 @@ func (b *expandBody) JustAttributes() (hcl.Attributes, hcl.Diagnostics) { func (b *expandBody) MissingItemRange() hcl.Range { return b.original.MissingItemRange() } + +// hcldec.MarkedBody impl +func (b *expandBody) BodyValueMarks() cty.ValueMarks { + return b.valueMarks +} diff --git a/ext/dynblock/expand_body_test.go b/ext/dynblock/expand_body_test.go index 3b245ee..0941f29 100644 --- a/ext/dynblock/expand_body_test.go +++ b/ext/dynblock/expand_body_test.go @@ -762,7 +762,7 @@ func TestExpandMarkedForEach(t *testing.T) { cty.ObjectVal(map[string]cty.Value{ "val0": cty.StringVal("static c 1").Mark("boop"), "val1": cty.StringVal("hey").Mark("boop"), - }), + }).Mark("boop"), }) got, diags := hcldec.Decode(dynBody, decSpec, nil) if diags.HasErrors() { -- cgit v1.2.3