@@ -260,48 +260,28 @@ func (e *evaluator) evaluateSteps() {
260
260
}
261
261
262
262
func (e * evaluator ) expandBlocks (blocks terraform.Blocks ) terraform.Blocks {
263
- return e .expandDynamicBlocks (e .expandBlockForEaches (e .expandBlockCounts (blocks ), false )... )
263
+ return e .expandDynamicBlocks (e .expandBlockForEaches (e .expandBlockCounts (blocks ))... )
264
264
}
265
265
266
266
func (e * evaluator ) expandDynamicBlocks (blocks ... * terraform.Block ) terraform.Blocks {
267
267
for _ , b := range blocks {
268
- e .expandDynamicBlock (b )
269
- }
270
- return blocks
271
- }
272
-
273
- func (e * evaluator ) expandDynamicBlock (b * terraform.Block ) {
274
- for _ , sub := range b .AllBlocks () {
275
- e .expandDynamicBlock (sub )
276
- }
277
- for _ , sub := range b .AllBlocks ().OfType ("dynamic" ) {
278
- if sub .IsExpanded () {
279
- continue
280
- }
281
- blockName := sub .TypeLabel ()
282
- expanded := e .expandBlockForEaches (terraform.Blocks {sub }, true )
283
- for _ , ex := range expanded {
284
- if content := ex .GetBlock ("content" ); content .IsNotNil () {
285
- _ = e .expandDynamicBlocks (content )
286
- b .InjectBlock (content , blockName )
287
- }
288
- }
289
- if len (expanded ) > 0 {
290
- sub .MarkExpanded ()
268
+ if err := b .ExpandBlock (); err != nil {
269
+ e .logger .Error (`Failed to expand dynamic block.` ,
270
+ log .String ("block" , b .FullName ()), log .Err (err ))
291
271
}
292
272
}
273
+ return blocks
293
274
}
294
275
295
276
func isBlockSupportsForEachMetaArgument (block * terraform.Block ) bool {
296
277
return slices .Contains ([]string {
297
278
"module" ,
298
279
"resource" ,
299
280
"data" ,
300
- "dynamic" ,
301
281
}, block .Type ())
302
282
}
303
283
304
- func (e * evaluator ) expandBlockForEaches (blocks terraform.Blocks , isDynamic bool ) terraform.Blocks {
284
+ func (e * evaluator ) expandBlockForEaches (blocks terraform.Blocks ) terraform.Blocks {
305
285
306
286
var forEachFiltered terraform.Blocks
307
287
@@ -348,7 +328,7 @@ func (e *evaluator) expandBlockForEaches(blocks terraform.Blocks, isDynamic bool
348
328
// is the value of the collection. The exception is the use of for-each inside a dynamic block,
349
329
// because in this case the collection element may not be a primitive value.
350
330
if (forEachVal .Type ().IsCollectionType () || forEachVal .Type ().IsTupleType ()) &&
351
- ! forEachVal .Type ().IsMapType () && ! isDynamic {
331
+ ! forEachVal .Type ().IsMapType () {
352
332
stringVal , err := convert .Convert (val , cty .String )
353
333
if err != nil {
354
334
e .logger .Error (
@@ -374,22 +354,7 @@ func (e *evaluator) expandBlockForEaches(blocks terraform.Blocks, isDynamic bool
374
354
375
355
ctx .Set (eachObj , "each" )
376
356
ctx .Set (eachObj , block .TypeLabel ())
377
-
378
- if isDynamic {
379
- if iterAttr := block .GetAttribute ("iterator" ); iterAttr .IsNotNil () {
380
- refs := iterAttr .AllReferences ()
381
- if len (refs ) == 1 {
382
- ctx .Set (idx , refs [0 ].TypeLabel (), "key" )
383
- ctx .Set (val , refs [0 ].TypeLabel (), "value" )
384
- } else {
385
- e .logger .Debug ("Ignoring iterator attribute in dynamic block, expected one reference" ,
386
- log .Int ("refs" , len (refs )))
387
- }
388
- }
389
- }
390
-
391
357
forEachFiltered = append (forEachFiltered , clone )
392
-
393
358
clones [idx .AsString ()] = clone .Values ()
394
359
})
395
360
0 commit comments