Getting Started with Terraform: Pt->1

2022.06.14

Terraform is an excellent Infrastructure as Code solution because to its short learning curve and simple HashiCorp Configuration Language (HCL).

Terraform is one of my favorite configuration management tools since it supports 2171 providers (AWS, Azure, Github, and so on), has a huge community, strong plugin support, and flexible interface with configuration management tools like ansible.

I'll aim to produce a series of terraform articles, starting at the 100 level and going to the 200 level, that will not only help you understand terraform fundamentally but will also help you operate with it.

Prerequisites

  • AWS Account
  • IDE (Visual Studio Code)
  • Access to Terminal

What is a provider?

  • There are numerous articles on how to get started with terraform. Terraform can be used to create an EC2 instance, but it is far more important to understand what is going on behind the scenes than simply writing code. (Knowing what's going on behind the scenes will help you solve and troubleshoot any problem.)
  • To tell Terraform that we want to interact with AWS and create infrastructure, we used the provider block.
  • Let's call the above-mentioned code ec2.tf; however, this won't suffice because of terraform.
  • We then use terraform init on the command line to download plugins for the AWS provider, which terraform uses to interact with AWS services.
  • Terraform created a .terraform directory to store the AWS provider plugins.
  • List of Terraform providers

Note:- The .terraform.lock.hcl file, which keeps track of the provider version, is also created by Terraform init. This lock file must be updated every time a new provider is added, which means terraform init must be run again.

What are resources?

  • Terraform resources are the means by which we can interact with various services based on the provider block we've chosen.
  • Terraform provides all the equivalent resources for the services provided by AWS, such as Ec2, EBS, and Dynamodb, for aws providers.
  • List of AWS Services which has sub resources
  • Some parameters in Resources will be optional, while others will be required.
  • https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance

    Note:- Terraform recommends adding terraform block starting with version 0.13. This is not required for terraform managed providers such as AWS, but it is required for providers that are not managed by Terraform.

  • optional ( aws is terraform managed provider but recommended )
  • mandatory ( for providers not managed by terraform provider)

Conclusion

The purpose of DevOps, as we all know, is to enhance software delivery efficiency, and we need certain tools to assist us achieve that. This is where solutions such as Terraform may aid businesses with infrastructure as code and automation.

Terraform is altering DevOps by redefining the way infrastructure is managed and making DevOps execution quicker and more efficient. You may have used tools such as Ansible, Chef, or Puppet to automate and provide software. Terraform follows the similar principle, infrastructure as code, but concentrates on infrastructure automation. Terraform allows you to simply specify your whole Cloud infrastructure.

Reference

https://registry.terraform.io/browse/providers

https://learn.hashicorp.com/collections/terraform/aws-get-started