I have a module that accepts a variable with a validation as follows
variable "policy_statements" {
description = "The statements of the policies to be created"
type = map(object({
path = string
capabilities = set(string)
}))
validation {
condition = contains(["create", "read", "update", "patch", "delete", "list"], var.policy_statements.capabilities)
error_message = "Valid values for capabilities are (\"create\", \"read\", \"update\", \"patch\", \"delete\", \"list\")."
}
}
I am then calling this module from another tf module:
module "policies" {
source = "../../../../path/to"
for_each = var.policies
policy_statements = each.value
}
In the outer module, the policies variable is declared as
variable "policies" {
description = "The statements of the policies to be created"
type = map(any)
}
Invocation fails with:
│ on ../../../../path/to/variables.tf line 13, in variable "policy_statements":
│ 13: condition = contains(["create", "read", "update", "patch", "delete", "list"], var.policy_statements.capabilities)
│ ├────────────────
│ │ var.policy_statements is map of object with 2 elements
│
│ This map does not have an element with the key "capabilities".
The outer module reads the policies variable in a terragrunt.hcl as below:
locals {
policies = yamldecode(file("config.yaml"))
}
inputs = {
policies = local.policies
}
where config.yaml
policies:
policy-test-1:
capabilities:
- read
- create
path: /foo/lala
policy-test-2:
capabilities:
- update
- delete
path: /foo/lala
What is the reason of the validation failure?