here is my code
variables
variable "definition_list" {
type = map(object({
policy_number = string
policy_file = string
display_effect = string
severity = string
env = string
}))
}
Terragrunt inputs section will relace the values in the map
inputs = {
definition_list = [
= {
policy_number = "Policy1"
policy_file = "policy1.definition.json"
display_effect = "Deny"
env = "B"
severity = "Critical"
}
{
policy_number = "Policy2"
policy_file = "policy2.json"
display_effect = "Allow"
env = "B"
severity = "Critical"
}
]
}
locals {
policy_list= flatten([
for key, value in var.definition_list : {
policy_number = value.policy_number
policy_file = jsondecode(file(value.policy_file)) #json file input from the terragrunt inputs
display_effect = value.display_effect
severity = value.severity
env = value.env
}
])
}
in my policy definition, i added the values like this
resource "azurerm_policy_definition" "definition" {
for_each = local.policy_list
name = each.value.policy_number
display_name = each.value.policy_file.properties.displayName
policy_type = each.value.policy_file.properties.policyType
mode = each.value.policy_file.properties.mode
metadata = jsonencode(each.value.policy_file.properties.metadata)
parameters = jsonencode(each.value.policy_file.properties.parameters)
policy_rule = jsonencode(each.value.policy_file.properties.policyRule)
}
My requirement is, get the inputs from policy_def.hcl file, apply the values in the policy definition, in the HCL list of inputs, there is a json file, which i will load from the code and parse the data along with terragrunt HCL file inputs.
While i am running the terragrunt run, getting the below error.
on definitions.tf line 7, in resource "azurerm_policy_definition" "definition":
│ 7: for_each = local.policy_definitions
│ ├────────────────
│ │ local.policy_definitions is tuple with 2 elements
│
│ The given "for_each" argument value is unsuitable: the "for_each" argument
│ must be a map, or set of strings, and you have provided a value of type
│ tuple.
can some one help me to fix this problem.