Terraform backends
- When two engineers execute the terraform configuration with a perspective to create infrastructure for an application, it creates two different infra.
- What if these two engineers want to create the same environment, in this case the state should not be on the local system, it should be present on common location.
- This approach is called as backend. The default backend is local folder
- Refer Here for the terraform backends
- Lets create a common infra for multiple users using Azure RM backend
Refer Here for the changes done - For simulating multiple users i will be creating a linux instance, installing terraform and creating infra
- Now execute initialization
- Now apply from system 2 and execute apply from system 1 as well, on system you should get an error message of lock acquired by some one else
- After successful apply from system 2 now execute apply from system 1
- AWS S3 Backend: We can use s3 backend, but for locking we need to use dynamo db. Refer Here
- Refer Here for the s3 backend changeset
- Initialize the backend and do the rest as done for azurerm backend
Workspaces
- Using Terraform configuration to create multiple environmetns from the same configuration
- Refer Here for the changeset containing workspace demo features
- Lets initialize
- Lets check for the workspaces available. create the dev on the system 2
- Lets create dev from system 2 and qa from system 1 parallely
- Dev from system 2
Lifecycle
- Refer Here for the terraform lifecycle
- Refer Here for the changeset
Packer
- Packer is a free and opensource tool to create images i.e we can create azure vm images, aws amis
- Refer Here
- Refer Here for installing packer
- Refer Here for the example to create ami with packer in aws
- Refer Here for the changes to create azure vm image