Terraform code structure

I am creating Azure Terraform code in a modular structure.
Created a submodule with all the variables declared along with the it , which are needed for that resource deployment.

While calling this submodule from the main module, do we need to redeclare the submodule variables along with the main module variable file?
It results in duplicate code.

Please suggest if there is a better approach for writing the code to avoid this duplicate declaration of submodule variables ?

I’m not certain what language you are working in, but generally creating a type that represents the configuration will allow you to pass an instance of that type to both the main module and the submodule.

If you are instead using HCL or needing to use from HCL, then yes, you’ll need to duplicate the variables.