From 15fefccf75e93db1345e7a37344597f06a832060 Mon Sep 17 00:00:00 2001 From: zjhe Date: Fri, 5 May 2023 17:17:34 +0800 Subject: [PATCH 1/4] add toggle variables that trigger yorbox --- variables.tf | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index a45f5d2..d3f75d4 100644 --- a/variables.tf +++ b/variables.tf @@ -107,4 +107,18 @@ variable "vnet_name" { description = "Name of the vnet to create" type = string default = "acctvnet" -} \ No newline at end of file +} + +# tflint-ignore: terraform_unused_declarations +variable "tracing_tags_enabled" { + type = string + description = "Whether enable tracing tags that generated by BridgeCrew Yor." + default = false +} + +# tflint-ignore: terraform_unused_declarations +variable "tracing_tags_prefix" { + type = string + description = "Default prefix for generated tracing tags" + default = "avm_" +} From 83ccf3bde32bef570fdcdd2eacdd687b4791d48c Mon Sep 17 00:00:00 2001 From: zjhe Date: Fri, 5 May 2023 17:30:55 +0800 Subject: [PATCH 2/4] update tflint_alt.hcl to meet the new autofix tool --- .tflint_alt.hcl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.tflint_alt.hcl b/.tflint_alt.hcl index f14b4ff..c60c873 100644 --- a/.tflint_alt.hcl +++ b/.tflint_alt.hcl @@ -6,7 +6,7 @@ SET THIS FILE'S PATH TO $TFLINT_CONFIG ENVVIRONMENT VARIABLE. plugin "azurerm" { enabled = true - version = "0.20.0" + version = "0.21.0" source = "github.com/terraform-linters/tflint-ruleset-azurerm" } @@ -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" { From 65713eb30014831bc03aa7fe6805577f787127df Mon Sep 17 00:00:00 2001 From: hezijie Date: Sat, 6 May 2023 13:23:29 +0800 Subject: [PATCH 3/4] update readme --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/README.md b/README.md index 38628ef..b3d6cc9 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,60 @@ Now Terraform core's version is v1.x and terraform-provider-azurerm's version is Please refer to the sub folders under `examples` folder. You can execute `terraform apply` command in `examples`'s sub folder to try the module. These examples are tested against every PR with the [E2E Test](#Pre-Commit--Pr-Check--Test). +## 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, (/**/ (var.tracing_tags_enabled ? { for k, v in /**/ { + 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" + } /**/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /**/)) +} +``` + +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 From 0c8e9446cee3b3263934469b3c1dcb8c16faad70 Mon Sep 17 00:00:00 2001 From: lonegunmanb Date: Mon, 8 May 2023 00:43:39 +0000 Subject: [PATCH 4/4] correct variable type, set nullable to false --- variables.tf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index d3f75d4..6b90828 100644 --- a/variables.tf +++ b/variables.tf @@ -111,9 +111,10 @@ variable "vnet_name" { # tflint-ignore: terraform_unused_declarations variable "tracing_tags_enabled" { - type = string + type = bool description = "Whether enable tracing tags that generated by BridgeCrew Yor." default = false + nullable = false } # tflint-ignore: terraform_unused_declarations @@ -121,4 +122,5 @@ variable "tracing_tags_prefix" { type = string description = "Default prefix for generated tracing tags" default = "avm_" + nullable = false }