Infrastructure as Code is the practice of managing and provisioning infrastructure through code, using configuration files and automation.

What is Infrastructure as Code?

IAC allows defining, managing, and provisioning infrastructure programmatically, providing versioning, reuse, and automation.

Declarative

  • Terraform: Multi-cloud provisioning
  • CloudFormation: AWS infrastructure
  • Azure Resource Manager: Azure infrastructure
  • Google Deployment Manager: GCP infrastructure

Imperative

  • Ansible: Configuration automation
  • Chef: Configuration management
  • Puppet: Infrastructure automation
  • SaltStack: Configuration management

Example with Terraform

Basic Configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
provider "aws" {
  region = "us-west-2"
}

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1d0"
  instance_type = "t2.micro"
  
  tags = {
    Name = "WebServer"
  }
}

resource "aws_security_group" "web" {
  name = "web-sg"
  
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

References