-
Notifications
You must be signed in to change notification settings - Fork 110
[BUG] Getting a null if a variable doesn't have a default value #309
Comments
@rsareth As always, thanks for the highly detailed bug reports. This really allows us to make Regula better for everyone. I'm wondering what the expected behavior should be here? It seems reasonable to replace non-nullable string variables with |
Hello @jaspervdj-luminal, You are asking the right question. I don't really know what it should be in that specific use case. Our context:
The name of the microservice is partially correlated to the name of the repository. For example, the repo name foobar-application-a, its microservice name is applicaton-a. As we tag all of our cloud resources with a naming convention, we have many empty variables that need to be filled by the terraform cli. So technically, it looks like this: $ terraform apply -var="app_name=<APP_NAME_A>" -var="app_group=<GROUP_A> -var="commit_id=<SHORT_COMMIT_ID>" [...]" We don't use terragrunt and we didn't make our microservices as terraform modules too. We developed our tool in python by wrapping the terraform cli. We are using this library: https://github.com/beelit94/python-terraform BTW, these standards help us to scale easily and to write more tools around them like scannig with regula our terraform code form example. Suggestion 1: But doing this, the cons are:
Suggestion 2:
But it is like the Pandora box. It is so dirty to me to have different behaviours that it can bring more issues than solving them. Suggestion 3:
But at the end, I don't know! :-( Regards, |
I saw your last release. In the version 2.5.0, checking some resources having some attributes filled with nullable variables didn't fail. On contrary, it helped to make fix misconfiguration like I wanted. But in the version 2.6.0, the same policy doesn't work anymore. So using the latest version makes me to be less precise on the check or I have to set a default value which I don't want to. The policy is doing this:
The local function_name is initialized like this: locals {
function_name = "${terraform.workspace}-${var.custom_name}
} The variable custom_name is null in the HCL2 code BUT it is provided in a tfvars file in another location. I type this globally: $ terraform apply -var "custom_name=foobar" So, did you have time to think of a solution on this particular issue ? Thank you Regards, |
I was thinking of a solution. Regula doesn't parse the tfvars file. If it does, it can offer more use cases of control. For example, we could check the length of some attributes according to the tfvars used for one environment. |
Describe the bug
It is the same kind of issue like #305. And since TF 1.1.0, it is possible to define a variable nullable: https://www.terraform.io/language/values/variables#disallowing-null-input-values
How you're running Regula
Steps to reproduce
We've tried a workaround by defining a default value with the empty character but we can't rely on this. We want to make mandatory to provide some values.
Thank you
Regards,
Rasmey
The text was updated successfully, but these errors were encountered: