'Why terraform validate is giving error on my declared varaibles?

├── comp-B
│   ├── comp-B.tf
│   ├── outputs.tf
│   ├── terraform.tfvars
│   ├── variables.tf
│   └── vcn.tf
├── main.tf
├── outputs.tf
├── provider.tf
└── variables.tf

The argument "vcns" is required, but no definition was found I have defined the vcns in comp-B/variables.tf and vcns value in terraform.tfvars But still getting the error.



Solution 1:[1]

Without seeing your source code I can't be sure, but I'm assuming that what you mean by this directory tree is that the root main.tf contains a module block with source = "./comp-B", and the error you saw is indicating that module block as the source of the problem.

The terraform.tfvars file is only for setting variables in the root module, which means the ones defined in your root variables.tf. If you want to pass those values on to a child module then you can include an argument in the module block which refers to the variable:

module "example" {
  source = "./comp-B"

  vcns = var.vcns
  # ...
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Atkins