Skip to content

Cloud agnostic Terraform module to manage tags with null resources. This module is used to standardize tags across all resources in a Terraform project. Terraform Registry: https://registry.terraform.io/modules/CloudAtScale/tags/null/latest

Notifications You must be signed in to change notification settings

CloudAtScale/terraform-null-tags

Repository files navigation

terraform-module-tags

This module is used to create tags for different resources that are supported by tags.

Goals

  • Create a well-versioned tagging schema.
  • Create tags for different resources that are supported by tags.
  • Define a tagging schema that is easy to understand and maintain.
  • Create a tagging schema that is easy to implement in different cloud providers.
  • Ability to understand resources created with their origin.

Why?

  • Tags are used to identify resources in the cloud.
  • Ability to create inventory reports accross multiple cloud providers and others resources that support tags
  • Ability to identify the version of the tagging schema used to create the resources and create automation around it.

Usage examples

Github

Terraform files

main.tf

module "tags" {
  source  = "CloudAtScale/tags/null"
  version = "x.x.x"

  git_project_url = var.git_project_url
  team            = "MyAwesomeTeam"
  environment     = "MyAwesomeEnvironment"
  project_name    = "MyAwesomeProject"
  extra_tags      = {
      "extra_tag_1" = "extra_tag_1_value"
      "extra_tag_2" = "extra_tag_2_value"
  }
}

variables.tf

variable "git_project_url" {
  type        = string
  description = "The URL of the git project"
}

For Github Actions, use:

    env:
      TF_VAR_git_project_url: ${{ github.repository }}

Gitlab

Terraform files

main.tf

module "tags" {
  source  = "CloudAtScale/tags/null"
  version = "x.x.x"

  vcs_provider = "gitlab"

  git_project_url   = var.git_project_url
  gitlab_project_id = var.gitlab_project_id
  team              = "MyAwesomeTeam"
  environment       = "MyAwesomeEnvironment"
  project_name      = "MyAwesomeProject"

  extra_tags = {
      "extra_tag_1" = "extra_tag_1_value"
      "extra_tag_2" = "extra_tag_2_value"
  }
}

variables.tf

variable "git_project_url" {
  type        = string
  description = "The URL of the git project"
}

variable "gitlab_project_id" {
  type        = string
  description = "The ID of the gitlab project"
}

For Gitlab CI, use:

    variables:
      TF_VAR_git_project_url: $CI_PROJECT_URL
      TF_VAR_gitlab_project_id : $CI_PROJECT_ID

How to use this module

This module is used to create tags for different resources that are supported by tags.

On AWS provider

provider "aws" {
  region = "us-west-2"
  default_tags {
    tags = module.tags.all_tags
  }
}

Note: Most AWS resources support 50 tags per resource but some resources support only 10 tags per resource like AWS S3 Object. Please refer to the AWS documentation for more information.

Outputs

All tags are returned in a map:

{
    "ProjectName": "MyAwesomeProject",
    "Onwer:Team": "MyAwesomeTeam",
    "Environment": "MyAwesomeEnvironment",
    "extra_tag_1": "extra_tag_1_value",
    "extra_tag_2": "extra_tag_2_value",
    "Compliance:TaggingSchemaVersion": "1.0.0"
}

Terraform Docs

Requirements

Name Version
terraform >= 0.12.0

Inputs

Name Description Type Default Required
environment Environment name string n/a yes
git_project_url Git project url string n/a yes
project_name Project name string n/a yes
team Team name string n/a yes
delimiter Delimiter to be used between Prefix and key. string ":" no
extra_tags Extra tags map(string) {} no
gitlab_project_id Gitlab project id number null no
vcs_provider VCS provider string "github" no

Outputs

Name Description
all_tags Tags
environment Environment
extra_tags Extra Tags
git_project_url Git Project URL
gitlab_project_id Gitlab Project ID
project_name Project Name
team Team
vcs_provider VCS Provider

Disclaimer

This module is most for example to show how to create tags for different resources that are supported by tags with a well-versioned tagging schema.

About

Cloud agnostic Terraform module to manage tags with null resources. This module is used to standardize tags across all resources in a Terraform project. Terraform Registry: https://registry.terraform.io/modules/CloudAtScale/tags/null/latest

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages