Infrastructure-as-code (IaC) enables managing and provisioning infrastructure through code instead of manual processes. IaC is crucial for DevOps teams as it lets them manage infrastructure components, such as networks and load balancers, and enables test applications in production-like environments early in the development cycle. It allows DevOps teams to build, change and manage infrastructure in a safe, consistent and repeatable way.
While infrastructure as code might traditionally be frustrating, as it requires cloud infrastructure to be created manually, Terraform brings the existing infrastructure under code management safely while removing manual processes. Terraform is one of the most popular open source IaC tools because it lets a user define resources and infrastructure in human-readable, declarative configuration files and easily manage infrastructure’s life cycle. It provides several other advantages such as the ability to manage infrastructure on multiple cloud platforms, write infrastructure code quickly, easily track resource changes throughout deployments, version control functionality and more. Terraform can operate on all cloud providers such as AWS, GCP and Azure, and is easy to install on machines or remote build servers.
How is Terraform Different?
Increasing fault tolerance by spreading infrastructure across multiple clouds is a common practice, as using a single cloud provider may provide a single point of failure. Multi-cloud deployment allows for easy recovery of the loss of a region or entire provider. But it can be challenging, as many existing tools for infrastructure management are cloud-specific.
Terraform addresses these challenges as it is cloud-agnostic and allows a single configuration to be used to manage multiple providers. It can also handle cross-cloud dependencies by simplifying management and orchestration.
Terraform provides a flexible abstraction of resources which allows DevOps teams to represent everything from physical hardware, virtual machines and containers to DNS providers easily. This flexibility can also manage a single application or even an entire data center—making it highly sought-after compared to other IaC tools.
Migrating From Existing Infrastructure to Terraform
Terraform brings existing infrastructure under as-code management in a safe and incremental way. One can easily migrate from an existing infrastructure by following these steps:
Install Terraformer from the below link:
To import resources from all services, use -- resources="*"
To exclude certain services, one can combine the parameter -- excludes
to exclude resources from services. For example, --resources="*" --excludes="iam"
After downloading Terraformer on the machine, one can migrate existing infrastructure into Terraform. For a smooth migration, everything must be included in a single command; otherwise, the state file may be lost or replaced. To migrate manually created resources, you need to specify everything in a single command.
For setting it up on Google Cloud, for example, one must access the information from Google Project and provide authentication information by setting up the environment variable “Google_Application_Credentials” along with the file path to the JSON file that contains the service account key. In this example, we migrated GKE clusters in GCP.
terraformer import google --resources=gke --filter=container_cluster=<Clusters-name separated by :> --filter=container_node_pool=<node-pools name separated by :> --regions=<region-name> --projects=<project-name>
Running this command will fetch all the resources of GKE into the local machine. However, this requires changing the backend to make these changes to Terraform cloud. Here’s how to do that:
backend "remote" {
organization = "<organisation-name>"
workspaces {
name = "<Your workspaces>"
The backend should be kept in a remote setting. The above steps ensure that the GKE cluster is migrated to Terraform without any interruption.
Challenges in Migrating Infrastructure
While Terraformer is an important tool to automate infrastructure and reduce the complexity of managing resources manually, migrating the infrastructure to Terraform can have its own set of challenges. It is important to include all the services in the import command. Failing to do so might require migrating the infrastructure by writing individual files which can be an intimidating task. Another challenge is that while importing different services, the backend file must be replaced or it may lead to losing the first infrastructure backup in the remote backend.
Importance of Migrating Existing Infrastructure
Migrating existing infrastructure to Terraform has several benefits such as:
- Easy migration of all the existing infrastructure into the cloud without any interruption
- Easy management of resources on the cloud while keeping track of changes
- Secure deployment of resources in Terraform cloud
One further caveat: Terraform is a relatively new technology and adapting it to manage an organization’s cloud resources might take some time and effort. It requires specialized skills and training to use Terraform to effectively manage cloud infrastructure. It may also be challenging to use it while dealing with concepts such as a remote backend. Despite these hiccups, Terraform offers huge advantages for DevOps teams to easily manage infrastructure.