DevOps(Day-60): Terraform

DevOps(Day-60): Terraform

TABLE OF CONTENTS

What is Terraform?

Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It enables you to define, provision, and manage your infrastructure as code using a declarative language. With Terraform, you can describe your infrastructure in a high-level configuration language, and then use that configuration to create, modify, and delete infrastructure resources in a consistent and repeatable way.

Overall, Terraform is a powerful and flexible tool that enables you to manage your infrastructure as code, providing a declarative, repeatable, and scalable way to manage infrastructure resources across multiple cloud providers.

Task 1: Configure Terraform

  • Install Terraform on your system.
  1. Create an EC2 instance in the AWS management console.

  2. Get the command to install Terraform on the Ubuntu server as our OS is in Ubuntu from the official Terraform site using the link - (terraform.io/downloads.html).

  3. Copy the commands and execute them in the server.

  4. Execute the 2nd command.

  5. Update apt in the server and then install Terraform.

  6. Let's check the version of Terraform.

Task 2: Terraform terminologies

  • Why do we use terraform?

    Here are some of the reasons why we use Terraform:

    1. Infrastructure as Code (IaC): With Terraform, you can define your infrastructure as code, making it easier to manage and maintain your infrastructure. Terraform provides a declarative syntax that makes it easy to understand and modify the infrastructure configuration.

    2. Multi-cloud Support: Terraform supports multiple cloud providers like Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and many others. This means that you can use Terraform to manage infrastructure across multiple cloud providers, which can be helpful if you have a multi-cloud strategy.

    3. Version Control: Terraform configurations can be versioned using Git or other version control systems, allowing you to track changes and roll back to previous versions if necessary.

    4. Consistency and repeatability: By using Terraform, you can ensure that your infrastructure is consistent and repeatable. Terraform configurations can be applied to new environments with minimal modification, making it easy to deploy infrastructure to multiple environments.

    5. Collaboration: Terraform supports collaboration between multiple teams and individuals working on the same infrastructure. Terraform configurations can be shared via version control systems, making it easier to collaborate and work together.

Overall, Terraform provides an efficient way to manage and provision infrastructure resources, enabling organizations to move faster and achieve greater consistency and repeatability in their infrastructure management.

  • What is Infrastructure as Code (IaC)?

    Infrastructure as Code (IaC) is an approach to managing IT infrastructure resources in a declarative manner, using machine-readable definition files instead of manual processes. It involves using code to define and automate the deployment, configuration, and management of infrastructure resources such as virtual machines, networks, storage, and applications.

    With IaC, infrastructure resources are treated as software components, where the code used to define them is stored in a version control system and can be tested, reviewed, and deployed using automated workflows. This approach allows for the same level of agility, scalability, and efficiency as software development.

  • What is a Resource?

    In Terraform, a resource is a single entity in your infrastructure that you want to manage using Terraform. It could be a virtual machine, a database, a network interface, or any other component that you want to provision, configure, or manage. A resource is defined using a Terraform configuration block that specifies the resource type, attributes, and dependencies.

  • What is Provider?

    In Terraform, a provider is a plugin that enables Terraform to manage a specific type of infrastructure or service, such as AWS, Azure, Google Cloud Platform, or many others. Providers are responsible for communicating with the underlying API of the infrastructure or service and exposing the necessary resources and operations to Terraform.

    Providers are typically distributed as separate binaries and can be installed and configured separately from Terraform itself. Each provider has its own set of resources, data sources, and other configuration blocks that allow you to interact with the corresponding infrastructure or service.

  • What is the State file in Terraform? What’s the importance of it?

    In Terraform, the state file is a JSON file that keeps track of the current state of your infrastructure as defined by your Terraform configuration. The state file contains information about the resources you have created, their configuration, and any dependencies between them. It also tracks metadata such as unique identifiers, timeouts, and other properties that Terraform uses to manage the resources.

    The state file is a critical component of Terraform, as it enables Terraform to know what resources are currently deployed, what changes have been made, and what changes are still needed to reach the desired state defined in your Terraform configuration. This allows Terraform to manage your infrastructure safely and predictably, ensuring that only the necessary changes are made to your infrastructure and that changes are made in the correct order to avoid any issues or errors.

  • What is Desired and Current State?

    In Terraform, the desired state is the state of your infrastructure that you define in your Terraform configuration files. It represents how you want your infrastructure to be configured, including what resources should exist, their attributes, and any dependencies between them.

    The current state, on the other hand, is the actual state of your infrastructure as it exists in the real world. It represents the current state of the resources that have been created, their attributes, and any dependencies between them.

Thanks for reading my article. Have a nice day.

WRITTEN BY Biswaraj Sahoo --AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes

Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333