An open API service indexing awesome lists of open source software.

https://github.com/obytes/terraform-aws-tag

Terraform module to automate creation of AWS tags and Name Attribute
https://github.com/obytes/terraform-aws-tag

Last synced: 8 months ago
JSON representation

Terraform module to automate creation of AWS tags and Name Attribute

Awesome Lists containing this project

README

          

## Summary
A Terraform open-source module to automate the creation of `tags`, the `Name` key and other attributes across resources in AWS, the `Name` prefix is based on a customizable order passed by the `prefix_order` variable with a default value of `["enviroemnt", "project_name", "region", "name", "attributes"]` and a configurable `delimiter` variable with value of `-`.

## Features

The module supports the following:
- Optionally limiting the `id` variable length to a specific number of chars by modifying the `prefix_lenght_limit` variable, defaulted to 0 which means no limit.
- Optionally configure the case letter of `tag_key_case` and `tag_value_case`, defaults to `title`, `lower` respectively.
- A random string will be created using the `random` provider that will be used in case of creating a truncated id, `prefix_legnth_limit` !=0.
- Supporting a configurable `regex_substitute_chars` variable which will replace any non-alphanumeric chars passed to `enviroment`, `project_name`, `region` and, `name`, defaulted to `"/[^(a-z)(A-Z)(0-9)$]/"`.
- A validation mechanism to validate some input variables e.g. `tag_key_case`, `tag_value_case`, `region`
- Optional `attributes` which will be added automatically to `tags` variable and `id`

## Usage
### Example 1
```hcl
module "label" {
source = "github.com/obytes/terraform-aws-tag.git?ref=v1.0.7"
environment = "dev"
project_name = "obytes"
region = "me-south-1"
delimiter = "+"
attributes = ["private"]
enabled = true
prefix_length_limit = 10
}
```
The above example will generate the below output that can be passed to another `label` module to create a new `id` that has the base values used on `label_1` module

```hcl
context = {
"additional_tags" = {}
"attributes" = [
"private",
]
"delimiter" = "+"
"enabled" = "true"
"environment" = "dev"
"prefix_length_limit" = 10
"prefix_order" = [
"environment",
"project_name",
"region",
"name",
]
"project_name" = "obytes"
"region" = "me-south-1"
"tag_key_case" = "title"
"tag_value_case" = "lower"
"tags" = {}
}
id = dev+n4rnkc
tags = {
"Attributes" = "private"
"Environment" = "dev"
"Name" = "dev+n4rnkc"
"Project_name" = "obytes"
"Region" = "mesouth1"
}
```
Check the example folder for more details scenarios.

## Requirements

| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >=0.13.0 |
| [random](#requirement\_random) | 3.1.0 |

## Providers

| Name | Version |
|------|---------|
| [random](#provider\_random) | 3.1.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [random_string.this](https://registry.terraform.io/providers/hashicorp/random/3.1.0/docs/resources/string) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [additional\_tags](#input\_additional\_tags) | Additional Tags, tags which can be accessed by module..tags\_as\_list not added to .. | `map(string)` | `{}` | no |
| [attributes](#input\_attributes) | A list of attributes e.g. `private`, `shared`, `cost_center` | `list(string)` | `null` | no |
| [company\_name](#input\_company\_name) | The company name or client name, could be fullName or abbreviation such as `ex` | `string` | `null` | no |
| [context](#input\_context) | n/a | `any` |

{
"additional_tags": {},
"attributes": [],
"company_name": null,
"delimiter": null,
"enabled": true,
"environment": null,
"prefix_length_limit": 0,
"prefix_order": [
"environment",
"project_name",
"company_name",
"region",
"attributes"
],
"project_name": null,
"random_string": null,
"regex_substitute_chars": null,
"region": null,
"tag_key_case": "title",
"tag_value_case": "lower",
"tags": {}
}
| no |
| [delimiter](#input\_delimiter) | Delimiter to be used between `project_name`, `environment`, `region` and, `name`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| [enabled](#input\_enabled) | A boolean to enable or disable tagging/labeling module | `string` | `null` | no |
| [environment](#input\_environment) | Environment, the environment name such as 'stg', 'prd', 'dev' | `string` | `null` | no |
| [prefix\_length\_limit](#input\_prefix\_length\_limit) | The minimum number of chars required for the id/Name desired (minimum =7)
Set it to `0` for unlimited number of chars, `full_id` | `number` | `null` | no |
| [prefix\_order](#input\_prefix\_order) | The order of the Name tag
Defaults to, `["environment", "project_name", "region", "name"]`
at least one should be provided | `list(string)` | `null` | no |
| [project\_name](#input\_project\_name) | The project name or organization name, could be fullName or abbreviation such as `ex` | `string` | `null` | no |
| [random\_string](#input\_random\_string) | A Random string, that will be appended to `id` in case of using `prefix_length_limit`
Using the default value which is `null`, the string will be created using the `random` terraform provider | `string` | `null` | no |
| [regex\_substitute\_chars](#input\_regex\_substitute\_chars) | a regex to replace empty chars in `project_name`, `environment`, `region` and, `name`
defaults to `"\[a-zA-Z0-9]\"`, replacing any chars other than chars and digits | `string` | `null` | no |
| [region](#input\_region) | Environment name such as us-east-1, ap-west-1, eu-central-1 | `string` | `null` | no |
| [tag\_key\_case](#input\_tag\_key\_case) | The letter case of output tag keys
Possible values are `lower', `upper` and `title`
defaults to `title`
` | `string` | `null` | no |
| [tag\_value\_case](#input\_tag\_value\_case) | The letter case of output tag values
Possible values are `lower', `upper` and `title`
defaults to `lower`
` | `string` | `null` | no |
| [tags](#input\_tags) | Tags, Tags to be generated by this module which can be access by module..tags e.g. map('CostCenter', 'Production') | `map(string)` | `{}` | no |

## Outputs

| Name | Description |
|------|-------------|
| [additional\_tags](#output\_additional\_tags) | Additional Tags, tags which can be accessed by module..tags\_as\_list not added to .. |
| [attributes](#output\_attributes) | A list of attributes e.g. `private`, `shared`, `cost_center` |
| [company\_name](#output\_company\_name) | The name of the company or client |
| [context](#output\_context) | A context to be used as an input for other modules |
| [delimiter](#output\_delimiter) | Delimiter to be used between `project_name`, `environment`, `region` and, `name`. |
| [enabled](#output\_enabled) | A boolean to enable or disable tagging/labeling module |
| [environment](#output\_environment) | Environment name passed to module such as us-east-1, ap-west-1, eu-central-1 |
| [id](#output\_id) | ID, restricted to `prefix_length_limit` if set otherwise, full ID |
| [id\_full](#output\_id\_full) | Full ID, not restricted to prefix\_length\_limit |
| [prefix\_order](#output\_prefix\_order) | an ordered list of strings that forms the `ID` attribute |
| [project\_name](#output\_project\_name) | The project name or organization name, could be fullName or abbreviation such as `ex` |
| [random\_string](#output\_random\_string) | A random string, used in `id` and `id_short` in case of setting `prefix_lenght_limit` |
| [regex\_substitute\_chars](#output\_regex\_substitute\_chars) | Regex, to be used for id substitution in case of using `prefix_length_limit` |
| [tags](#output\_tags) | Tags, Tags to be generated by this module which can be access by module..tags e.g. map('CostCenter', 'Production') |