Tags
for AWS Resources or Labels
for Kubernetes objects allows Users to add metadta to Resource/Objects. Each tag is simple key-value pair which makes it easier to manage, search for, and filter resources.
This module defines base tags
we here at Peak assign to each of our resources and are just a base Idea. You might want change that as per your organisation's needs. In that case feel free to fork this repo and define base tags that fits your organisation needs.
All tags and their values are converted to lower case to avoid confusions and duplications
stage
: Stagging environment the resource belogs to. Must be one of [latest, test, beta, prod]
tenant
: Tenant the resource belongs to. Defaults to platform
feature
: Feature this resource belogs to say shopping-cart
service
: Service this resource belogs to say shopiing-cart-database
No requirements.
No provider.
Name | Description | Type | Default | Required |
---|---|---|---|---|
feature | n/a | string |
n/a | yes |
service | n/a | string |
n/a | yes |
stage | Stage on which infra should be deployed | string |
n/a | yes |
tenant | n/a | string |
"platform" |
no |
Name | Description |
---|---|
default | Tags object |
string | Tags as string |
Once initialised tags added to as many resources as you want.
# Importing module
module "tags" {
source = "git::https://github.com/peak-ai/terraform-modules.git//tags"
# Passing values from here will overide the default values
tenant = "new-client"
# It is good practice to make workspaces matching four staging environment rather than hardcoing them
stage = terraform.workspace
# hardcoing example
# stage = "latest"
feature = "example"
service = "example"
}
# Using module to to add tags to a resource say a S3 bucket
provider "aws" {
version = "~> 2.62"
}
resource "aws_s3_bucket" "example" {
bucket = "example"
tags = module.tags.default
}
module "tags" {
source = "git::https://github.com/peak-ai/terraform-modules.git//tags?ref=v0.1.0"
tenant = "new-client"
stage = "latest"
feature = "example"
service = "example"
}
provider "aws" {
version = "~> 2.62"
}
resource "aws_s3_bucket" "example" {
bucket = "example"
tags = module.tags.default
}
You can assign tags to any kubernetes object as well
module "tags" {
source = "git::https://github.com/peak-ai/terraform-modules.git//tags?ref=v0.5.0"
tenant = "new-client"
stage = "latest"
feature = "example"
service = "example"
}
provider "kubernetes" {
version = "~> 1.11"
}
resource "kubernetes_namespace" "example" {
metadata {
labels = module.tags.default
name = "example"
}
}