> For the complete documentation index, see [llms.txt](https://terraform201.devart.tv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://terraform201.devart.tv/2./domain.md).

# Domain 등록하기

## 도메인 구매

도메인 구매는 AWS Route 53에서 손쉽게 구매하실 수 있습니다. 외부에서 구매한 도메인을 사용하셔도 무방합니다.

본 실습에서는 `devops-art-factory.com` 라는 도메인을 구입했다는 가정하에 정의하겠습니다.&#x20;

### Host zone 등록

코드 경로는 `terraform/route53/art-id/devops-art-factory.com` 입니다. **만약 도메인을 AWS 상에서 구매하셨다면 기본 host zone을 AWS에서 자동으로 생성해줍니다. 이 경우에는 해당 리소스를** [**import**](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone#import) **하시는 것이 좋습니다.**

{% code title="vim terraform/route53/art-id/devops-art-factory.com/route53.tf" %}

```hcl
# AWS Route53 Zone
resource "aws_route53_zone" "devopsartfactory_com" {
  name     = "devops-art-factory.com"
  comment  = "HostedZone created by Route53 Registrar - Manged Terraform"
}
```

{% endcode %}

## 서로 다른 Account에서 subdomain 등록하기

서비스를 운영하다보면, 환경별로 서로 다른 계정에서 도메인을 함께 쓰고 싶은 경우가 있습니다. 예를 들어 A 계정에서 example.com을 사용하고 있는데, B라는 계정에서 prod.example.com 도메인을 사용하는 것입니다. 이 경우에는 서브 도메인의 네임서버 리스트를 상위 도메인에 등록하면 됩니다.

정리하면, 과정은 아래와 같습니다.

1. &#x20;B 계정에 `prod.example.com` 이라는 aws route53 zone을 생성합니다.
2. &#x20;A 계정에서 `example.com` route53 zone에 NS 레코드로 prod.example.com 의 네임서버들을 등록합니다.

1번 과정 코드는 아래와 같습니다.

{% code title="vim terraform/route53/art-prod/prod.devops-art-factory.com/route53.tf" %}

```hcl
resource "aws_route53_zone" "prod_devops-art-factory_com" {
  name = "prod.devops-art-factory.com."
}
```

{% endcode %}

생성이 완료되면 아래 그림처럼 hosted zone이 생성되고, 레코드로 Name server들이 생성됩니다.

![](/files/-MZcCJiO-nmHPsPOHfdY)

2번 작업은 아래와 같습니다.

1번에서 생성된 name server list를 코드 `records`에 넣어주시면 됩니다.

{% code title="vim terraform/route53/art-id/devops-art-factory.com/route53.tf" %}

```hcl
resource "aws_route53_record" "ns_prod_devops-art-factory_com" {
  zone_id = aws_route53_zone.devopsartfactory_com.zone_id
  name    = "prod"
  type    = "NS"
  ttl     = "300"
  records = [
    # Refer to Route53 Zone for `prod.devops-art-factory.com in `art-id`
    "ns-316.awsdns-39.com.",
    "ns-1936.awsdns-50.co.uk.", 
    "ns-982.awsdns-58.net.",
    "ns-1191.awsdns-20.org."
  ]
}
```

{% endcode %}

이렇게 등록이 마무리 되면,  `*.prod.example.com` 형태로 ACM도 생성할 수 있고, sub domain을 추가로 만들어서 사용하실 수 있습니다.&#x20;

작동 원리는 DNS 질의 원리와 동일합니다.

1\) `prod.example.com` 을 질의하게 되면 `.com` 도메인에게 `example.com` 의 Name Server IP를 물어봅니다.

2\)  A 계정에 있는 `example.com` 네임서버가 이를 받아서 위에서 등록한 `prod.example.com` 네임서버 리스트 중에 하나를 반납해줍니다.&#x20;

3\) B 계정에 있는 `prod.example.com` 네임서버는 질의 받은 레코드에 대한 값을 반환합니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://terraform201.devart.tv/2./domain.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
