What is a Terraform and Infrastructure as Code?

Top Infrastructure as Code (IaC) Providers: Advantages, Best Practices, and  Futures | Insights: Blog - AIM Consulting

Terraform is an open source tool built by Hashicorp to automate the provisioning of infrastructure resources. It is used to build, manage, update and delete infrastructure resources like virtual machines, containers, networking and others using infrastructure as a coding philosophy. Terraform is a vendor agnostic tool and can manage infrastructure for multiple resource providers (for example AWS, Google Cloud, Azure, Aviatrix, Heroku, Oracle, etc.).

In simple terms, if you want to provision a Virtual Private Cloud or an EC2 instance in AWS, you can write a terraform configuration to automate this process rather than doing it manually from AWS console.

Infrastructure as code is the process of provisioning and managing your cloud resources by writing a template file that is both human readable, and machine consumable. For AWS cloud development the built-in choice for infrastructure as code isĀ AWS CloudFormation.

Using AWS CloudFormation you can write a description of the resources that you want to create on your AWS account, and then ask AWS CloudFormation to make this description into reality. For example the following YAML template snippet describes an AWS ECS service resource to create:

Service:
  Type: 'AWS::ECS::Service'
  DependsOn: 'ServiceDiscoveryService'
  Properties:
    ServiceName: 'app'
    Cluster: 'production'
    DeploymentConfiguration:
      MaximumPercent: 200
      MinimumHealthyPercent: 75
    DesiredCount: 5
    TaskDefinition: !Ref 'TaskDefinition'
    ServiceRegistries:
      - RegistryArn: !GetAtt ServiceDiscoveryService.Arn
        ContainerPort: 3000
        ContainerName: 'myapp'

AWS CloudFormation takes this template and then assumes the responsibility of creating, updating, and deleting resources on your AWS account according to what is described in the template. If you add a new resource to the file CloudFormation will create that resource on your account. If you update a resource CloudFormation will either update or replace any existing matching resources. And if you remove a resource from the template it will be cleaned up and removed from your AWS account.

This article was updated on Jan 29, 2022

Toyhoshi

I'm Marco Varagnolo aka Toyhoshi, the author behind Clouday.dev, curious about everything by nature, i'm a system architect. Huge supporter of DevOps mindset. My hands are dirty all day long with Kubernetes, containers and many similar things in between. What else do you need? :-)