From 5f738a38ddce35411b30be236948b854996bd23a Mon Sep 17 00:00:00 2001 From: Andriy Zahornyak Date: Thu, 1 Jun 2023 17:18:24 +0300 Subject: [PATCH] add prefix --- README.md | 7 +++++++ examples/parse-env-file/main.tf | 2 ++ examples/simple/main.tf | 2 ++ main.tf | 4 ++-- variables.tf | 6 ++++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6efb615..241587c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ Especially useful with Terragrunt. module "parameters" { source = "zahornyak/multiple-ssm-parameters/aws" + # prefix for parameter name + parameter_prefix = "/dev/" + parameters = { db_name = { name = "foo" @@ -31,6 +34,9 @@ module "parameters" { module "parameters" { source = "zahornyak/multiple-ssm-parameters/aws" + # prefix for parameter name + parameter_prefix = "/dev/" + file_path = ".env" } @@ -93,6 +99,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [file\_path](#input\_file\_path) | file to parse | `string` | `null` | no | +| [parameter\_prefix](#input\_parameter\_prefix) | prefix for parameter names. For example you wanna split dev/prod parameters so you wanna add /service\_name/development/ prefix before parameter name | `string` | `null` | no | | [parameters](#input\_parameters) | map of parameters for parameter store | `any` | `{}` | no | | [tags](#input\_tags) | Specifies a tags | `any` | `{}` | no | diff --git a/examples/parse-env-file/main.tf b/examples/parse-env-file/main.tf index 41785f5..76dcbc0 100644 --- a/examples/parse-env-file/main.tf +++ b/examples/parse-env-file/main.tf @@ -1,6 +1,8 @@ module "parse_files" { source = "../.." + parameter_prefix = "/dev/" + file_path = ".env" } diff --git a/examples/simple/main.tf b/examples/simple/main.tf index d330dc8..179093a 100644 --- a/examples/simple/main.tf +++ b/examples/simple/main.tf @@ -1,6 +1,8 @@ module "parameters" { source = "../.." + parameter_prefix = "/dev/" + parameters = { db_name = { name = "foo" diff --git a/main.tf b/main.tf index 541352c..38a00fd 100644 --- a/main.tf +++ b/main.tf @@ -1,7 +1,7 @@ resource "aws_ssm_parameter" "this" { for_each = var.parameters - name = lookup(each.value, "name", null) == null ? each.key : lookup(each.value, "name") + name = var.parameter_prefix != null ? "${var.parameter_prefix}${lookup(each.value, "name", null) == null ? each.key : lookup(each.value, "name")}" : lookup(each.value, "name", null) == null ? each.key : lookup(each.value, "name") type = lookup(each.value, "type", "SecureString") value = lookup(each.value, "value", null) description = lookup(each.value, "description", null) @@ -30,7 +30,7 @@ locals { resource "aws_ssm_parameter" "parsed" { for_each = local.parsed_data - name = each.key + name = var.parameter_prefix != null ? "${var.parameter_prefix}${each.key}" : each.key type = "SecureString" value = each.value # description = null diff --git a/variables.tf b/variables.tf index d1a95c0..c1b4634 100644 --- a/variables.tf +++ b/variables.tf @@ -15,3 +15,9 @@ variable "file_path" { default = null type = string } + +variable "parameter_prefix" { + description = "prefix for parameter names. For example you wanna split dev/prod parameters so you wanna add /service_name/development/ prefix before parameter name" + default = null + type = string +}