LogoSkills

terraform-plan

Terraform Plan 실행 및 변경 분석. apply 전에 인프라 변경 사항을 미리 보거나 검토할 때 사용합니다.

Terraform Plan Execution and Analysis#

한마디로#

이 스킬은 서버나 클라우드 설정을 실제로 바꾸기 전에 "이렇게 바뀔 거예요"라고 미리 보여 주는 미리보기 기능입니다. 마치 새 가구를 사기 전에 방에 어떻게 놓일지 미리 그려 보는 것과 같습니다. 실제로 바꾸는 것이 아니라 변경 사항을 점검만 하므로 안전하게 확인할 수 있습니다. 예상치 못한 삭제나 변경이 없는지 미리 걸러 주는 안전 장치 역할을 합니다.

무엇을·언제#

  • 무엇을 해 주나요?
    • 클라우드 인프라(서버, 네트워크 등) 설정을 실제로 적용하기 전에 무엇이 추가·변경·삭제되는지 목록으로 보여 줍니다.
    • 일부 구성 요소가 빠져 있어 미리보기가 실패하는 흔한 문제(Lambda ZIP 파일 누락)를 자동으로 해결해 줍니다.
    • 특정 부분만 골라서 미리보기하거나, 작업 환경(운영/스테이징 등)을 바꿔 가며 확인할 수 있습니다.
  • 언제 작동하나요?
    • 설정 코드를 바꾼 뒤 잘 바뀌는지 확인하고 싶을 때
    • 어떤 변경이 어디까지 영향을 주는지 파악하고 싶을 때
    • 전체가 아닌 일부 자원만 골라 미리보기하고 싶을 때

핵심 용어#

용어쉬운 설명
Terraform클라우드 인프라(서버, 네트워크 등)를 코드로 정의하고 관리하는 도구
Plan실제로 바꾸기 전에 "무엇이 바뀔지" 미리 보여 주는 미리보기 단계
Apply미리보기에서 확인한 변경을 실제로 적용하는 단계
Lambda서버를 직접 두지 않고 필요할 때만 실행되는 작은 클라우드 프로그램
ZIP (placeholder)프로그램 파일을 압축한 묶음. 진짜 파일이 없을 때 임시로 채워 넣는 빈 묶음을 placeholder라고 함
-target 옵션전체가 아니라 지정한 일부만 골라서 미리보기하는 설정
destroy자원을 삭제한다는 뜻. 예상에 없던 삭제가 있으면 위험 신호
workspace운영·스테이징 등 서로 다른 작업 환경을 구분해 두는 공간
module여러 설정을 묶어 재사용할 수 있게 만든 설정 꾸러미

Runs Terraform plan to preview infrastructure changes. Automatically resolves Lambda ZIP file missing issues.

Triggers#

  • Plan verification after Terraform code changes
  • Infrastructure change impact analysis
  • Plan specific resources with -target option

Lambda ZIP Placeholder Auto-Handling#

Problem#

The filebase64sha256() function evaluates expressions for all resources regardless of -target option. Since Lambda ZIP files are only built in CI, running plan locally causes file missing errors.

Solution#

Analyzes ${path.module}/../../../lambda/ paths within modules and creates placeholder ZIPs at the correct locations.

# Module-relative path resolution
# modules/pdf_processing/../../../lambda/python/ → deploy/aws/lambda/python/
# Resolved relative to module file location, NOT the terraform execution directory

See "Local Placeholder Generation" in lambda-management/SKILL.md for the placeholder ZIP generation script

ZIP File Path Mapping#

ModulePath (from module)Actual Path (from deploy/aws/)
pdf_processing ${path.module}/../../../lambda/python/pdf_router/build/pdf-router.zip lambda/python/pdf_router/build/pdf-router.zip
pdf_processing ${path.module}/../../../lambda/python/pdf_processor/build/pdf-processor.zip lambda/python/pdf_processor/build/pdf-processor.zip
pdf_processing ${path.module}/../../../lambda/python/pdf_page_processor/build/pdf-page-processor.zip lambda/python/pdf_page_processor/build/pdf-page-processor.zip
pdf_processing ${path.module}/../../../lambda/python/pdf_aggregator/build/pdf-aggregator.zip lambda/python/pdf_aggregator/build/pdf-aggregator.zip
pdf_processing ${path.module}/../../../lambda/python/pdf_prepare_batches/build/pdf-prepare-batches.zip lambda/python/pdf_prepare_batches/build/pdf-prepare-batches.zip
pdf_processing ${path.module}/../../../lambda/python/layers/pymupdf/build/x86_64/pymupdf-layer.zip lambda/python/layers/pymupdf/build/x86_64/pymupdf-layer.zip
batch_processing ${path.module}/../../../lambda/python/book_batch_processor/build/book-batch-processor.zip lambda/python/book_batch_processor/build/book-batch-processor.zip
message abspath(var.push_forwarder_lambda_path) lambda/dart/sqs_to_sns/build/x86_64/sqs_to_sns.zip
message abspath(var.fcm_topic_manager_lambda_path) lambda/go/fcm_topic_manager/build/x86_64/fcm_topic_manager.zip

fileexists() Check Status#

Modulefileexists()Notes
messagesource_code_hash = null if file missing
batch_processingbatch_processor_zip_exists local variable
pdf_processing ❌ (called directly in lambda.tf) File always required

Plan Execution Patterns#

Plan Specific Resources Only#

# Check module names (module block names in main.tf)
# production_env, staging_env, development_env (NOT production, staging, etc.)

terraform plan \
  -target= ' module.production_env[0].aws_route53_record.deeplink '   \
  -target= ' module.staging_env[0].aws_route53_record.deeplink '

Workspace Switch#

# Check current workspace
terraform workspace list

# Switch workspace (production, staging, default)
terraform workspace select production

Note: This project manages environments with a workspace + enable_*_server flag combination. Within each workspace, feature flags conditionally create per-environment resources.

Checklist#

  • Lambda ZIP placeholders created (under deploy/aws/lambda/)
  • terraform init success verified
  • Impact scope limited with -target option
  • Verify no destroy resources in plan results
  • Verify expected resource change count