Table of Contents
What is Terraform and what are its benefits
The beauty of Terraform is that it allows experienced system administrators to work on the infrastructure without needing deep knowledge about how these things work. This is especially useful in cloud system administration, where the infrastructure is more dynamic and less predictable.
Programmers can write code to manage data center orchestration, billing, and so on. The developer doesn’t need to know OpenStack and VMware intimately but just enough to write a function that does what he wants. He can download or generate a template for AWS or OpenStack virtual machines for free from communities like Packer and Ansible Galaxy that support Terraform.
Terraform is the cloud infrastructure as code solution that everyone is talking about. The service automates how infrastructure is configured and managed through the use of configuration files that are in plaintext. These files are stored in a git repo and can be granted secure access to collaborators. Terraform reads these configuration files and creates a new infrastructure that is exactly as specified, with dependencies handled correctly so changes aren’t lost when they’re refactored or deleted.
– https://medium.com/@julian.flickr/what-is-terraform-and-what-are-its-benefits-5c25a7b1bb2a

How to use Terraform to create and manage infrastructure
Terraform is, to quote the developers, “a tool for building and changing infrastructure in any cloud or in your data center.” It uses a declarative configuration language that makes it easy for a system administrator to describe what resources should be created and how they should be configured. It operates on a .tfplan file that is created in a directory where other Terraform configuration files (a terraform.tfstate file) are kept. This state is used as the basis for creating the desired infrastructure; this is referred to as “dispatching” work.
Terraform is written in Go and is available as a Ruby plugin.
##
##
To use Terraform, you must have the “terraform” binary on your system, either in a directory listed in your PATH environment variable or in the terraform folder. You can download it from the terraform-providers/terraform-provider-aws repository on GitHub.
##
terraform init [options]
A terraform init is the simplest way to get started with Terraform. It creates a configuration file and a state. The terraform init command is designed to help you quickly start using terraforming, and it operates “behind the scenes” to keep your infrastructure up-to-date and locked down appropriately.
The different types of resources that Terraform can manage
Terraform offers a wide range of resources like application servers, databases, networks, volumes and even configuration files. The following are the types of resources that are possible to manage with Terraform: – Resource configuration files – Configuration files to manage resources (e.g. Consul config, Nginx)
– Provider plugins – A plugin that manages a specific kind of resource (e.g. MySQL, Redis)
– Module plugins – A plugin that manages a set of resources (e.g. Cluster resource)
– Terraform maps – Maps from names to values (e.g. RabbitMQ nodes)
– Databases – Amazon RDS, PostgreSQL, MySQL, MongoDB and more – Amazon EC2 instances – DigitalOcean droplets, Azure virtual machines and more – Public and private Docker registries – Cloud storage providers (e.g. AWS S3) – Cloud images on various providers (e.g. Packer images)
– Networking providers (e.g. AWS VPC, DigitalOcean Networks)
– Volumes on cloud storage providers (e.g. AWS EBS) – Firewall rules (e.g. AWS VPC) – DNS providers (e.g. AWS Route 53)
– HTTP(s)/TCP/UDP/tcpdysproxies and SOCKS proxies – DNS zone providers (e.g. AWS Route 53, CloudFlare)
– Databases – MySQL, PostgreSQL and others – Key-value stores like Consul, Redis and Riak

How to apply a Terraform configuration to a target environment
Before it is possible to apply this configuration, you need to first create a Terraform configuration. The Terraform configuration contains the definitions of resources that are to be managed. The terraform apply command will then work its way through your terraform.tfplan file, applying the defined resources to your target environment. It is important to remember that though Terraform performs the actions specified in the configuration, it will not modify anything if there are errors. All changes that Terraform makes will be stored in your terraform.tfstate file. It is the responsibility of you and your team to review those changes and decide what happens next.
##
The terraform apply command allows you to apply a Terraform configuration to a target environment. The terraform apply command allows you to apply more configurations to your infrastructure.
The terraform apply command coordinates the configuration of your infrastructure with the Terraform client. The terraform apply command instructs it to run the commands in your Terraform configuration that configure and deploy resources onto your target environments. This can be used to define and deploy infrastructure, such as application servers, databases or load balancers.
The terraform apply command allows you to input a target environment name. It then executes the supplied Terraform configuration against that resource.
The terraform apply command supports the following options:
-f, –file Terraform configuration file (defaults to $TARIFORMTF_HOME/terraform.tfplan) -h, –help Display this help message To see all commands supported by Terraform and their respective help text, run terraform help command .
##

Tips for troubleshooting Terraform errors
A good first step to solving any Terraform errors that may arise is to look at it from a human perspective as opposed to using the error message alone. For instance, if you are attempting to create a “vip” resource that does not exist, try looking at the plan and checking for any missing directories or files. If you see that resources need adding but don’t exist, add them and then reapply. If you are experiencing a “no such file or directory” error, try looking at the state file to see whether it is a directory or a file that doesn’t exist – this can help as you can change your order of execution to search for files that are not explicitly mentioned.