How terraform variables work when there is modularized stack?

Hi Team,

Can someone please explain, I have been using it but have some gap 100% understand it.

Let say I have following:

terraform

  • modules:

    • ec2:
      • main.tf
      • variables.tf
  • main.tf

  • variable.tf

I’ve main.tf, variables.tf and modules under root.
Under module, I’ve ec2 folder with main.tf and variables.tf.

Root main.tf will call modules/ec2 main.tf which will have variables passed from variables.tf. Same variables are defined in variables.tf in root folder. How this works.

Can someone please help me understand this?

Thanks.
KS

Hi

I have written a full tutorial on best practices for Terraform and Ansible that uses modules. Please take a look and let me know if explains the variables and modules relationship.

Is that what you are looking for?

BR
Javier