I have a terraform script that provisions a web service on AWS.
Now I want to reuse this script in different environments (production, stage, dev, ...).
Here's my folder structure:
.
├── main.tf
└── core_module
├── outputs.tf
├── my_service.tf
└── variables.tf
main.tf contains something like the following:
module "prod-service" {
source = "./core_module"
env_specific_variable = "this is a production environment"
...
}
module "stage-service" {
source = "./core_module"
env_specific_variable = "this is a stage environment"
...
}
module "dev-service" {
source = "./core_module"
env_specific_variable = "this is a dev environment"
...
}
When I want to create the service on the production environment, I run
terraform apply -target=module.prod-service \
-var 'access_key=<prod_access_key>' \
-var 'secret_key=<prod_secret_key>' \
-var 'region=<prod_region>
And when I want to create the service on the stage environment, I run
terraform apply -target=module.stage-service \
-var 'access_key=<stage_access_key>' \
-var 'secret_key=<stage_secret_key>' \
-var 'region=<stage_region>
How can I force the users of this script to add the -target option so that he/she doesn't create all the environments in one single command?
Because different environments require different aws_access_key_id and aws_secret_access_key, running terraform apply to create all environments will create errors.