This script will pull down an S3 remote configuration before running any terraform actions. Assumes the following structure:
main.tf
terraform.cfg
vars/dev
vars/staging
vars/production
ansible.cfg is required for the remote configuration.
You can use it like so:
./terraform-env.sh dev show
./terraform-env.sh staging plan -out plan
./terraform-env.sh production apply -var="some_var=some_value"
You can use the script just like you'd use terraform, passing whatever arguments you would before. It will only pull the latest environment if the current environment is different from the one you're requesting.
I just had a chance to look at this. It won't work as you are using the cache located in .terraform/terraform.tfstate. All you will end up doing is changing the location on S3 and then changing the state to use the different variables. It will modify the same infrastructure unless I am missing something?