IaC(Infrastructure as Code)는 인프라를 선언적 코드로 정의·프로비저닝·관리하는 방법이다. 수동 클릭 대신 코드로 서버, 네트워크, 데이터베이스를 생성해 일관성, 반복성, 버전 관리를 가능하게 한다.
IaC 도구 비교
hcl
# main.tf
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
backend "s3" {
bucket = "my-tfstate"
key = "prod/terraform.tfstate"
region = "ap-northeast-2"
}
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "production"
cidr = "10.0.0.0/16"
azs = ["ap-northeast-2a", "ap-northeast-2c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
enable_nat_gateway = true
single_nat_gateway = false
}
resource "aws_eks_cluster" "main" {
name = "production"
role_arn = aws_iam_role.eks.arn
vpc_config {
subnet_ids = module.vpc.private_subnets
}
}
bash
terraform init # 초기화 및 프로바이더 다운로드
terraform plan # 변경사항 미리보기 (dry run)
terraform apply # 실제 적용
terraform destroy # 리소스 삭제
관련 개념