Skip to content

Commit 96ea06d

Browse files
authored
Support multiple services in params reader policy (#121)
1 parent 6765b83 commit 96ea06d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

aws-params-reader-policy/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Creates a policy to access encrypted parameters in Parameter Store for a given s
88
| Name | Description | Type | Default | Required |
99
|------|-------------|:----:|:-----:|:-----:|
1010
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
11+
| extra_services | Extra services to be given parameter read access to, within the same project and environment. | list(string) | `[]` | no |
1112
| parameter\_store\_key\_alias | Alias of the encryption key used to encrypt parameter store values. | string | `"parameter_store_key"` | no |
1213
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
1314
| region | Region the parameter store values can be read from. Defaults to all. | string | `"*"` | no |

aws-params-reader-policy/main.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
locals {
22
resource_name = "${var.project}-${var.env}-${var.service}"
3+
services = concat([var.service], var.extra_services)
4+
5+
param_resources = [
6+
for serv in local.services : "arn:aws:ssm:${var.region}:${data.aws_caller_identity.current.account_id}:parameter/${var.project}-${var.env}-${serv}/*"
7+
]
38
}
49

510
data "aws_caller_identity" "current" {}
@@ -18,7 +23,7 @@ data "aws_iam_policy_document" "policy" {
1823
"ssm:DescribeParameters",
1924
]
2025

21-
resources = ["arn:aws:ssm:${var.region}:${data.aws_caller_identity.current.account_id}:parameter/${local.resource_name}/*"]
26+
resources = local.param_resources
2227
}
2328

2429
statement {

aws-params-reader-policy/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ variable "region" {
2929
description = "Region the parameter store values can be read from. Defaults to all."
3030
type = "string"
3131
}
32+
33+
variable "extra_services" {
34+
type = list(string)
35+
description = "Extra services to be given parameter read access to, within the same project and environment."
36+
default = []
37+
}

0 commit comments

Comments
 (0)