Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple services in params reader policy #121

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
}