The IaaC Ninja - Terraform!

The IaaC Ninja - Terraform!

Crazy! Just one word to describe this tool.

Yes, I've only lately started looking into DevOps and Cloud possibilities. While still relatively new, I had heard of a tool by the name of Terraform. While searching for ways to upskill myself into things on the internet, I suddenly remembered this tool. The two resources I remembered were Pythoholic YT and of course my learning material from Great Learning ... Pythoholic YT is a genius at conveying information. I went to his YouTube page to see whether he had made any tutorial videos for this program, and to my luck, he was producing a series called "Level Up in DevOps" that included terraform. The best thing about his video series is that he starts by explaining everything, including how to download and install Terraform and which IDEs we may use. Trust me, it's also really simple to follow along.


I got began by installing my preferred IDE, Visual Studio Code. I simply adore it! So I started acting in accordance with the code I was carrying and a few things I had previously read about.

1> Installing Terraform locally on my local Machine

2> Spinning up an EC2 instance, and installing it (Terraform) manually.

3> Spinning up an EC2 instance with user data script to install Terraform.


Here is what Pythoholic said that we should keep in mind and comprehend while viewing the series on his YouTube channel:

1> Scope: Identify the infrastructure required for your project

2> Author: Write the configuration for your project infrastructure

3> Initialize: Install all the plugins needed for the management of the infrastructure

4> Plan: Preview the changes that terraform will make to match your configuration

5> Apply: Make the planned changes


Here are some basic commands that I tried as my first steps in terraform learning:

1> terraform init

The working directory holding the Terraform configuration files is initialized by the terraform init command. After creating a new Terraform configuration or cloning an existing one from version control, this is the first command that needs to be executed. We can run this command more than once without risk.

There are many options for this command. To name a few switches, -input, -lock, -lock-timeout=<duration>, -no-color and -upgrade. For more information, we can always look up the Documentation Register (https://registry.terraform.io/namespaces/hashicorp) for different providers.


2> terraform plan

Once the initialization is done, we need to plan the changes.

You can preview the steps Terraform would take to change your infrastructure using the terraform plan command, or you can save a hypothetical plan that you can use at a later time. The purpose of terraform plan is hypothetical; to use it, you must first save its contents and then feed them to a terraform apply command.

While we execute these commands, we can see a couple more files getting created. One of them would be the .terraform.lock.hcl and the other would be the .configuration object. The ".configuration" object represents your configuration as it was at the moment the terraform plan was created. To ensure that you utilize the same provider versions that produced the plan to implement the suggested modifications, this configuration snapshot records the versions of the providers listed in your ".terraform.lock.hcl" file.

Like the init command, the plan command also has switches.

More about terraform plan command: https://developer.hashicorp.com/terraform/cli/commands/plan


3> terraform apply

Once all the configurations have been examined and deemed "Good to Go," this command can be used to implement the modifications. The "terraform apply" can be executed in two distinct ways: "Automatic Plan Mode" and "Saved Plan File mode." There are no requirements for the Automatic Plan Mode before the "terraform apply" command. If no parameters are given, it just generates a new execution plan. We must include the file's name with terraform apply if we plan to deploy the infrastructure using the Saved Plan file option.

Oh, the endlessness of this! Yes, the alternatives available to coders in automation are plentiful.


Last but not least, remember to terminate or destroy any resources you've established with your provider while learning about these resource-oriented tools.


4> terraform destroy

This command, which I like to refer to as a "ka-boom command," merely eliminates or ends the resources.

Even though the installation and command-line operations went without a hitch, I did come across a few straightforward problems, such as the absence of the default VPC. So that offered me a fresh idea for using Terraform to create VPC. I only needed to go to the provider's page on Terraform and search for the VPC-related documentation. After the code was added and aligned with the previous code, I was able to deploy resources from my VSCODE, validate their availability, and then softly terminate them.


So special credits to Pythoholic YT and Great Learning team for making us understand these tools so easily. I would definitely recommend visiting their videos once if you are a beginner.


As always, Happy learning and keep evolving! and feedback is always welcome :)

要查看或添加评论,请登录

社区洞察

其他会员也浏览了