DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Terraform and IaC
Andrey Frol
Andrey Frol

Posted on • Updated on

Terraform and IaC

What is IaC?

The first objective will cover basic understanding of IaC and why it is useful in the first place.

So what is Infrastructure as Code?

Infrastructure as Code (IaC) is the practice of managing and provisioning of infrastructure through code instead of through manual processes.

IaC configuration files contain your infrastructure specifications. Configuration files contain modularized representation of the resources such as compute instances, storage, load balancers, DNS setup, security groups, network access controls, autoscaling, and much more.

What are the advantages of IaC patterns?

IaC enables teams to collaborate, edit, and distribute configurations with ease. IaC also ensures consistent environments every time. Ability to version configuration changes is another reason why IaC is gaining traction because configuration can be stored in VCS like Github or Gitlab.

Infrastructure as Code promotes cloud-first or cloud-native approach to resource management. This approach emphasizes resilience, elasticity, and availability by automating resource provisioning and setup. Standardization and consistency are enforced allowing developers to create production-like environments on-demand. Automated deployment reduces human-error which is common when managing complex infrastructure.

Integration of new services and features is greatly simplified because developers and DevOps professionals can create environments and test new features with relatively quick feedback.

Platform-agnostic tools like Terraform allow management of resources from multiple providers (e.g. AWS+Azure+GCP) in one place.

Terraform’s purpose and multi-cloud / provider-agnostic benefits

Cloud hosting took internet by storm. It brought in a new paradigm of how people use IT infrastructure. Resources are expendable in this paradigm. They are created, modified, scaled, and destroyed when needed.

This is a stark difference from conventional managed infrastructure where organization would need to buy and setup physical hardware. Expanding infrastructure this way meant that it took weeks or months to add additional servers or databases. Initial cost was very large and very few organizations had the resources to do it.

Cloud enabled provisioning of resources within minutes and paying only for what you use allowed startups to bring their products to market in record time.

Terraforms aims to provide a consolidated view of resources while also allowing teams to collaboratively and safely change or deploy infrastructure. IaC provides convenient and automated management of resources through API.

Terraform is often used to create and manage infrastructure for SaaS (Software as a Service), PaaS (Platform as a Service), and IaaS (Infrastructure as a Service). All of these models rely on standardized and consistent deployment of new resources while making sure that there is a high degree of consistency.

Another big reason for Terraform’s popularity is the fact that it is provider-agnostic. It is not uncommon for organizations to have a hybrid infrastructure with some resources residing in one or more cloud hosting providers (eg AWS+Snowflake) and some resources being in a privately-owned datacenter.

So, to summarize Terraform’s purpose:

  • Unify resources from one or more providers
  • Create a high-level abstraction of resources
  • Allow teams to make changes to infrastructure in a safe and predictable fashion
  • Allow versioning of infrastructure using VSC like Github
  • Separate planning from execution (dry runs)
  • Allow infrastructure management through API
  • Be provider-agnostic
  • Support creation of consistent environments on-demand
  • Support parallel management of resources
  • Standardize configurations

Benefits of state

Terraform state stores the record of your managed infrastructure.

During execution Terraform will check the state of the currently running resources and evaluate any changes between current state and revised state. An output from Terraform (console or file) will indicate if any changes were detected. If there are changes that need to be applied, Terraform will ask for approval to proceed with modifying resources. This process will only affect resources marked for change, existing infrastructure will remain as is.

There is also a really good article from spacelift.io that covers IaC benefits in great detail. I recommend reading it too.

#

This covers the first two objectives of the exam preparation. The next chapter would deal with Terraform basics. Since it is called β€˜Basics’ I took the liberty of adding articles about basic structure of a Terraform configuration file and a breakdown of each module. Objective 3 will be a doozy and it will probably be broken down into several articles due to the amount of material I intend to cover.

Thank you for reading and see you in the next chapter!

Top comments (0)

πŸ‘€ Just want to lurk?

Β 
That's fine, you can still create an account and turn on features like 🌚 dark mode.