Terraform Architecture


Terraform is an open-source infrastructure as code (IaC) tool developed by HashiCorp. It allows users to define and provision infrastructure using a declarative configuration language.

The architecture of Terraform involves several key components and concepts:

  1. Configuration Files:

    • Terraform uses configuration files written in HashiCorp Configuration Language (HCL) to describe the desired infrastructure. These files typically have a .tf extension.
    • Configuration files specify the resources, providers, and other settings needed to create and manage infrastructure.
  2. Providers:

    • Providers are plugins in Terraform that define and interact with a particular infrastructure platform or service, such as AWS, Azure, Google Cloud, or others.
    • Each provider has its own set of resources and data sources that can be managed using Terraform.
  3. Resources:

    • Resources are the fundamental building blocks in Terraform configurations. They represent infrastructure components like virtual machines, networks, databases, etc.
    • Resource declarations specify the desired state of the infrastructure, and Terraform manages the creation, updating, and deletion of these resources to achieve that state.
  4. State Files:

    • Terraform maintains a state file that keeps track of the current state of the infrastructure being managed. This file is used to plan and apply changes, as well as to track the relationships between resources.
    • The state file can be stored locally or remotely, and it helps Terraform understand what changes need to be made to reach the desired state.
  5. Execution Plan:

    • When you run terraform plan, Terraform generates an execution plan based on the configuration files and the current state. The plan outlines what actions Terraform will take to bring the infrastructure to the desired state.
  6. Execution Apply:

    • Running terraform apply applies the changes specified in the execution plan. Terraform will create, update, or delete resources as needed to match the desired state.
  7. Backends:

    • Terraform supports various backends for storing the state file. Common backends include local, remote, and version-controlled options like AWS S3, Azure Storage, and others.
    • Choosing an appropriate backend is important for collaboration, versioning, and maintaining the state file securely.
  8. Modules:

    • Modules in Terraform allow you to organize and reuse configuration code. They encapsulate a set of resources and can be used as building blocks for creating larger and more complex infrastructures.
  9. Variables and Outputs:

    • Variables are used to parameterize configurations, making them more flexible and reusable. Outputs allow you to expose certain values from the configuration for reference or use in other Terraform configurations.

Understanding these key components and concepts is crucial for effectively using Terraform to manage infrastructure as code. The tool provides a scalable and consistent approach to provisioning and managing infrastructure across various cloud and on-premises environments.


Terraform itself doesn't have a complex architecture, but it excels at managing the infrastructure architecture you define with it.

Terraform's architecture:

  • Configuration Files: Terraform uses configuration files written in HashiCorp Configuration Language (HCL) to define the infrastructure you want to provision. These files describe the resources needed and their configurations.

  • Providers: Terraform uses plugins called providers to interact with different cloud platforms or infrastructure services. You specify the providers required in your configuration files.

  • Dependency Graph: Terraform creates a dependency graph based on the configuration. This graph determines the order in which resources need to be provisioned due to their dependencies on each other.

  • Execution: Terraform uses the dependency graph to execute the configuration. It calls the appropriate provider APIs to create or manage resources based on the definitions.

This architecture allows Terraform to manage infrastructure in a declarative way. You define what you want, and Terraform takes care of how to achieve it.

Some additional points to consider:

  • Modular Design: Terraform configurations can be broken down into modules, promoting code reusability and maintainability.

  • State Management: Terraform keeps track of the infrastructure it manages in a state file. This file allows Terraform to track changes and ensure idempotence (avoiding unintended modifications).

  • Backend Options: Terraform supports storing the state file in various backends, like local storage, cloud object storage, or dedicated Terraform Enterprise backends.

Overall, Terraform's architecture is designed for simplicity and flexibility, allowing you to define and manage infrastructure in a code-driven and automated way.



The Terraform lifecycle refers to the various stages and processes involved in managing infrastructure using Terraform. It includes the steps from initializing a project to applying changes and updating the infrastructure.

Overview of the Terraform lifecycle:

  1. Initialization (terraform init):

    • The first step in using Terraform with a new or existing project is to run terraform init. This command initializes the working directory, downloads the necessary provider plugins, and sets up the backend for storing the Terraform state.
    • During initialization, Terraform downloads the provider plugins specified in the configuration and prepares the local environment for managing infrastructure.
  2. Configuration (*.tf files):

    • After initialization, you define your infrastructure in one or more Terraform configuration files (usually with a .tf extension). These files describe the resources, variables, outputs, and other settings necessary for your infrastructure.
  3. Planning (terraform plan):

    • The terraform plan command is used to create an execution plan. Terraform examines the current state, the desired state defined in the configuration, and determines what actions are necessary to reach the desired state.
    • The plan output displays the changes that Terraform will make to the infrastructure, allowing you to review and confirm before applying the changes.
  4. Apply (terraform apply):

    • The terraform apply command is used to apply the changes specified in the execution plan generated by terraform plan. During this step, Terraform communicates with the API of the infrastructure provider to create, update, or delete resources as needed.
    • Terraform will prompt for confirmation before making any changes, and the user can review the plan output before proceeding.
  5. Execution (terraform apply continued):

    • When you confirm the changes, Terraform executes the plan and updates the infrastructure. It creates new resources, updates existing ones, and removes resources that are no longer part of the desired state.
    • Terraform also updates the state file with the current state of the infrastructure.
  6. Destroy (terraform destroy):

    • The terraform destroy command is used to destroy all the resources created by Terraform for a given configuration. This is helpful when you want to decommission an environment or remove all resources.
    • Similar to terraform apply, terraform destroy generates a plan, and you need to confirm the destruction of resources before the operation is executed.
  7. State Management:

    • Terraform maintains a state file (by default, terraform.tfstate) to keep track of the current state of the infrastructure. The state file contains information about resources, their attributes, and dependencies.
    • Managing the state is crucial for collaboration and coordination among team members working on the same infrastructure.

These lifecycle stages provide a structured process for managing infrastructure as code with Terraform. It ensures that changes are planned, reviewed, and applied in a controlled manner, reducing the risk of unintentional or destructive modifications to the infrastructure.


Enroll Now

  • DevOps
  • Automation