클라우드
테라폼에서 RDS 메세지 구독 설정 시 주의 사항
Firewall
2024. 9. 20. 19:07
RDS 구독 메세지를 테라폼을 적용해서 사용 중인데 리소스를 찾지 못했던 경험을 공유 합니다.
이번에는 source_ids 를 정할때 aws 의 ids 가 아닌 identifier 를 입력해야 합니다. 자꾸 ids 를 다시 확인하라고 해서, 문제 해결에 시간이 걸렸습니다.
문법이나 내용은 맞는 것 같은데 실제 리소스를 찾지 못할때는 아래처럼 환경 설정이 어떻게 되어 있나 확인하고 적절한 리소스를 대입해서 찾아보면 좋습니다.
terraform state show aws_db_instance.logdb01
정상적으로 rds 에 sns 구독을 연결 시키는 코드입니다.
resource "aws_sns_topic" "rds_events_topic" {
name = "rds-events-topic"
}
resource "aws_sns_topic_subscription" "email_subscription" {
topic_arn = aws_sns_topic.rds_events_topic.arn
protocol = "email"
endpoint = "email@email.co.kr" # Recieve E-mail
depends_on = [aws_sns_topic.rds_events_topic] # SNS topic depend
}
resource "aws_db_event_subscription" "rds_event_subscription" {
name = "rds-event-subscription"
sns_topic = aws_sns_topic.rds_events_topic.arn
source_type = "db-instance"
event_categories = ["availability", "configuration change", "failover", "failure", "maintenance", "notification", "recovery", "restoration"]
source_ids = [aws_db_instance.logdb01.identifier,
aws_db_instance.gamedb01.identifier
]
depends_on = [
aws_db_instance.logdb01, #instance depend. Can be deleted.
aws_db_instance.gamedb01,
aws_sns_topic_subscription.email_subscription
]
tags = {
Name = "rds-event-subscription"
}
}