From 95639b1043543a4b41634cbfb302ba1ec0638b36 Mon Sep 17 00:00:00 2001 From: Rafid Aslam Date: Fri, 9 Feb 2024 20:31:45 +0700 Subject: [PATCH] terraform_plan/provider_config: Send error=2 when region isn't provided --- src/tirith/providers/terraform_plan/handler.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tirith/providers/terraform_plan/handler.py b/src/tirith/providers/terraform_plan/handler.py index ba0836d..4e460e6 100644 --- a/src/tirith/providers/terraform_plan/handler.py +++ b/src/tirith/providers/terraform_plan/handler.py @@ -230,10 +230,20 @@ def provider_config_operator(input_data: dict, provider_inputs: dict, outputs: l return outputs.append({"value": version_constraint, "meta": provider_config_dict}) elif attribute_to_get == "region": - # TODO: The region might not be in the constant_value, it can be in a variable + # FIXME: The region might not be in the constant_value, it can be in a variable + region = provider_config_dict.get("expressions", {}).get("region", {}).get("constant_value") + if region is None: + outputs.append( + { + "value": ProviderError(severity_value=2), + "err": f"region is not found in the provider_config (severity_value: 2)", + "meta": provider_config_dict, + } + ) + return outputs.append( { - "value": provider_config_dict.get("expressions", {}).get("region", {}).get("constant_value"), + "value": region, "meta": provider_config_dict, } )