terraform-course

Infrastructure as Code

Infrastructure as code is the practice and discipline of provisioning IT resources using a machine-readable configuration file. The types of infrastructure that may be covered by IaC can be both physical (bare-metal) or virtual machines.

Infrastructure as Code Tools

  1. Hashicorp Terraform
    • There is also an Open-Source fork of Terraform called OpenTofu
  2. Google Cloud Deployment Manager
  3. AWS Cloud Formation
  4. Azure Resource Manager

Infrastructure Lifecycle

Infrastructure lifecycle is a defined and distinct set of work phases which are used by DevOps Engineers to plan, design, build, test, deliver, maintain, and retire cloud infrastructure.

IaC’s role in Infrastructure Lifecycle

Non-Idempotent vs. Idempotent Changes to Configuration

As a DevOps engineer when I deploy my IaC configuration file it will provision and launch two virtual machines:

Provisioning vs Deployment vs Orchestration

Configuration Drift

Configuration “drift” is when configurations in an IT system gradually change over time. It often happens when undocumented or unapproved changes are made to software, hardward, and operating systems.

Going unnoticed, this can lead to larger issues including:

Luckily, you can detect configuration drift using a compliance tool (i.e. AWS Config, Azure Policies). Some providers may also have a feature you can enable which can alert you to possible configuration drift that may have happened. A big feature inside terraform is its ability to manage and track state. If you’ve detected configuration drift, correcting it may be possible using many of the same tools.

Some steps you can take to prevent the problem: - Immutable infrastructure: always create and destroy, never reuse. - Using methodologies like GitOps to version control IaC and peer review changes with Pull Requests.

GitOps

GitOps is used to automate the process of provisioning infrastructure and is built on three smaller practices.

  1. IaC - a git repository is used as the single source-of-truth for infrastructure definitions
  2. MRs - Merge Requests are used as the change mechanism for which infrastructure updates will occur
  3. CI/CD - Continuous Integration and Delivery is used to automate the deployment of infrastructure

GitOps Diagram

GitLab Article