From 776d8f15e70b4bd9551bf79d0233a5519e728d0f Mon Sep 17 00:00:00 2001 From: Bennie Mosher Date: Mon, 29 Jun 2020 11:31:00 -0600 Subject: [PATCH] initial module commit --- .pre-commit-config.yaml | 8 ++++++++ README.md | 24 ++++++++++++++++++++++++ main.tf | 11 +++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 main.tf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6444191 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: +- repo: git://github.com/antonbabenko/pre-commit-terraform + rev: v1.31.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases + hooks: + - id: terraform_fmt + - id: terraform_docs + - id: terraform_tflint + - id: terraform_tfsec diff --git a/README.md b/README.md index 70b834b..7436d22 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ # nested_maps A small Terraform module to build a nested map for for_each resource declarations + + +## Requirements + +No requirements. + +## Providers + +No provider. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| map | n/a | `any` | n/a | yes | +| replace | n/a | `any` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| map | n/a | + + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..2a6a4b3 --- /dev/null +++ b/main.tf @@ -0,0 +1,11 @@ +variable "map" {} +variable "replace" {} + +locals { + keys = flatten([for s in var.replace["string_replace"] : [for k, v in var.map : replace(k, var.replace["string_find"], s)]]) + values = flatten([for s in var.replace["string_replace"] : [for k, v in var.map : map("name", replace(v, var.replace["string_find"], s))]]) +} + +output "map" { + value = zipmap(local.keys, local.values) +}