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

tag-prefix doesn't work with tags or tag-groups cli switches #492

Closed jim-weller closed 1 month ago

jim-weller commented 4 months ago

Describe the bug tag-prefix does not play well with other command line switches. I've tried quite a few combinations of switches. Prefix only seems to work in the barest of configurations.

To Reproduce main.tf

resource "aws_ssm_parameter" "environment_type" {
  name        = "environment_type"
  type        = "String"
  value       = "dev"
  description = "A basic SSM parameter that will vary between DEV and PROD aws accounts according to the tfvars files in the env/ directory."

  # tags will be injected below  here by yor
}

prefix switch breaks behavior when specifying tags

❯ yor tag -d . --tags yor_trace  --tag-prefix "test:" --dry-run
  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.189
 Yor Findings Summary
 Scanned Resources:   1
 New Resources Traced:    0
 Updated Resources:   0

prefix switch works alone

❯ yor tag -d . --tag-prefix "technical:" --dry-run
  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.189
 Yor Findings Summary
 Scanned Resources:   1
 New Resources Traced:    1
 Updated Resources:   0

New Resources Traced (1):
+---------+------------------------------------+--------------------------------+------------------------------------------+--------+
|  FILE   |              RESOURCE              |            TAG KEY             |                TAG VALUE                 | YOR ID |
+---------+------------------------------------+--------------------------------+------------------------------------------+--------+
| main.tf | aws_ssm_parameter.environment_type | technical:yor_trace            | cc810173-70aa-4c76-9493-5edd20288bec     |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:yor_name             | environment_type                         |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_repo             | enbl-demo-iac-yor-tagging                |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_org              | HylandSoftware                           |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_modifiers        | jim.weller                               |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_last_modified_by | jim.weller@hyland.com                    |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_last_modified_at | 2024-02-29 15:21:45                      |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_file             | main.tf                                  |        |
+         +                                    +--------------------------------+------------------------------------------+--------+
|         |                                    | technical:git_commit           | 4c39aa9f59024a8d618a77bba5a75f05345058e5 |        |
+---------+------------------------------------+--------------------------------+------------------------------------------+--------+

Expected behavior yor should tag files with the appropriate prefix and honor other CLI switches like tags and tag-groups.

Desktop (please complete the following information):

Additional context n/a

jim-weller commented 4 months ago

More weird combinations

works, just the tag-group for git

  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.189
 Yor Findings Summary
 Scanned Resources:   1
 New Resources Traced:    1
 Updated Resources:   0

New Resources Traced (1):
+---------+------------------------------------+---------------------------+------------------------------------------+--------+
|  FILE   |              RESOURCE              |          TAG KEY          |                TAG VALUE                 | YOR ID |
+---------+------------------------------------+---------------------------+------------------------------------------+--------+
| main.tf | aws_ssm_parameter.environment_type | TEST_git_repo             | enbl-demo-iac-yor-tagging                |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_org              | HylandSoftware                           |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_modifiers        | jim.weller                               |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_last_modified_by | jim.weller@hyland.com                    |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_last_modified_at | 2024-02-29 15:21:45                      |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_file             | main.tf                                  |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_commit           | 4c39aa9f59024a8d618a77bba5a75f05345058e5 |        |
+---------+------------------------------------+---------------------------+------------------------------------------+--------+

add code2cloud tag-group and it still works

❯ yor tag -d . --tag-prefix "TEST_" --tag-groups git,code2cloud  --dry-run
  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.189
 Yor Findings Summary
 Scanned Resources:   1
 New Resources Traced:    1
 Updated Resources:   0

New Resources Traced (1):
+---------+------------------------------------+---------------------------+------------------------------------------+--------+
|  FILE   |              RESOURCE              |          TAG KEY          |                TAG VALUE                 | YOR ID |
+---------+------------------------------------+---------------------------+------------------------------------------+--------+
| main.tf | aws_ssm_parameter.environment_type | TEST_yor_trace            | baf4cd53-f627-4f80-9511-bb467ebcc121     |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_yor_name             | environment_type                         |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_repo             | enbl-demo-iac-yor-tagging                |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_org              | HylandSoftware                           |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_modifiers        | jim.weller                               |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_last_modified_by | jim.weller@hyland.com                    |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_last_modified_at | 2024-02-29 15:21:45                      |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_file             | main.tf                                  |        |
+         +                                    +---------------------------+------------------------------------------+--------+
|         |                                    | TEST_git_commit           | 4c39aa9f59024a8d618a77bba5a75f05345058e5 |        |
+---------+------------------------------------+---------------------------+------------------------------------------+--------+

add a tag and it fails

❯ yor tag -d . --tag-prefix "TEST_" --tag-groups git --tags git_repo  --dry-run
  __    __
  \ \  / /
   \ \/ /___  _  ____
    \  /  _ \| |/  __|
    | |  |_| |   /
    |_|\____/|__|v0.1.189
 Yor Findings Summary
 Scanned Resources:   1
 New Resources Traced:    0
 Updated Resources:   0
jim-weller commented 4 months ago

It looks like tags and tag-prefix are incompatible. This doesn't work

yor tag -d . --tag-prefix "TEST_" --tags git_repo --dry-run

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.