Skip to content

refactor: DB EC2 AMI 갱신 시 인스턴스 교체 방지 - #72

Merged
Hexeong merged 1 commit into
mainfrom
refactor/70-db-ec2-ami-ignore-changes
Aug 18, 2026
Merged

refactor: DB EC2 AMI 갱신 시 인스턴스 교체 방지#72
Hexeong merged 1 commit into
mainfrom
refactor/70-db-ec2-ami-ignore-changes

Conversation

@Hexeong

@Hexeong Hexeong commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

관련 이슈

작업 내용

  • 운영 중인 DB EC2가 AMI 변경만으로 재생성되지 않도록 aws_instance.db_serverlifecycle.ignore_changesami를 추가했습니다.

특이 사항

  • 현재 aws_instance.db_serverignore_changesami가 없어 db_ec2_ami_id 변경만으로 destroy 후 create가 발생합니다. aws_volume_attachmentstop_instance_before_detaching = true가 적용되어 있어 MySQL이 실행 중인 상태에서 인스턴스가 정지됩니다.
  • #70에서 AWS CLI와 MySQL 복구 도구를 포함한 Custom AMI를 생성할 예정인데, 사용자가 있는 상황에서 AMI ID를 반영하면 운영 DB가 중단됩니다. AMI ID 반영과 인스턴스 교체를 분리하기 위해 이번 변경을 먼저 진행합니다.
  • 이 구성에서는 새 AMI ID를 반영해도 기존 인스턴스가 유지되며, 이후 어떤 사유로든 인스턴스가 재생성되는 시점에 새 AMI가 적용됩니다. 예기치 않은 EC2 장애로 재생성되는 경우에도 AWS CLI와 복구 도구가 포함된 상태로 기동되므로 백업 파이프라인의 생존성이 높아집니다.
  • aws_instance.api_server는 이미 동일하게 ami를 무시하고 있어 두 인스턴스의 관리 방식이 통일됩니다.
  • 계획된 인스턴스 교체는 #67의 EC2 장애 복구 리허설 시점에 진행합니다.

트레이드오프

  • ignore_changes = [ami]는 코드상의 AMI ID와 실제 인스턴스의 AMI가 달라지는 drift를 지속적으로 숨깁니다. 실제 적용 시점은 운영 문서에 별도로 기록해야 합니다.
  • API EC2가 이미 같은 상태로 운영되고 있어 새로 발생하는 관리 부담은 아니라고 판단했습니다.

리뷰 요구사항 (선택)

  • terraform plan 결과에 aws_instance.db_server의 교체가 포함되지 않는지 확인 부탁드립니다.
  • AMI drift를 코드가 아닌 운영 문서로 관리하는 방식이 적절한지 의견 부탁드립니다.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 문서화
    • 데이터베이스 서버의 AMI 변경을 무시하는 인프라 설정에 설명 주석을 추가했습니다.
    • 실행 동작이나 배포 결과에는 변경 사항이 없습니다.

- 운영 중인 DB EC2가 AMI 변경만으로 재생성되지 않도록 lifecycle ignore_changes에 ami 추가
- API EC2와 동일한 방식으로 통일

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e0511ad-69d1-4ab1-9e85-e8ef8ce3fa08

📥 Commits

Reviewing files that changed from the base of the PR and between 16f1c23 and 23df9d4.

📒 Files selected for processing (1)
  • modules/app_stack/db_ec2.tf

Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

aws_instance.db_server의 기존 AMI 변경 무시 설정에 운영 동작을 설명하는 주석을 추가했습니다. Terraform 동작은 변경하지 않았습니다.

Changes

DB 서버 AMI 설정

Layer / File(s) Summary
AMI lifecycle 동작 설명
modules/app_stack/db_ec2.tf
운영 중 인스턴스 교체와 재생성 시 AMI 적용 동작을 설명하는 주석을 추가했습니다.

Estimated code review effort: 1 (사소함) | ~2 minutes

Merge Risk: 🔵 Low · up to 23df9

This change prevents an AMI ID update from replacing the running DB instance, avoiding an unintended interruption, but it also leaves AMI drift to be managed operationally and still needs plan confirmation for unintended changes; it is mergeable with explicit owner follow-up.

Possibly related issues

  • solid-connection/solid-connection-infra#70 — 동일한 aws_instance.db_server의 AMI 관련 lifecycle.ignore_changes 설정을 다룹니다.

Suggested reviewers: gyuhyeok99

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 DB EC2의 AMI 갱신 시 인스턴스 교체를 방지하는 주요 변경사항을 명확하게 설명합니다.
Description check ✅ Passed 관련 이슈, 작업 내용, 특이 사항, 트레이드오프, 리뷰 요구사항을 포함하여 변경 목적과 운영 영향을 충분히 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/70-db-ec2-ami-ignore-changes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Terraform Plan: stage

No changes. Your infrastructure matches the configuration.

전체 plan 결과는 보안을 위해 댓글에 포함되지 않습니다. 워크플로우 실행 아티팩트를 확인하세요.

@Hexeong Hexeong self-assigned this Aug 16, 2026
@github-actions

Copy link
Copy Markdown

Terraform Plan: prod

No changes. Your infrastructure matches the configuration.

전체 plan 결과는 보안을 위해 댓글에 포함되지 않습니다. 워크플로우 실행 아티팩트를 확인하세요.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23df9d455b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

lifecycle {
# AMI 갱신이 운영 중인 DB EC2를 교체하지 않도록 무시하고, 인스턴스가 재생성되는 시점에 새 AMI를 적용합니다.
ignore_changes = [
ami,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ensure replacements use the configured AMI

When db_ami_id changes and the existing instance is later recreated because of -replace, tainting, or another replacement-triggering attribute, Terraform retains the prior state value for attributes in ignore_changes; consequently, the replacement is launched with the old AMI rather than the newly configured one. This contradicts the lifecycle comment and means the planned recovery rehearsal—or an emergency rebuild after AMI drift—will not install the expected backup tooling and can fail entirely if the old AMI has been deregistered. The AMI ignore must therefore be removed or conditionally disabled before replacement, or the rollout needs another mechanism that explicitly supplies the new AMI.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

의견 감사합니다. 하지만 공식 문서를 확인해본 결과 ignore_changes는 create를 계획할 때는 해당 인자를 고려하고, update를 계획할 때만 무시한다고 되어 있습니다. 따라서 해당 의견은 반영하지 않도록 하겠습니다.

@lsy1307 lsy1307 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니당 이상 없습니당

@Hexeong
Hexeong merged commit bc220a7 into main Aug 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants