문서 목차
이 페이지에서목차

dns-management

도메인을 서버에 연결하거나 주소 연결 문제를 해결할 때 사용합니다. AWS Route53의 DNS 레코드와 서브도메인을 추가·수정·삭제하고 연결 결과를 확인합니다.

한마디로#

AWS Route53의 DNS 레코드와 서브도메인을 추가·수정·삭제하고 연결 결과를 확인합니다.

무엇을·언제#

  • 무엇을 해 주나요?
    • 새로운 하위 주소(예: myapp.unibook.co.kr)를 만들어 실제 서버와 연결해 줍니다.
    • 기존 주소가 가리키는 곳을 바꾸거나, 더 이상 쓰지 않는 주소를 정리합니다.
    • 두 개의 도메인(주 도메인 unibook.co.kr, 예전 도메인 laputa.im)을 함께 관리합니다.
    • 주소가 제대로 연결됐는지 확인하는 점검 절차를 제공합니다.
  • 언제 작동하나요?
    • 새 하위 주소(딥링크, 앱 호스팅 등)를 추가할 때
    • DNS 기록을 수정하거나 삭제할 때
    • 도메인을 옮기는 작업(도메인 이전)을 할 때

핵심 용어#

용어쉬운 설명
DNS사람이 읽는 웹주소를 컴퓨터가 찾아갈 실제 위치로 바꿔 주는 인터넷 전화번호부
Route53아마존(AWS)이 제공하는 DNS 관리 서비스. 이 전화번호부를 보관하는 곳
DNS Record(레코드)전화번호부 안의 한 줄. "이 주소는 저 서버로 연결" 같은 항목 하나
Subdomain(하위 주소) 큰 주소 앞에 붙는 이름. 예: app.unibook.co.kr의 app 부분
Hosted Zone한 도메인에 속한 모든 레코드를 담아 두는 묶음(주소록 한 권)
CNAME"이 주소는 다른 주소와 같은 곳을 가리킨다"라고 별명을 연결하는 방식
A record주소를 실제 서버의 숫자 주소(IP)로 직접 연결하는 방식
TTL이 연결 정보를 얼마 동안 기억해 둘지 정하는 시간(초)
ACM Certificate(인증서)주소가 안전(https) 연결임을 보증하는 보안 증명서
ALB / CloudFront사용자의 접속을 받아 주는 입구 역할의 AWS 서비스
Terraform이런 인프라 설정을 코드로 적어 두고 자동으로 적용하는 도구
Production / Staging실제 사용자용 환경(운영) / 출시 전 시험용 환경(스테이징)
DNS propagation(전파)바뀐 주소 정보가 전 세계 인터넷에 퍼져 적용되는 과정

Manages Route53 DNS records with Terraform. Multi-domain support (primary + secondary domain).

Triggers#

  • Add new subdomains (deep links, Firebase Hosting, etc.)
  • Modify/delete DNS records
  • Domain migration

Domain Structure#

Hosted Zones#

DomainZone IDPurpose
unibook.co.krZ0775776240YOL7IYBNYHPrimary (currently used)
laputa.imZ0911207339KKWN48L9BWSecondary (legacy)

Certificates (ACM)#

PurposeRegionNotes
ALBap-northeast-2*.unibook.co.kr wildcard
CloudFront us-east-1 *.unibook.co.kr wildcard (CloudFront required)
Secondary ALBap-northeast-2*.laputa.im wildcard
Secondary CloudFrontus-east-1*.laputa.im wildcard

Subdomain Patterns#

SubdomainTargetProductionStaging
api ALB api.unibook.co.kr api-stg.unibook.co.kr
web ALB web.unibook.co.kr web-stg.unibook.co.kr
insights ALB insights.unibook.co.kr insights-stg.unibook.co.kr
storage CloudFront storage.unibook.co.kr storage-stg.unibook.co.kr
assets CloudFront assets.unibook.co.kr assets-stg.unibook.co.kr
app Firebase app.unibook.co.kr app-stg.unibook.co.kr
console Firebase console.unibook.co.kr console-stg.unibook.co.kr
deeplink ALB (CNAME) deeplink.unibook.co.kr stdeeplink.unibook.co.kr

DNS Record Addition Procedure#

1. Add Map Variable to variables.tf (root)#

variable "new_config" {
  description = "New domain configuration"
  type = map(object({
    subdomain = string
    target    = string
  }))
  default = {}
}

2. Set Values in config.auto.tfvars#

new_config = {
  "production" = {
    "subdomain" = "myapp"
    "target"    = "web.unibook.co.kr"
  }
  "staging" = {
    "subdomain" = "myapp-stg"
    "target"    = "web-stg.unibook.co.kr"
  }
}

3. Add Variable to environment Module variables.tf#

variable "new_subdomain" {
  description = "Subdomain for new service"
  type        = string
  default     = ""
}

variable "new_target" {
  description = "Target for new service"
  type        = string
  default     = ""
}

4. Add Resource to firebase-dns.tf (or new .tf file)#

# Primary domain
resource "aws_route53_record" "new_service" {
  count = var.enable_route53 && var.enable_primary_dns && var.new_subdomain != "" ? 1 : 0

  zone_id         = var.hosted_zone_id
  name            = var.new_subdomain
  type            = "CNAME"
  ttl             = "60"
  records         = [var.new_target]
  allow_overwrite = true
}

# Secondary domain
resource "aws_route53_record" "new_service_secondary" {
  count = var.enable_route53 && var.secondary_domain != null && var.new_subdomain != "" ? 1 : 0

  zone_id         = var.secondary_hosted_zone_id
  name            = var.new_subdomain
  type            = "CNAME"
  ttl             = "60"
  records         = ["${var.new_subdomain}.${var.secondary_domain}"]
  allow_overwrite = true
}

5. Pass Variables in main.tf#

module "production_env" {
  # ...
  new_subdomain = lookup(var.new_config, "production", null) != null ? var.new_config["production"]["subdomain"] : ""
  new_target    = lookup(var.new_config, "production", null) != null ? var.new_config["production"]["target"] : ""
}

count Condition Patterns#

Primary Domain DNS#

count = var.enable_route53 && var.enable_primary_dns && var.<subdomain> != "" ? 1 : 0

Secondary Domain DNS#

count = var.enable_route53 && var.secondary_domain != null && var.<subdomain> != "" ? 1 : 0

Production-only Resources (Top domain alias, etc.)#

count = var.enable_route53 && var.enable_primary_dns && var.enable_top_domain_alias && <condition> ? 1 : 0

Verification#

# Check CNAME record
dig <subdomain>.unibook.co.kr CNAME +short

# Check A record
dig <subdomain>.unibook.co.kr A +short

# Direct Route53 query
aws route53 list-resource-record-sets \
  --hosted-zone-id <hosted-zone-id> \
  --query "ResourceRecordSets[?contains(Name, '<keyword>')]" \
  --output table

Checklist#

  • Add Map variable to root variables.tf
  • Set per-environment values in config.auto.tfvars
  • Add variables to environment module variables.tf
  • Define Route53 resources (primary + secondary)
  • Pass variables to each environment module in main.tf (lookup pattern)
  • Verify changes with terraform plan
  • Apply with terraform apply -target
  • Verify DNS propagation with dig or AWS CLI

검색어를 입력하면 문서를 찾습니다.

↑ ↓ 이동 · Enter 열기Esc 닫기