Skip to content

Commit 84b0857

Browse files
author
Ben Fortuna
committed
Support configuring multiple parameters in parameter store
1 parent de4b927 commit 84b0857

File tree

6 files changed

+145
-2
lines changed

6 files changed

+145
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
terraform-aws-ssm-parameters.iml
3+
.terraform/

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SHELL:=/bin/bash
2+
TERRAFORM_VERSION=0.13.0
3+
TERRAFORM=docker run --rm -v "${PWD}:/work" -v "${HOME}:/root" -e AWS_DEFAULT_REGION=$(AWS_DEFAULT_REGION) -e http_proxy=$(http_proxy) --net=host -w /work hashicorp/terraform:$(TERRAFORM_VERSION)
4+
5+
.PHONY: all clean test docs format
6+
7+
all: test docs format
8+
9+
clean:
10+
rm -rf .terraform/
11+
12+
test:
13+
$(TERRAFORM) init && $(TERRAFORM) validate
14+
15+
docs:
16+
docker run --rm -v "${PWD}:/work" tmknom/terraform-docs markdown ./ >./README.md
17+
18+
format:
19+
$(TERRAFORM) fmt -list=true ./

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
1-
# terraform-aws-ssm-parameters
2-
Configure a list of SSM Parameter Store entries
1+
# ![AWS](aws-logo.png) SSM ParameterStore parameters
2+
3+
Purpose: Configure parameters in AWS SSM ParameterStore
4+
5+
## Requirements
6+
7+
No requirements.
8+
9+
## Providers
10+
11+
| Name | Version |
12+
|------|---------|
13+
| aws | n/a |
14+
15+
## Inputs
16+
17+
| Name | Description | Type | Default | Required |
18+
|------|-------------|------|---------|:--------:|
19+
| allowed\_pattern | A regular expression to restrict allowed parameter values | `any` | `null` | no |
20+
| context | A parameter context used as a prefix to the stored parameter key | `any` | `null` | no |
21+
| data\_type | Indicates the type of parameter value. Supported values are: `text` and `aws:ec2:image` | `any` | `null` | no |
22+
| key\_id | KMS key id for encrypting SecureString type parameters | `any` | `null` | no |
23+
| list\_params | A list of StringList parameters to add to ParameterStore | `list(map(any))` | `[]` | no |
24+
| overwrite | Overwrite existing parameter values | `bool` | `false` | no |
25+
| parameters | A list of String parameters to add to ParameterStore | `list(map(any))` | `[]` | no |
26+
| secure\_params | A list of SecureString parameters to add to ParameterStore | `list(map(any))` | `[]` | no |
27+
28+
## Outputs
29+
30+
No output.
31+

aws-logo.png

3.84 KB
Loading

main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* # ![AWS](aws-logo.png) SSM ParameterStore parameters
3+
*
4+
* Purpose: Configure parameters in AWS SSM ParameterStore
5+
*/
6+
resource "aws_ssm_parameter" "parameters" {
7+
count = length(var.parameters)
8+
name = var.context != null ? "/${var.context}/${lookup(var.parameters[count.index], "name")}" : lookup(var.parameters[count.index], "name")
9+
value = lookup(var.parameters[count.index], "value")
10+
description = lookup(var.parameters[count.index], "description") != null ? lookup(var.parameters[count.index], "description") : null
11+
type = "String"
12+
overwrite = var.overwrite
13+
allowed_pattern = var.allowed_pattern
14+
data_type = var.data_type
15+
16+
tags = {
17+
Context = var.context
18+
}
19+
}
20+
21+
resource "aws_ssm_parameter" "list_params" {
22+
count = length(var.list_params)
23+
name = var.context != null ? "/${var.context}/${lookup(var.list_params[count.index], "name")}" : lookup(var.list_params[count.index], "name")
24+
value = lookup(var.list_params[count.index], "value")
25+
description = lookup(var.list_params[count.index], "description") != null ? lookup(var.list_params[count.index], "description") : null
26+
type = "String"
27+
overwrite = var.overwrite
28+
allowed_pattern = var.allowed_pattern
29+
data_type = var.data_type
30+
31+
tags = {
32+
Context = var.context
33+
}
34+
}
35+
36+
resource "aws_ssm_parameter" "secure_params" {
37+
count = length(var.secure_params)
38+
name = var.context != null ? "/${var.context}/${lookup(var.parameters[count.index], "name")}" : lookup(var.secure_params[count.index], "name")
39+
value = lookup(var.secure_params[count.index], "value")
40+
description = lookup(var.secure_params[count.index], "description") != null ? lookup(var.secure_params[count.index], "description") : null
41+
type = "SecureString"
42+
overwrite = var.overwrite
43+
allowed_pattern = var.allowed_pattern
44+
data_type = var.data_type
45+
key_id = var.key_id
46+
47+
tags = {
48+
Context = var.context
49+
}
50+
}

vars.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
variable "parameters" {
2+
description = "A list of String parameters to add to ParameterStore"
3+
type = list(map(any))
4+
default = []
5+
}
6+
7+
variable "secure_params" {
8+
description = "A list of SecureString parameters to add to ParameterStore"
9+
type = list(map(any))
10+
default = []
11+
}
12+
13+
variable "list_params" {
14+
description = "A list of StringList parameters to add to ParameterStore"
15+
type = list(map(any))
16+
default = []
17+
}
18+
19+
variable "context" {
20+
description = "A parameter context used as a prefix to the stored parameter key"
21+
default = null
22+
}
23+
24+
variable "allowed_pattern" {
25+
description = "A regular expression to restrict allowed parameter values"
26+
default = null
27+
}
28+
29+
variable "data_type" {
30+
description = "Indicates the type of parameter value. Supported values are: `text` and `aws:ec2:image`"
31+
default = null
32+
}
33+
34+
variable "overwrite" {
35+
description = "Overwrite existing parameter values"
36+
default = false
37+
}
38+
39+
variable "key_id" {
40+
description = "KMS key id for encrypting SecureString type parameters"
41+
default = null
42+
}

0 commit comments

Comments
 (0)