Skip to content

Commit

Permalink
fix(vault-group): specify missing policy types
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-miemiec committed Jun 3, 2020
1 parent f5131e3 commit 4fd1179
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions modules/vault-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ locals {
for policy in ["read", "write"] : [
for key, data in secret_engines : {
type = "${data[0]}-${policy}"
key = "${environment}-${key}"
key = "${environment}-${key}/${policy}"
environment = environment
engine_path = data[1]
separator = var.separator
Expand All @@ -73,7 +73,14 @@ locals {

policy_templates = {
for policy in local.policy_data :
policy.key => templatefile("${local.templates_path}/${policy.type}.hcl", policy)
policy.key => templatefile("${local.templates_path}/${policy.type}.hcl", policy)
}

secret_engine_paths = {
for environment, secret_engines in var.environments:
environment => {
for engine, data in secret_engines: engine => data[1]
}
}
}

Expand All @@ -91,8 +98,11 @@ resource "vault_identity_group" "groups" {
member_entity_ids = each.value.entities
policies = flatten([
for policy in each.value.policies : [
for env in each.value.environments :
vault_policy.policies["${env}-${policy}"].id
for env in each.value.environments : [
for secret_engine in env : [
vault_policy.policies["${env}-${secret_engine}/${policy}"].id
]
]
]
])
}
6 changes: 6 additions & 0 deletions modules/vault-group/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
output "environments" {
value = var.environments
description = "Environments variable passthrough."
}

output "secret_engine_paths" {
value = local.secret_engine_paths
description = "Environments variable, but without Secret Engine types. For example kv = [\"kv2\", \"kv\"] becomes just kv = \"kv\""
}

output "group_ids" {
Expand Down

0 comments on commit 4fd1179

Please sign in to comment.