Hello,
I am creating a module with example code. My understanding is after I published this module, consumers who imported this module will execute example code as well when they run terraform apply.
If my understanding is correct, how to avoid this?
Appreciate for any help!
If you just have a separate directory with some example code then nothing needs to be done. By default the top level directory is where Terraform looks for the module’s code, so any subdirectories are ignored. They would only be used if there are references (e.g. with templatefile or as submodules).
2 Likes
what is the command that I wan to run module’s code under example folder only? should I cd to example folder, then run terraform apply?
what’s the way that I want to run module code under both example folder and root?
appreciate!
@stuart-c would you kindly help? Did I make myself clear? Appreciate!
Yes you need to be in the directory of the code you want to run (or use the global -chdir option).
The code in the example folder & root folder are totally separate, so you’d run terraform apply
in each, resulting in two different state files (you’d also need to run terraform init
in each directory to populate the .terraform directory).
1 Like