I want to be able to create vault
policies from a yaml
configuration as follows
policies:
policy-test-1:
- capabilities:
- read
- create
path: /foo/lala
- capabilities:
- create
- patch
path: /voo/lala
policy-test-2:
- capabilities:
- update
- delete
path: /foo/lala
i.e. I want to provision so that each policy document may be able to have multiple statements.
var.policy_statements
is the output of yamldecode
of the above file.
The following approach using dynamic
blocks however fails
data "vault_policy_document" "this" {
dynamic "rule" {
for_each = var.policy_statements
content {
path = rule.value.path
capabilities = rule.value.capabilities
}
}
}
resource "vault_policy" "this" {
for_each = var.policy_statements
name = each.key
policy = data.vault_policy_document.this[each.key].hcl
}
β Error: Unsupported attribute
β
β on ../path/to/policies/main.tf line 8, in data "vault_policy_document" "this":
β 8: capabilities = rule.value.capabilities
β βββββββββββββββββ
β β rule.value is list of object with 2 elements
β
β Can't access attributes on a list of objects. Did you mean to access
β attribute "capabilities" for a specific element of the list, or across all
β elements of the list?
β΅
β·
β Error: Unsupported attribute
β
β on ../path/to/policies/main.tf line 8, in data "vault_policy_document" "this":
β 8: capabilities = rule.value.capabilities
β βββββββββββββββββ
β β rule.value is list of object with 1 element
β
β Can't access attributes on a list of objects. Did you mean to access
β attribute "capabilities" for a specific element of the list, or across all
β elements of the list?
What is the correct way to run the loop, given that each object with the policy name (e.g. policy-test-1
) is an array of objects having as keys paths
and capabilities
?