테라폼 시작 가이드 (Terraform Initial Setup Guide)
이 문서는 Terraform을 처음 시작하는 사용자를 위한 기본 환경 구축 가이드입니다.
AWS VPC 리소스를 예제로, 실제 인프라 코드 작성 및 적용 과정을 설명합니다.
명확한 단계별 설명을 통해 Terraform의 기본 흐름을 이해할 수 있도록 구성되어 있습니다.
Terraform 기본 시작 가이드 (pmpubp01dp01 기준)
✅ 0단계: 작업 폴더 준비
mkdir -p ~/terraform/pmpubp01dp01 cd ~/terraform/pmpubp01dp01 code .
✅ 1단계: Terraform 설정 파일 만들기
1. provider.tf
provider "aws" { region = "ap-northeast-1" access_key = var.aws_access_key secret_key = var.aws_secret_key }
2. variables.tf
variable "aws_access_key" { description = "AWS Access Key" type = string sensitive = true }</p> <p>variable "aws_secret_key" { description = "AWS Secret Key" type = string sensitive = true }
3. terraform.tfvars
aws_access_key = "AKIAXXXXXXXX" aws_secret_key = "xxxxxxxxxxxxxxxxxxxx"
주의:
terraform.tfvars
는 절대 외부 공유하지 말 것..gitignore
에 반드시 추가!
✅ 2단계: 기본 VPC 만들기
1. main.tf
resource "aws_vpc" "main" { cidr_block = "10.254.0.0/16" enable_dns_support = true enable_dns_hostnames = true</p> <p>tags = { Name = "vpc-pmpubp01dp01" Environment = "dev" } }
✅ 3단계: Terraform 실행
terraform init terraform plan terraform apply
✅ 4단계: 메모 예시
✅ [2025-04-08]
- 작업 환경: VS Code + WSL2(Ubuntu 24.04)
- 작업 내용: provider.tf, variables.tf, tfvars 생성
- 실행: terraform init → plan → apply
- 결과: vpc-pmpubp01dp01 생성 완료 (CIDR: 10.254.0.0/16)
메모는
.md
파일이나 Obsidian, Typora 등에 기록하면 좋아요.