Terraform by HashiCorp Infrastracture as Code

in #devops6 years ago (edited)

Terraform.png

Terraform is an open source Infrastructure as Code (IoC) tool provided by HashiCorp Inc. It helps System Engineers and Developers to write there infrastructure in an easy way. This means you can create, adjust and destroy your infrastructure as you speak in a safe and efficient way.

You can use Terraform to create computing instances, setup storage, change your network and so one. This can be done for multiple public cloud vendors like AWS, Google Cloud, as well for you private cloud like OpenStack and VMware vSphere. The list of available official providers is long.

Terraform is not a Configuration Management (CM) solution like Puppet, Chef and Ansible. Which helps you to install software on your server and add your specially tailored configurations.
Terraform is a 'orchestration tools' which means it helps you to provision your servers and leaving the configuration to tools configuration management solution. With Terraform you spawn the Infrastructure and hand the new virtual machine (VM) to your Configuration Management tool of choice. Now you may ask your self why should I not use Puppet, Chef or Ansible to create my infrastructure, they can more or less do it. But this tools are made mainly to take care about your configuration not to setup your infrastructure. Infrastructure as Code tools will do this in a better and cleaner way then you could do with your CM tool.

Enough words let's see some examples.

To create a EC2 instance with Terraform all you need are few lines.

resource "aws_instance" "example-ec2" {
  ami = "ami-2d39803a"
  instance_type = "t2.micro"
}

If you would run now terraform apply you would have one EC2 instance. That was easy no? but that not all :)

To scale your EC2 instances may due to more traffic, all you need is to add one single line.

resource "aws_instance" "example-ec2" {
  count = "3"
  ami = "ami-2d39803a"
  instance_type = "t2.micro"
}

The count attribute create two more instances with the next terraform apply. You may ask yourself now why two instances? Terraform is declarative, so it is aware of the last state. In our case we created one EC2 instance before we changed our resource in the main.tf to three. So Terraform will just create two more so we have three in total.
With a CM tool you could end up with four VM but not with Terraform.

To get rid of your three EC2 instances simply run terraform destroy and all instances will be removed.

I hope you got hocked up with my short intro into Terraform. In the next days I will add more examples and tell more about what you can do. If you can't wait please take a look at Terraform intro.

If you liked this post, upvote/resteem.