From b2f87800ce8453162024548b4fcfa42ee9a6ce0f Mon Sep 17 00:00:00 2001 From: Kamlesh Date: Mon, 12 Aug 2019 20:51:13 +0530 Subject: [PATCH] terraform 0.11.0 --- LICENSE | 21 +++++++++++++++++++++ README.md | 28 ++++++++++++++++++++++++++++ examples/example.tf | 6 ++++++ main.tf | 29 +++++++++++++++++++++++++++++ outputs.tf | 29 +++++++++++++++++++++++++++++ variables.tf | 44 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100755 LICENSE create mode 100755 README.md create mode 100755 examples/example.tf create mode 100755 main.tf create mode 100755 outputs.tf create mode 100755 variables.tf diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..39c4e25 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Anmol Nagpal + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..3780a9f --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|:----:|:-----:|:-----:| +| attributes | Additional attributes, e.g. `1` | list | `` | no | +| delimiter | Delimiter to be used between `organization`, `name`, `environment` and `attributes` | string | `-` | no | +| enabled | Set to false to prevent the module from creating any resources | string | `true` | no | +| name | Solution name, e.g. `app` | string | - | yes | +| organization | organization, which could be your organization name, e.g. `cp` or `anmolnagpal` | string | - | yes | +| environment | environment, e.g. `prod`, `staging`, `dev`, or `test` | string | - | yes | +| tags | Additional tags (e.g. `map(`BusinessUnit`,`XYZ`) | map | `` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| attributes | Normalized attributes | +| id | Disambiguated ID | +| name | Normalized name | +| organization | Normalized organization | +| environment | Normalized environment | +| tags | Normalized Tag map | + +## 👬 Contribution +- Open pull request with improvements +- Discuss ideas in issues + +- Reach out with any feedback [![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/anmol_nagpal.svg?style=social&label=Follow%20%40anmol_nagpal)](https://twitter.com/anmol_nagpal) diff --git a/examples/example.tf b/examples/example.tf new file mode 100755 index 0000000..cae978d --- /dev/null +++ b/examples/example.tf @@ -0,0 +1,6 @@ +module "label" { + source = "../" + name = "label" + application = "clouddrove" + environment = "test" +} diff --git a/main.tf b/main.tf new file mode 100755 index 0000000..209634d --- /dev/null +++ b/main.tf @@ -0,0 +1,29 @@ +## Managed By : CloudDrove +## Copyright @ CloudDrove. All Right Reserved. + +#Module : locals +#Description : Terraform module to create consistent naming for multiple names. +locals { + enabled = "${var.enabled == "true" ? true : false }" + id = "${local.enabled == true ? lower(join(var.delimiter, compact(concat(list(var.environment, var.name), var.attributes)))) : ""}" + name = "${local.enabled == true ? lower(format("%v", var.name)) : ""}" + application = "${local.enabled == true ? lower(format("%v", var.application)) : ""}" + environment = "${local.enabled == true ? lower(format("%v", var.environment)) : ""}" + createdby = "${local.enabled == true ? lower(format("%v", var.createdby)) : ""}" + managedby = "${local.enabled == true ? lower(format("%v", var.managedby)) : ""}" + attributes = "${local.enabled == true ? lower(format("%v", join(var.delimiter, compact(var.attributes)))) : ""}" + + # Merge input tags with our tags. + # Note: `Name` has a special meaning in AWS and we need to disamgiuate it by using the computed `id` + tags = "${ + merge( + map( + "Name", "${local.id}", + "Applicatoin", "${local.application}", + "Environment", "${local.environment}", + "CreatedBy", "${local.createdby}", + "ManagedBy", "${local.managedby}" + ), var.tags + ) + }" +} diff --git a/outputs.tf b/outputs.tf new file mode 100755 index 0000000..bc24242 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,29 @@ +output "id" { + value = "${local.id}" + description = "Disambiguated ID" +} + +output "name" { + value = "${local.name}" + description = "Normalized name" +} + +output "application" { + value = "${local.application}" + description = "Normalized namespace" +} + +output "environment" { + value = "${local.environment}" + description = "Normalized stage" +} + +output "attributes" { + value = "${local.attributes}" + description = "Normalized attributes" +} + +output "tags" { + value = "${local.tags}" + description = "Normalized Tag map" +} diff --git a/variables.tf b/variables.tf new file mode 100755 index 0000000..18742c9 --- /dev/null +++ b/variables.tf @@ -0,0 +1,44 @@ +variable "name" { + description = "Solution name, e.g. `app`" +} + +variable "application" { + description = "Application name, e.g. `dw` or `CloudDrove`" +} + +variable "environment" { + description = "Environment, e.g. `prod`, `staging`, `dev`, or `test`" +} + +variable "createdby" { + description = "CreatedBy, eg 'terraform'" + default = "terraform" +} + +variable "managedby" { + description = "ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'" + default = "anmol@clouddrove.com" +} + +variable "enabled" { + description = "Set to false to prevent the module from creating any resources" + default = "true" +} + +variable "delimiter" { + type = "string" + default = "-" + description = "Delimiter to be used between `organization`, `name`, `environment` and `attributes`" +} + +variable "attributes" { + type = "list" + default = [] + description = "Additional attributes, e.g. `1`" +} + +variable "tags" { + type = "map" + default = {} + description = "Additional tags (e.g. `map(`BusinessUnit`,`XYZ`)" +}