- Terraform
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.
- Amazon Web Services
Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 200 fully featured services from data centers globally. Millions of customers—including the fastest-growing startups, largest enterprises, and leading government agencies—are using AWS to lower costs, become more agile, and innovate faster.
-
This project demonstrates the core power of cloud computing and infrastructure as code , within few minutes and with just few lines you could set up a fully enterprise grade IT infra to host your
monolithic
ormicroservices
applications. -
With this code you could set up a cluster of 2 EC2 instances hosting a nginx docker container as webserver in differnet Availability Zone in single region with one Application Load Balancer in front, distributing the backend traffic with required networking setup. With making sure that our state files are also get backed up on AWS S3 buckets. "Sounds Fun isn't it !!"
Terraform V-1.0.1
Download URLAWS Account with Admin access
Console
- Creation of Backend bucket
Change directory to remote-state
and perform below tasks.
cd remote-state
terraform init
terraform plan
terraform apply
- Terraform Init
To work on our main config move out of remote-state
dir.
For initiating the terraform to download the plugins as per your provider in this case AWS
, execute below command from the directory having main.tf
and other .tf*
files.
cd ..
terraform init
- Variables
Prepare your variable file terraform.tfvars or *.tfvars
accordingly as per the variables defined in the main.tf
file.
- Terraform Plan
For rendering objects created by the terraform and as a best practice always do a terraform plan
before applying the config.
- Terraform apply
Use command terraform apply
to apply the config.
terraform apply
- Terraform state
To view the list of all objects created by Terraform use terraform state list
command.
terraform state list
- Use
terraform destroy
command for destroying all objects mentioned in config file. If we want to remove specific object then we can useterraform destroy -target aws_<resource_name>.<name_mentioned_maintf>
.However it is not the best practice, always try to keep your config file updated as per the infra required.
terraform destroy
terraform destroy -target aws_vpc.myapp_vpc ## will delete vpc only
[x] Refer to Terraform-AWS documentation for extra custom configs.
[x] As for backend terraform configuration bucket should be already existing in our infra. We have created a dedicated directory remote-state
with config for bucket provisioning.