GoDaddy Domain + Google Cloud DNS

  • Post author:
  • Post category:칼럼
  • Post comments:0 Comments
  • Post last modified:February 8, 2020

시나리오

  • GoDaddy에서 test.com 도메인을 구입했다.
  • test.com을 GoDaddy가 아닌 Google Cloud DNS에서 관리하기 위해 네임서버를 이전하려 한다.
  • Terraform을 이용해 Google Cloud Platform에 Provisioning한다.

코드

Terraform 코드는 다음과 같다.

variable "dns_name" {
  default = "test.com"
}

variable "godaddy_key" {
}

variable "godaddy_secret" {
}

resource "google_dns_managed_zone" "prod" {
  name        = "prod-zone"
  dns_name    = "${var.dns_name}."
  description = "Production DNS zone"
}

data "template_file" "nameservers" {
  template = "${replace(join(",", formatlist("\"%s\"", google_dns_managed_zone.prod.name_servers)), ".\"", "\"")}"
}

resource "null_resource" "godaddy" {
  triggers {
    run_always = "${data.template_file.nameservers}"
  }

  provisioner "local-exec" {
   command = "curl -X PATCH -H 'Authorization: sso-key ${var.godaddy_key}:${var.godaddy_secret}' -H 'Content-Type: application/json' -d '{ \"nameServers\": [ ${data.template_file.nameservers.rendered} ] }' https://api.godaddy.com/v1/domains/${var.dns_name}"
 }
}
  • google_dns_managed_zonetest.com을 Google Cloud DNS에 등록한다.
  • test.com을 등록하면 Cloud DNS측 네임서버 주소 목록이 ${google_dns_managed_zone.prod.name_servers}에 담겨 나온다. GoDaddy - Nameservers
  • GoDaddy의 API를 curl로 호출해 test.com을 조회할 때 Cloud DNS측 네임서버를 쓰도록 한다.

terraform apply를 실행해 Provisioning 하고 나면 GoDaddy에 새로운 네임서버가 등록된다.

Google Cloud Platform - Networking

참고 문서

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments