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
795 stars 121 forks source link

Only "yor" tag group added when "tags" value is specified for a resource #475

Closed rstml closed 1 month ago

rstml commented 5 months ago

Describe the bug

If tags field of a resource has a value that has been specified using a map {} or merge function, then yor adds only yor_* tag group but not git_*.

To Reproduce Steps to reproduce the behaviour:

Here's example.tf:

resource "aws_athena_workgroup" "analytics" {
  name = "analytics"

  # no tags

  configuration {
    enforce_workgroup_configuration = true
  }
}

resource "aws_athena_workgroup" "processing" {
  name = "processing"

  tags = merge(module.mylabel.tags, {
    Group = "DataEngineering"
  })

  configuration {
    enforce_workgroup_configuration = false
  }
}

Result

% yor tag -d . -skip-tags yor_name --dry-run
  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.188
 Yor Findings Summary
 Scanned Resources:       5
 New Resources Traced:    2
 Updated Resources:       0

New Resources Traced (2):
+----------------------------+------------------------------------+----------------------+------------------------------------------+--------------------------------------+
|            FILE            |              RESOURCE              |       TAG KEY        |                TAG VALUE                 |                YOR ID                |
+----------------------------+------------------------------------+----------------------+------------------------------------------+--------------------------------------+
| example.tf                 | aws_athena_workgroup.analytics     | yor_trace            | 71fa19ce-e2d0-4a39-b178-dcf7f056dd0a     | 71fa19ce-e2d0-4a39-b178-dcf7f056dd0a |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_repo             | aws-data-example                         |                                      |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_org              | rstml                                    |                                      |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_modifiers        | rstml                                    |                                      |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_last_modified_at | 2024-01-31 18:30:02                      |                                      |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_file             | example.tf                               |                                      |
+                            +                                    +----------------------+------------------------------------------+                                      +
|                            |                                    | git_commit           | 139c180d9955xxxxxxxxxxxxxxxxxx973b702472 |                                      |
+                            +------------------------------------+----------------------+------------------------------------------+--------------------------------------+
|                            | aws_athena_workgroup.processing    | yor_trace            | 96d7b44d-7fc0-4171-a1f7-61a49fc7b5cc     | 96d7b44d-7fc0-4171-a1f7-61a49fc7b5cc |
+----------------------------+------------------------------------+----------------------+------------------------------------------+--------------------------------------+
...

Expected behavior aws_athena_workgroup.processing resource should get git_* tags, similarly how it has got yor_* tags.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context

The behaviour doesn't change even if I specify tags without merge function, i.e. this will still exclude git_* tags:

resource "aws_athena_workgroup" "processing" {
  name = "processing"

  tags = {
    Group = "DataEngineering"
  }

  configuration {
    enforce_workgroup_configuration = false
  }
}
jim-weller commented 4 months ago

Ha! I just came to report this! Couple edge cases to add.

works

# tags from yor go here

works

  # tags from yor go here
  tags = {
  }

NOT work

  # tags from yor go here
  tags = {

  }

NOT work

  # tags from yor go here
  tags = {
    SomeTag = "SomeValue"
  }
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.