We earn commission when you buy through affiliate links.
This does not influence our reviews or recommendations.Learn more.
Wondering, what is Terraform?
Lets find out about it.
Infrastructure as Code (IaC) is a widespread terminology among DevOps professionals.
It is a software engineering approach toward operations.
It helps in automating the complete data center by using programming scripts.
Terraformis an open-source infrastructure as Code tool developed by HashiCorp.
With Terraform, you’ve got the option to use it on othercloud hosting platformsas well.
Below are some of the benefits of using Terraform.
How Terraform Works?
Thefirstinput source is a Terraform configuration that you, as a user, configure.
Here, you define what needs to be created or provisioned.
It figures out what needs to be done to get to that desired state in the configuration file.
Providers
The second component of the architecture are providers for specific technologies.
This could be cloud providers like AWS, Azure, GCP, or other infrastructure as a service platform.
It gives you the possibility to create infrastructure on different levels.
With Kubernetes provider, you access to commodities, resources like services and deployments and namespaces, etc.
Lets do some practical stuff.
We will install Terraform on Ubuntu and provision a very basic infrastructure.
Install Terraform
Download the latest terraform package.
Refer to theofficial download pageto get the latest version for the respective OS.
Extract the downloaded package.
Move the terraform executable file to the path shown below.
Check the terraform version.
you could see these are the available commands in terraform for execution.
Create a working directory for this Terraform demo.
Note: I have changed the access and secret keys , you oughta use your own.
From the configuration mentioned above, you could see I am mentioning the provider like AWS.
Inside the provider, I am giving AWS user credentials and regions where the instance must be launched.
terraform init
Now, the first step is to initialize terraform.
terraform apply
The apply stage will execute the configuration file and launch an AWS EC2 instance.
You have successfully launched an AWS EC2 instance using Terraform.
If you recheck the EC2 dashboard, you will see the instance got terminated.
Conclusion
I believe the above gives you an idea to get it started with Terraform.
Go ahead and try out the example I have just shown.
If you are interested in learning more, then I would suggest checkingLearning DevOps with Terraform course.