@@ -16,6 +16,7 @@ type expandBody struct {
16
16
original hcl.Body
17
17
forEachCtx * hcl.EvalContext
18
18
iteration * iteration // non-nil if we're nested inside another "dynamic" block
19
+ valueMarks cty.ValueMarks
19
20
20
21
checkForEach []func (cty.Value , hcl.Expression , * hcl.EvalContext ) hcl.Diagnostics
21
22
@@ -125,7 +126,7 @@ func (b *expandBody) extendSchema(schema *hcl.BodySchema) *hcl.BodySchema {
125
126
}
126
127
127
128
func (b * expandBody ) prepareAttributes (rawAttrs hcl.Attributes ) hcl.Attributes {
128
- if len (b .hiddenAttrs ) == 0 && b .iteration == nil {
129
+ if len (b .hiddenAttrs ) == 0 && b .iteration == nil && len ( b . valueMarks ) == 0 {
129
130
// Easy path: just pass through the attrs from the original body verbatim
130
131
return rawAttrs
131
132
}
@@ -142,13 +143,24 @@ func (b *expandBody) prepareAttributes(rawAttrs hcl.Attributes) hcl.Attributes {
142
143
if b .iteration != nil {
143
144
attr := * rawAttr // shallow copy so we can mutate it
144
145
attr .Expr = exprWrap {
145
- Expression : attr .Expr ,
146
- i : b .iteration ,
146
+ Expression : attr .Expr ,
147
+ i : b .iteration ,
148
+ resultMarks : b .valueMarks ,
147
149
}
148
150
attrs [name ] = & attr
149
151
} else {
150
- // If we have no active iteration then no wrapping is required.
151
- attrs [name ] = rawAttr
152
+ // If we have no active iteration then no wrapping is required
153
+ // unless we have marks to apply.
154
+ if len (b .valueMarks ) != 0 {
155
+ attr := * rawAttr // shallow copy so we can mutate it
156
+ attr .Expr = exprWrap {
157
+ Expression : attr .Expr ,
158
+ resultMarks : b .valueMarks ,
159
+ }
160
+ attrs [name ] = & attr
161
+ } else {
162
+ attrs [name ] = rawAttr
163
+ }
152
164
}
153
165
}
154
166
return attrs
@@ -192,8 +204,9 @@ func (b *expandBody) expandBlocks(schema *hcl.BodySchema, rawBlocks hcl.Blocks,
192
204
continue
193
205
}
194
206
195
- if spec .forEachVal .IsKnown () {
196
- for it := spec .forEachVal .ElementIterator (); it .Next (); {
207
+ forEachVal , marks := spec .forEachVal .Unmark ()
208
+ if forEachVal .IsKnown () {
209
+ for it := forEachVal .ElementIterator (); it .Next (); {
197
210
key , value := it .Element ()
198
211
i := b .iteration .MakeChild (spec .iteratorName , key , value )
199
212
@@ -202,7 +215,7 @@ func (b *expandBody) expandBlocks(schema *hcl.BodySchema, rawBlocks hcl.Blocks,
202
215
if block != nil {
203
216
// Attach our new iteration context so that attributes
204
217
// and other nested blocks can refer to our iterator.
205
- block .Body = b .expandChild (block .Body , i )
218
+ block .Body = b .expandChild (block .Body , i , marks )
206
219
blocks = append (blocks , block )
207
220
}
208
221
}
@@ -214,7 +227,10 @@ func (b *expandBody) expandBlocks(schema *hcl.BodySchema, rawBlocks hcl.Blocks,
214
227
block , blockDiags := spec .newBlock (i , b .forEachCtx )
215
228
diags = append (diags , blockDiags ... )
216
229
if block != nil {
217
- block .Body = unknownBody {b .expandChild (block .Body , i )}
230
+ block .Body = unknownBody {
231
+ template : b .expandChild (block .Body , i , marks ),
232
+ valueMarks : marks ,
233
+ }
218
234
blocks = append (blocks , block )
219
235
}
220
236
}
@@ -226,7 +242,7 @@ func (b *expandBody) expandBlocks(schema *hcl.BodySchema, rawBlocks hcl.Blocks,
226
242
// case it contains expressions that refer to our inherited
227
243
// iterators, or nested "dynamic" blocks.
228
244
expandedBlock := * rawBlock // shallow copy
229
- expandedBlock .Body = b .expandChild (rawBlock .Body , b .iteration )
245
+ expandedBlock .Body = b .expandChild (rawBlock .Body , b .iteration , nil )
230
246
blocks = append (blocks , & expandedBlock )
231
247
}
232
248
}
@@ -235,11 +251,12 @@ func (b *expandBody) expandBlocks(schema *hcl.BodySchema, rawBlocks hcl.Blocks,
235
251
return blocks , diags
236
252
}
237
253
238
- func (b * expandBody ) expandChild (child hcl.Body , i * iteration ) hcl.Body {
254
+ func (b * expandBody ) expandChild (child hcl.Body , i * iteration , valueMarks cty. ValueMarks ) hcl.Body {
239
255
chiCtx := i .EvalContext (b .forEachCtx )
240
256
ret := Expand (child , chiCtx )
241
257
ret .(* expandBody ).iteration = i
242
258
ret .(* expandBody ).checkForEach = b .checkForEach
259
+ ret .(* expandBody ).valueMarks = valueMarks
243
260
return ret
244
261
}
245
262
0 commit comments