Merge pull request #256 from lonegunmanb/tracing-tag

Add tracing tags toggle variable
This commit is contained in:
JT 2023-05-08 10:56:26 +08:00 коммит произвёл GitHub
Родитель 62b9d10d79 150c12d7c4
Коммит b6f2b92d64
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 78 добавлений и 8 удалений

Просмотреть файл

@ -193,35 +193,35 @@ rule "terraform_workspace_remote" {
}
rule "terraform_locals_order" {
enabled = true
enabled = false
}
rule "terraform_output_order" {
enabled = true
enabled = false
}
rule "terraform_output_separate" {
enabled = true
enabled = false
}
rule "terraform_variable_nullable_false" {
enabled = true
enabled = false
}
rule "terraform_variable_order" {
enabled = true
enabled = false
}
rule "terraform_variable_separate" {
enabled = true
enabled = false
}
rule "terraform_resource_data_arg_layout" {
enabled = true
enabled = false
}
rule "azurerm_arg_order" {
enabled = true
enabled = false
}
rule "azurerm_resource_tag" {

Просмотреть файл

@ -308,6 +308,60 @@ output "windows_vm_private_ips" {
```
## Enable or disable tracing tags
We're using [BridgeCrew Yor](https://github.com/bridgecrewio/yor) and [yorbox](https://github.com/lonegunmanb/yorbox) to help manage tags consistently across infrastructure as code (IaC) frameworks. In this module you might see tags like:
```hcl
resource "azurerm_resource_group" "rg" {
location = "eastus"
name = random_pet.name
tags = merge(var.tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "3077cc6d0b70e29b6e106b3ab98cee6740c916f6"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-05-05 08:57:54"
avm_git_org = "lonegunmanb"
avm_git_repo = "terraform-yor-tag-test-module"
avm_yor_trace = "a0425718-c57d-401c-a7d5-f3d88b2551a4"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
}
```
To enable tracing tags, set the variable to true:
```hcl
module "example" {
source = "{module_source}"
...
tracing_tags_enabled = true
}
```
The `tracing_tags_enabled` is default to `false`.
To customize the prefix for your tracing tags, set the `tracing_tags_prefix` variable value in your Terraform configuration:
```hcl
module "example" {
source = "{module_source}"
...
tracing_tags_prefix = "custom_prefix_"
}
```
The actual applied tags would be:
```text
{
custom_prefix_git_commit = "3077cc6d0b70e29b6e106b3ab98cee6740c916f6"
custom_prefix_git_file = "main.tf"
custom_prefix_git_last_modified_at = "2023-05-05 08:57:54"
custom_prefix_git_org = "lonegunmanb"
custom_prefix_git_repo = "terraform-yor-tag-test-module"
custom_prefix_yor_trace = "a0425718-c57d-401c-a7d5-f3d88b2551a4"
}
```
## Pre-Commit & Pr-Check & Test
### Configurations

Просмотреть файл

@ -456,3 +456,19 @@ variable "zone" {
type = string
default = null
}
# tflint-ignore: terraform_unused_declarations
variable "tracing_tags_enabled" {
type = bool
description = "Whether enable tracing tags that generated by BridgeCrew Yor."
default = false
nullable = false
}
# tflint-ignore: terraform_unused_declarations
variable "tracing_tags_prefix" {
type = string
description = "Default prefix for generated tracing tags"
default = "avm_"
nullable = false
}