@@ -261,14 +261,14 @@ func extractTagsLabelsDynamicBlock(resourceb *hclwrite.Body, name string) (hclwr
261261 }
262262 collectionExpr := strings .TrimSpace (string (d .forEach .Expr ().BuildTokens (nil ).Bytes ()))
263263 keyExpr := strings .TrimSpace (strings .ReplaceAll (string (key .Expr ().BuildTokens (nil ).Bytes ()),
264- fmt .Sprintf ("%s.%s" , name , nKey ), nKey ))
264+ fmt .Sprintf ("%s.%s" , name , nKey ), nKey )) // e.g. occurrences of tags.key are changed to key to be valid in the for expression
265265 valueExpr := strings .TrimSpace (strings .ReplaceAll (string (value .Expr ().BuildTokens (nil ).Bytes ()),
266266 fmt .Sprintf ("%s.%s" , name , nValue ), nValue ))
267267 forExpr := strings .TrimSpace (fmt .Sprintf ("for key, value in %s : %s => %s" ,
268268 collectionExpr , keyExpr , valueExpr ))
269269 tokenDynamic := hcl .TokensObjectFromExpr (forExpr )
270270 if keyExpr == nKey && valueExpr == nValue { // expression can be simplified and use for_each expression
271- tokenDynamic = hcl .TokensFromString (collectionExpr )
271+ tokenDynamic = hcl .TokensFromExpr (collectionExpr )
272272 }
273273 resourceb .RemoveBlock (d .block )
274274 return tokenDynamic , nil
@@ -474,11 +474,7 @@ func getDynamicBlock(body *hclwrite.Body, name string) (dynamicBlock, error) {
474474 if content == nil {
475475 return dynamicBlock {}, fmt .Errorf ("dynamic block %s: block %s not found" , name , nContent )
476476 }
477- return dynamicBlock {
478- forEach : forEach ,
479- block : block ,
480- content : content ,
481- }, nil
477+ return dynamicBlock {forEach : forEach , block : block , content : content }, nil
482478 }
483479 return dynamicBlock {}, nil
484480}
0 commit comments