Terraform은 HashiCorp가 개발한 오픈소스 Infrastructure as Code(IaC) 도구다. 클라우드 인프라를 코드로 정의하고, 버전 관리·자동화·재현성을 확보한다.
IaC의 장점
수동 클릭 → 코드로 정의
✓ 버전 관리 (Git)
✓ 코드 리뷰로 인프라 변경 검토
✓ 동일한 환경 재현 가능
✓ CI/CD 파이프라인과 통합
기본 문법 (HCL)
hcl
# main.tf
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_instance" "web" {
ami = "ami-0abcdef1234567890"
instance_type = "t3.micro"
tags = {
Name = "web-server"
Env = "production"
}
}
resource "aws_s3_bucket" "static" {
bucket = "my-unique-bucket-name"
}
output "instance_ip" {
value = aws_instance.web.public_ip
}
기본 명령어
bash
terraform init # 프로바이더 초기화
terraform plan # 변경 사항 미리 보기
terraform apply # 인프라 생성/수정
terraform destroy # 인프라 삭제
terraform state list # 현재 상태 확인
관련 개념
- •AWS EC2 — Terraform으로 관리하는 인프라
- •Docker — Terraform으로 컨테이너 인프라 관리
- •CI/CD — Terraform을 파이프라인에 통합
참고문헌
- •Terraform 공식 문서: terraform.io
- •Yevgeniy Brikman. Terraform: Up & Running, 3rd Ed.