Closed Tanchwa closed 1 year ago
Hi @Tanchwa, please try updating the locals validation (variables.tf line 109) to the below and try again, let me know if this helps and I'll fix in the next release:
locals {
parameters = coalesce(var.policy_parameters, try((local.policy_object).properties.parameters, {}))
}
Thanks that seems to have worked. I tried using an empty string earlier, should have thought to use an empty object. I'll keep an eye out for similar issues with the other fields and report back here if I find them, but I think parameters is the only optional one.
Issue Template
Prerequisites
Context
Expected Behavior
Module should be able to handle null values for certain fields in policy JSON Ex: not all policies have a parameters attribute, the module should not break if this is missing.
Current Behavior
policy definition module variables.tf currently does not have a way to properly handle null values (coalesce errors out on null) if you introduce a try block that results in null around the parameters locals value
try(coalesce(var.policy_parameters, try((local.policy_object).properties.parameters, null)), null)
, it results in a further error that APPEARS to attempt to allow null values, but is not functioning as expected ╷ │ Error: Invalid function argument │ │ on Modules/Policy/main.tf line 11, in resource "azurerm_policy_definition" "def": │ 11: parameters = length(local.parameters) > 0 ? jsonencode(local.parameters) : null │ ├──────────────── │ │ while calling length(value) │ │ local.parameters is null │ │ Invalid value for "value" parameter: argument must not be null.Possible Solution
introduce the necessary null value handlers throughout the code to allow for null values, especially in the parameters field.
Failure Information (for bugs)
Steps to Reproduce
Failure Logs
│ Error: Error in function call │ │ on Modules/Policy/variables.tf line 109, in locals: │ 109: parameters = coalesce(var.policy_parameters, try((local.policy_object).properties.parameters, null)) │ ├──────────────── │ │ while calling coalesce(vals...) │ │ local.policy_object is object with 3 attributes │ │ var.policy_parameters is null │ │ Call to function "coalesce" failed: no non-null, non-empty-string arguments.
│ Error: Invalid function argument │ │ on Modules/Policy/main.tf line 11, in resource "azurerm_policy_definition" "def": │ 11: parameters = length(local.parameters) > 0 ? jsonencode(local.parameters) : null │ ├──────────────── │ │ while calling length(value) │ │ local.parameters is null │ │ Invalid value for "value" parameter: argument must not be null. ╵