Workspaces, modules, TF files and directory layout

Hello everyone,
I’m trying to setup a Terraform configuration to manage AWS resources for a project involving some services (EKS RDS EC2 instances etc.) and 3 envs: production, staging and development. As a reference I’m using an already existing Terraform config that uses modules but everything is in the default workspace. I’d like to follow best practices found here: Part 1: Overview of Our Recommended Workflow - Terraform Recommended Practices | Terraform by HashiCorp and create a workspace per environment per Terraform configuration while keeping using the modules.
I went through documentation / tutorials but they tend to focus on workspaces xor modules, and above all I cannot find information on how to layout files so that switching to a certain workspace only relevant TF files are used by terraform plan and apply.
For example if I switch to a workspace called security-staging how can I tell terraform to only load a TF file (that will source modules) pertaining to such workspace (for example security-staging.tf) while ignoring the others (for example database-prod.tf etc.)?
Is this even possible with Terraform open source? I see that there are difference compared to Terraform enterprise Part 1: Overview of Our Recommended Workflow - Terraform Recommended Practices | Terraform by HashiCorp
Maybe I’m misunderstanding the role of workspaces and modules, I’d appreciate any hints.
Thnk you in advance for your help

  • Fabio