# 1. Homebrew가 설치되어 있는지 확인brew --version# Homebrew가 없다면 설치/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"# 2. Terraform 설치brew tap hashicorp/tapbrew install hashicorp/tap/terraform# 3. 설치 확인terraform version
예상 출력:
Terraform v1.7.0
on darwin_arm64 # M1/M2/M3 Mac
# 또는
on darwin_amd64 # Intel Mac
🔄 업데이트
# Terraform 업데이트brew upgrade hashicorp/tap/terraform# 특정 버전 설치brew install hashicorp/tap/terraform@1.6
🐧 Linux 설치 (Ubuntu/Debian)
# 1. HashiCorp GPG 키 추가wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg# 2. 저장소 추가echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list# 3. 패키지 업데이트 및 설치sudo apt updatesudo apt install terraform# 4. 설치 확인terraform version
🪟 Windows 설치
Chocolatey 사용
# PowerShell (관리자 권한)choco install terraform# 설치 확인terraform version
# 환경 변수 설정export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"export AWS_DEFAULT_REGION="ap-northeast-2"# Terraform 실행terraform plan
영구 설정 (bashrc/zshrc):
# ~/.zshrc 또는 ~/.bashrc에 추가echo 'export AWS_DEFAULT_REGION="ap-northeast-2"' >> ~/.zshrcsource ~/.zshrc
🧪 자격증명 테스트
# AWS 계정 정보 확인aws sts get-caller-identity# 예상 출력:{ "UserId": "AIDACKCEVSQ6C2EXAMPLE", "Account": "123456789012", "Arn": "arn:aws:iam::123456789012:user/terraform-user"}
3. 첫 번째 프로젝트
🎯 Hello Terraform 프로젝트
실습 목표
간단한 S3 버킷을 생성하여 Terraform 워크플로우를 경험합니다.
📁 프로젝트 구조
# 프로젝트 디렉토리 생성mkdir ~/terraform-hellocd ~/terraform-hello
📄 main.tf 작성
# Terraform 버전 및 Provider 설정terraform { required_version = ">= 1.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } }}# AWS Provider 설정provider "aws" { region = "ap-northeast-2" # 서울 리전}# S3 버킷 생성resource "aws_s3_bucket" "my_first_bucket" { bucket = "my-terraform-bucket-${formatdate("YYYYMMDDhhmmss", timestamp())}" tags = { Name = "My First Terraform Bucket" Environment = "Learning" ManagedBy = "Terraform" }}# S3 버킷 버저닝 활성화resource "aws_s3_bucket_versioning" "my_first_bucket_versioning" { bucket = aws_s3_bucket.my_first_bucket.id versioning_configuration { status = "Enabled" }}# 출력output "bucket_name" { description = "생성된 S3 버킷 이름" value = aws_s3_bucket.my_first_bucket.id}output "bucket_arn" { description = "S3 버킷 ARN" value = aws_s3_bucket.my_first_bucket.arn}
🚀 실행하기
# 1. 초기화terraform init
출력:
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Installing hashicorp/aws v5.31.0...
- Installed hashicorp/aws v5.31.0
Terraform has been successfully initialized!
Terraform will perform the following actions:
# aws_s3_bucket.my_first_bucket will be created
+ resource "aws_s3_bucket" "my_first_bucket" {
+ bucket = "my-terraform-bucket-20251231143022"
+ id = (known after apply)
+ arn = (known after apply)
...
}
# aws_s3_bucket_versioning.my_first_bucket_versioning will be created
+ resource "aws_s3_bucket_versioning" "my_first_bucket_versioning" {
...
}
Plan: 2 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ bucket_arn = (known after apply)
+ bucket_name = "my-terraform-bucket-20251231143022"
# 5. 적용terraform apply
입력:
Do you want to perform these actions?
Enter a value: yes