read part one and two before reading this part.

So in the previous part, we were able to deploy to multiple environments.
The challenges that we will try solve in this part are
- One single source of truth for variables for both the app and terraform.
- Variable inheritance, i.e those variables that were shared in staging and production. We had to copy them in each file
- An ephemeral environment without creating new files.
So let's start by checking out this branch terraform_with_ansible
Use this command
git checkout terraform_with_ansibleSo in this, you will notice we don’t have a specific configuration for development, staging and production. We are using the same terraform for development, staging and production.
Also, notice we don’t have to terraform variables for each environment.
In this case, we are using terraform workspace to create a different environment with the same terraform file and providing variables from ansible group variables. We are also using ansible to dynamically get those variables from group vars and calling to terraform with the same environment.
Now we can create an ephemeral environment by calling this command
make deploy config=staging env=my-custom-envAnd with that, you will have another replica of your environment.
Also, notice that the same environment that we are passing to terraform are the same values we are passing to the app via the env file. So we have solved the issue of having two different sources of variable values. And also we have tackled the issue of creating the ephemeral environment.
The theory will make sense if you get hands-on with part one, two and three.
In case you get issue while running the application please raise an issue so that we can improve it for the next person who reads this article https://github.com/mwaaas/ansible_terraform_demo/issues
