Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #119 from lonegunmanb/yortag
Browse files Browse the repository at this point in the history
Add toggle variables that trigger yorbox
  • Loading branch information
jiaweitao001 authored May 8, 2023
2 parents b135b99 + 0c8e944 commit 7c10faa
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
18 changes: 9 additions & 9 deletions .tflint_alt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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" {
Expand Down
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, (/*<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
Expand Down
18 changes: 17 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,20 @@ variable "vnet_name" {
description = "Name of the vnet to create"
type = string
default = "acctvnet"
}
}

# 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
}

0 comments on commit 7c10faa

Please sign in to comment.