Default Input Type In Terraform


When I just declare an input variable like below, what does it type points to? would that be map by default or some other types like null?

variable “my_vnet” {}

If not specified the type defaults to any (Input Variables - Configuration Language | Terraform | HashiCorp Developer). I’d always recommend including the type explicitly as it makes it really clear about what is expected & finds issues more quickly.

If you don’t specify a type constraint then Terraform will choose a type automatically based on the given value, which is essentially the same as type = any.

However, a module that doesn’t declare type constraints for its input variables is typically hard to use (callers need to read the source code to guess what values would be valid) and hard to develop (because Terraform will be forced to guess your intent in more places and will therefore generate worse error messages), so I would suggest declaring an appropriate exact type constraint – that is, a type constraint that does not include the any placeholder in it at all – for all of your input variables except in some rare situations where arbitrary types are really required.