Day 1 - Terraform 입문
설치 · 기본 구조 · init / plan / apply / destroy
목차
학습 목표
- IaC와 Terraform 역할 설명
init→plan→apply순서 실행- state 파일이 무엇인지 이해
설치
# macOS
brew install terraform
terraform version
프로젝트 구조
terraform-lab/
├── main.tf
├── variables.tf # (Day 2)
├── outputs.tf # (Day 2)
└── terraform.tfstate # apply 후 생성 (gitignore 권장)
첫 실습 local_file
main.tf:
terraform {
required_version = ">= 1.5.0"
}
resource "local_file" "hello" {
content = "hello terraform"
filename = "${path.module}/hello.txt"
}
cd terraform-lab
terraform init
terraform plan
terraform apply # yes
cat hello.txt
terraform destroy # 정리
명령 흐름
| 명령 | 역할 |
|---|---|
terraform init | 프로바이더 다운로드 |
terraform fmt | 코드 포맷 |
terraform validate | 문법 검증 |
terraform plan | 실행 계획 |
terraform apply | 실제 생성/변경 |
terraform destroy | 리소스 삭제 |