Terraform is an open-source infrastructure as a code software tool created by HashiCorp. Users define and provide data centre infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. It enables building, changing, and versioning infrastructure safely and efficiently. It can manage existing and popular service providers as well as custom in-house solutions. It also provisions infrastructure across public and private cloud platforms.
Infrastructure as Code:
Infrastructure as code manages and provisions computer data centres through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools. Terraform allows you to build, change, and version your infrastructure using code techniques. It will enable you to set configuration files to define your applications or infrastructure and store your infrastructure's state to modify or update.
The Terraform plan command creates an execution plan. By default, creating a project consists of reading the current state of any existing remote objects to ensure that the Terraform state is up-to-date. It compares the current configuration to the initial state and notes the differences. Terraform has a "planning" step where it generates an execution plan. The execution plan shows what Terraform will do when you apply for a call. This lets you avoid any surprises with Terraform.
Important Terraform Concepts:
ng to the server.
Modules: To organize configuration code & make the code reusable, the modules are used as a container for multiple resources that can be used together. Every Terraform configuration has at least one module, called the ‘root’ module.
Terraform Remote: To share responsibility for infrastructure, you can run Terraform in a remote environment with shared access to the state. This feature is called the ‘remote backend’. We can use Consul and S3 as a backend to store the state.
Important Commands of Terraform
Terraform version: This shows the current version of Terraform that is installed on the system. This can be helpful to figure out issues or ways of working with the current version.
Terraform init: Initializes a working directory containing Terraform configuration files. This working directory can also be checked from source control.
Terraform plan: Creates an execution plan. It reads the current state of any pre-existing remote objects to make sure that the Terraform state is up-to-date. The current configurations are compared to the prior state and differences are calculated.
Set of change actions to make the remote objects match the configuration are proposed. This won’t execute the changes
If this proposal matches expectations then this can be executed later.
Terraform fmt: rewrites Terraform configuration files to a canonical format and style. The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform this command should be run on modules to adopt the new version.
Terraform validate: Checks whether a configuration is syntactically valid and internally consistent.
Terraform apply: Executes the actions proposed in a Terraform plan.
Terraform show: Provides human-readable output from a state or plan file. This can be used to inspect a plan to ensure that the planned operations are expected, or to inspect the current state.
Terraform providers: Shows information about the provider requirements of the configuration in the current working directory.
Terraform output: Extracts the value of an output variable from the state file. With no additional arguments, the output will display all the outputs for the root module. If an output NAME is specified, only the value of that output is printed.
Terraform destroy: Destroys all remote objects managed by a particular Terraform configuration.
terraform import: Terraform is able to import existing infrastructure. This command allows us to bring resources that were created by some other means under Terraform management.
You can start using Terraform in internal AWS accounts for the below services.
To Build EC2 instances
To Build RDS instances
For S3 Buckets
To build VPC’s
To build SNS and SQS services
Benefits of Terraform:
Portability: You can use one tool and one language to describe the infrastructure for Google Cloud, AWS, OpenStack and any other cloud. The hassle of switching providers regularly is mitigated.
Ease of full-stack deployment: You can have Amazon instances running Kubernetes containers with your workloads and manage the whole system from one tool.
Easy collaboration: The Terraform registry (Terraform’s central registry version control) enables teams to collaborate on infrastructure.
Flexibility: Terraform not only handles IaaS (AWS, Azure, etc) but also PaaS (SQL, NodeJS). It can also store local variables such as cloud tokens and passwords in encrypted form on the terraform registry.
Neebal, a technology solutions provider, has delivered top of the line solutions across Agro, Pharma, and BFSI verticals. Neebal aims to provide top tier services for API, RPA, and advanced mobility with a prime focus on Hyperautomation. Founded in 2010, Neebal is a proud recipient of the Deloitte Technology Fast 500 Award (APAC) and the Deloitte Fast 50 Award (India) for four consecutive years (2017-20).