ci: Terraform GitOps 파이프라인 (OIDC + 원격 state + 승인 게이트)#6
Merged
Conversation
- S3 원격 백엔드(use_lockfile) 도입 — CI 러너가 공유 state 사용 (DynamoDB 불필요) - GitHub Actions 워크플로: PR→terraform plan 코멘트, dev 머지(push)→apply - apply는 GitHub Environment 'dev-apply' 수동 승인 게이트 통과 후 실행 - AWS 인증은 OIDC로 role(sw-hub-dev-gha-terraform) assume — 장기 액세스 키 없음 - providers: CI에서 aws_profile="" 이면 null 처리(OIDC 임시자격증명 사용) - EC2 ami ignore_changes — most_recent AMI 갱신이 인스턴스를 교체하지 않도록 (자동 apply 안전장치)
# Conflicts: # terraform/modules/ec2/main.tf
Terraform Plan
|
- cloudflare 터널: import 시 secret을 API로 다시 못 읽어 매 apply마다 재생성(라이브 터널 끊김)으로 잡히는 문제 → lifecycle ignore_changes=[secret] - RDS: auto-minor-version-upgrade로 16.13으로 오른 마이너 버전을 terraform이 16.11로 되돌리려다 apply 실패 → ignore_changes=[engine_version] - import 후 plan: 0 to destroy (터널/RDS 무중단)
Terraform Plan
|
- OIDC 기반 인프라 배포 파이프라인 흐름 - 자격증명/시크릿 위치 정리, 런타임/앱 인증 흐름 - 부트스트랩 리소스, 드리프트 처리(ignore_changes) 메모, 일상 운영
Terraform Plan
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
Terraform GitOps 파이프라인을 추가합니다. PR →
terraform plan코멘트, dev 머지 →terraform apply(수동 승인 게이트), 인증은 GitHub OIDC(장기 키 없음)로 동작합니다.변경 사항 (코드)
terraform/environments/dev/backend.tf— S3 원격 백엔드(use_lockfile로 잠금, DynamoDB 불필요).github/workflows/terraform.yml— plan(PR)/apply(dev push) 워크플로, OIDC role assumeproviders.tf— CI에서aws_profile=""이면null처리(OIDC 임시자격증명 사용)modules/ec2/main.tf—amiignore_changes(most_recent AMI 갱신이 인스턴스를 교체하지 않도록)이미 완료한 부트스트랩
sw-hub-dev-tfstate-850919911012(버전관리·암호화·퍼블릭차단)dev/terraform.tfstate, 36 리소스)1. OIDC provider + CI role 생성
→ 결과 ARN
arn:aws:iam::850919911012:role/sw-hub-dev-gha-terraform은 워크플로에 이미 박혀 있음.2. GitHub Environment
dev-apply만들기 (승인 게이트)Settings → Environments → New environment →
dev-apply:dev만 허용3. Repository Secrets 추가 (Settings → Secrets → Actions)
CLOUDFLARE_API_TOKENTF_VAR_CLOUDFLARE_ACCOUNT_IDTF_VAR_CLOUDFLARE_ZONE_NAMETF_VAR_CLOUDFLARE_HOSTNAME4. 첫 plan 리뷰 (중요)
현재 마이그레이션한 state는 cloudflare 튜닝(터널) 도입 이전 시점이라, 첫
terraform plan에 cloudflare 리소스가 "생성 예정"으로 뜰 수 있습니다(이미 라이브엔 cloudflared 동작 중). 그대로 apply하지 말고, 기존 터널을terraform import하거나 상태를 맞춘 뒤 진행하세요.비고