Skip to content

Commit

Permalink
add prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
zahornyak committed Jun 1, 2023
1 parent f8b7ba9 commit 5f738a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,6 +34,9 @@ module "parameters" {
module "parameters" {
source = "zahornyak/multiple-ssm-parameters/aws"
# prefix for parameter name
parameter_prefix = "/dev/"
file_path = ".env"
}
Expand Down Expand Up @@ -93,6 +99,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_file_path"></a> [file\_path](#input\_file\_path) | file to parse | `string` | `null` | no |
| <a name="input_parameter_prefix"></a> [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 |
| <a name="input_parameters"></a> [parameters](#input\_parameters) | map of parameters for parameter store | `any` | `{}` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Specifies a tags | `any` | `{}` | no |

Expand Down
2 changes: 2 additions & 0 deletions examples/parse-env-file/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module "parse_files" {
source = "../.."

parameter_prefix = "/dev/"

file_path = ".env"

}
Expand Down
2 changes: 2 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module "parameters" {
source = "../.."

parameter_prefix = "/dev/"

parameters = {
db_name = {
name = "foo"
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5f738a3

Please sign in to comment.