Let's think about this for a second
In real projects, dev environments usually run small/cheap instances while production runs bigger, redundant ones — a common pattern is to use the module from Project 1 as a base template and split variable values into `dev.tfvars`, `staging.tfvars`, and `production.tfvars` per environment. You then run something like `terraform apply -var-file="production.tfvars"` to pick the value set for a given environment and apply it — since all three environments share the same module code, there's no need to duplicate anything.
Let's connect this to a real scenario
Set `instance_type = "t3.micro"` and `instance_count = 1` in `environments/dev.tfvars`, and `instance_type = "t3.large"` and `instance_count = 3` in `environments/production.tfvars` — then apply the same root config (the one calling the module) with a different `-var-file` flag per environment. You should also split the remote backend (from the Advanced chapter) by environment key (`key = "dev/terraform.tfstate"` vs `key = "prod/terraform.tfstate"`).
Let's look at an example
# environments/dev.tfvars
# instance_type = "t3.micro"
# instance_count = 1
# environments/production.tfvars
# instance_type = "t3.large"
# instance_count = 3
terraform apply -var-file="environments/dev.tfvars"
terraform apply -var-file="environments/production.tfvars"$ terraform apply -var-file="environments/dev.tfvars"
+ instance_type = "t3.micro"
+ instance_count = 1
Plan: 1 to add, 0 to change, 0 to destroy.Try it in 5 minutes
Write your own `dev.tfvars` and `production.tfvars` files, then apply a `local_file` resource (with content driven by a variable) twice, each time with a different `-var-file` flag — confirm the two output files end up with different content.
A quick word of caution
Before applying a production `.tfvars` file, double-check the environment name on your terminal — mixing up dev and production is one of the most common root causes of production incidents.