Skip to content

Commit

Permalink
Support multiple services in params reader policy (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrien authored Sep 16, 2019
1 parent 6765b83 commit 96ea06d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions aws-params-reader-policy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Creates a policy to access encrypted parameters in Parameter Store for a given s
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging). | string | n/a | yes |
| extra_services | Extra services to be given parameter read access to, within the same project and environment. | list(string) | `[]` | no |
| parameter\_store\_key\_alias | Alias of the encryption key used to encrypt parameter store values. | string | `"parameter_store_key"` | no |
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | string | n/a | yes |
| region | Region the parameter store values can be read from. Defaults to all. | string | `"*"` | no |
Expand Down
7 changes: 6 additions & 1 deletion aws-params-reader-policy/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
locals {
resource_name = "${var.project}-${var.env}-${var.service}"
services = concat([var.service], var.extra_services)

param_resources = [
for serv in local.services : "arn:aws:ssm:${var.region}:${data.aws_caller_identity.current.account_id}:parameter/${var.project}-${var.env}-${serv}/*"
]
}

data "aws_caller_identity" "current" {}
Expand All @@ -18,7 +23,7 @@ data "aws_iam_policy_document" "policy" {
"ssm:DescribeParameters",
]

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

statement {
Expand Down
6 changes: 6 additions & 0 deletions aws-params-reader-policy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ variable "region" {
description = "Region the parameter store values can be read from. Defaults to all."
type = "string"
}

variable "extra_services" {
type = list(string)
description = "Extra services to be given parameter read access to, within the same project and environment."
default = []
}

0 comments on commit 96ea06d

Please sign in to comment.