When NOT to use Terraform (and what to use instead)

Updated: February 3, 2024 By: Guest Contributor Post a comment

Introduction

Terraform by HashiCorp has become a cornerstone tool for creating, managing, and orchestrating infrastructure across a variety of cloud and on-premises environments. Its declarative configuration language allows developers and operations teams to codify infrastructure, ensuring consistency, traceability, and automation at scale. However, like any tool, Terraform is not a one-size-fits-all solution. There are scenarios where Terraform might not be the best tool for the job.

Scenarios Where Terraform Should NOT Be Used

Small Scale Projects and Rapid Prototyping

In scenarios where teams are working on very small-scale projects or need to rapidly prototype, the overhead of setting up and maintaining Terraform configurations may not be justifiable. For such use cases, direct use of cloud provider SDKs or the console might be more efficient.

// Example of quickly provisioning an AWS S3 bucket using the AWS CLI
aws s3 mb s3://my-prototype-bucket

Output:

make_bucket: my-prototype-bucket

Highly Dynamic Environments

In environments where resources need to be spun up and down frequently within minutes, Terraform’s apply and destroy cycles can be relatively slow. Tools like AWS Cloud Development Kit (CDK) or Google Cloud Deployment Manager, which are closer to the cloud providers, may offer better real-time manageability.

// Example of deploying an AWS Lambda function using AWS CDK
const lambda = new cdk.aws_lambda.Function(this, 'MyFunction', {
  runtime: cdk.aws_lambda.Runtime.NODEJS_12_X,
  handler: 'index.handler',
  code: cdk.aws_lambda.Code.fromAsset(path.join(__dirname, 'lambda'))
});

Specific Cloud-Native Resources

When working with cloud-native resources that have very specific, detailed settings or configurations, the abstraction provided by Terraform might limit the fine-tuning possible compared to using the cloud provider’s specific service CLI or SDK.

// Example of setting a Google Cloud Function's memory and timeout
// directly using gcloud CLI
gcloud functions deploy myFunction --runtime nodejs10 --trigger-http --memory 512MB --timeout 60s

Networking-centric Infrastructure

For networking-centric tasks, especially those requiring a high degree of real-time adjustments or optimizations, native networking tools may be more suitable. This includes direct manipulation of network appliances or using cloud provider-specific networking services and configurations. Tools like Ansible, known for their capability in configuration management, might be more suited.

// Example of using Ansible to configure a network device
- name: Ensure the VLAN exists
  net_vlan:
    name: myvlan
    vlan_id: 100
  register: vlan_details

Development Environments

While Terraform is excellent for staging and production environments where infrastructure stability is critical, for day-to-day development, the overhead of applying Terraform plans for minor changes might be excessive. Technologies like Docker Compose, especially for microservices architectures, can be more agile for local development setups.

// Example of defining and running a multi-container Docker application using Docker Compose
version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"

Conclusion

Terraform is a powerful and versatile tool that, when used in the right context, can significantly enhance infrastructure management. However, understanding when not to use Terraform and opting for alternative tools better suited for specific needs can lead to more efficient project delivery. Remember, the goal is to choose the right tool for the job, not to adapt the job for the tool.