bridgecrewio / yor

Extensible auto-tagger for your IaC files. The ultimate way to link entities in the cloud back to the codified resource which created it.
https://www.yor.io
Apache License 2.0
791 stars 120 forks source link

Error if tags are calculated with a for loop #496

Closed kayman-mk closed 1 month ago

kayman-mk commented 3 months ago

Describe the bug Yor is not able to deal with statements like { for k, v in local.tags : k => v if k != "environment" } which causes problems in our pipeline. It creates wrong Terraform code:

resource "aws_security_group" "a" {
  name = "b"

  tags = { for k, v in local.tags : k => v if k != "environment"
    yor_name  = "a"
    yor_trace = "c3bec54a-a976-4886-8a03-792318011ed0"
  }
}

To Reproduce

  1. Use the following Terraform file
    
    locals {
    tags = {a: "b", c: "d"}
    }

resource "aws_security_group" "a" { name = "b"

tags = { for k, v in local.tags : k => v if k != "environment" } }


2. Run `yor tags -d .`
3. Check the file system. There is still a temporary file which shows incorrect Terraform code.

**Expected behavior**
- there should be no temp file left
- the source code should show the correct tags

**Screenshots**
none

**Desktop (please complete the following information):**
 - OS: Linux, Windows
 - Yor Version: 0.1.191

**Additional context**
None
stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.