Skip to content

fix: null_resource SSH PEM 키 의존성 제거 → SSM RunCommand 방식으로 전환 #41

@Hexeong

Description

@Hexeong

문제 상황

PR #37 머지 후 Terraform Apply (CD) 가 prod/stage 환경 모두 실패하고 있습니다.

근본 원인

modules/app_stack/ec2.tfnull_resource.update_nginx, null_resource.update_side_infra 두 리소스가 SSH connection 블록에서 로컬 PEM 키 파일을 직접 읽습니다.

# modules/app_stack/ec2.tf line 74, 118
connection {
  type        = "ssh"
  user        = "ubuntu"
  host        = aws_instance.api_server.public_ip
  private_key = file(var.ssh_key_path)  # "../../solid-connection-server-2.pem"
}

var.ssh_key_path는 개발자 로컬 머신 기준 상대 경로(../../solid-connection-server-2.pem)이며, GitHub Actions 러너 환경에는 해당 파일이 존재하지 않아 file() 함수 자체가 실패합니다.

Error: Invalid function argument
on ../../modules/app_stack/ec2.tf line 75, in resource "null_resource" "update_nginx":
75:     private_key = file(var.ssh_key_path)
Invalid value for "path" parameter: no file exists at "../../solid-connection-server-2.pem"

이번 PR에서 처음 터진 이유

PR #37이 nginx_setup.sh.tftpl을 수정해 null_resource.update_nginxtriggers.script_hash가 변경되었고, Terraform이 해당 리소스를 tainted 상태로 replace 시도하면서 SSH connection을 실제로 실행하려다 에러가 발생했습니다. 이전 apply들은 해당 리소스에 변경이 없어 실행을 건너뛰었기 때문에 문제가 드러나지 않았습니다.

영향 범위

리소스 파일 상태
`null_resource.update_nginx` `modules/app_stack/ec2.tf:59` triggers 변경 시마다 실패
`null_resource.update_side_infra` `modules/app_stack/ec2.tf:97` triggers 변경 시마다 실패

두 리소스 모두 동일한 구조로, 어느 쪽이든 triggers 변경이 생기면 CD가 막힙니다.

해결 방향

SSH + PEM 키 방식을 제거하고, SSM RunCommand 방식으로 전환합니다.

  • PEM 키 파일 없이 IAM 권한만으로 EC2에 명령 실행 가능
  • null_resource + SSH provisioner 제거
  • local-exec에서 aws ssm send-command로 스크립트 전송 및 실행
  • var.ssh_key_path 변수 제거

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions