Each module has its own set of input variables.
The input variables for the root module are set when you run Terraform, e.g. on the command like with the -var
option.
The input variables for any child module, like your module "logs"
here, are set inside the module
block.
Each variable declaration is valid only for the module it appears in. You happen to have given both of these variables the same name, which is fine and sensible as it helps a human reader understand that they represent the same concept, but Terraform considers these two variables entirely separate and requires you to declare and set both of them.
As an analogy, consider a module as being somewhat equivalent to a function in a programming language. Each function defines its own arguments, and two functions might have an argument of the same name but they are still distinct by virtue of belonging to different functions:
function main(env: string) {
logs(env)
}
function logs(env: string) {
// "env" in here is "test" because it was passed through
// the arguments of both of these functions, not because
// the arguments happened to have the same name in both
// functions.
}
// Calling main here is, for the purposes of this analogy,
// corresponding to running: terraform apply -var="env=test"
main("test")