본문 바로가기

퍼블릭 클라우드

[Terraform] 테라폼 Route 53 도메인 등록

반응형

Route 53 도메인 등록

route53.tf 파일 생성

$ vim route53.tf
####################Route 53 Zone(도메인) 등록
resource "aws_route53_zone" "sangchulkr" {
    name = "sangchul.kr"
    comment = "sangchul.kr"
}

####################Route 53 MX Record(서브 도메인) 등록(G. Suite)
resource "aws_route53_record" "sangchulkr_mx" {
    zone_id = aws_route53_zone.sangchulkr.id
    name    = "sangchul.kr"
    type    = "MX"
    ttl     = "3600"
    records = [
        "1 ASPMX.L.GOOGLE.COM.",
        "5 ALT1.ASPMX.L.GOOGLE.COM.",
        "5 ALT2.ASPMX.L.GOOGLE.COM.",
        "10 ALT3.ASPMX.L.GOOGLE.COM.",
        "10 ALT4.ASPMX.L.GOOGLE.COM."
    ]
}

###################Route 53 A Record(서브 도메인) 등록
resource "aws_route53_record" "sangchulkr_sub1" {
    zone_id = aws_route53_zone.sangchulkr.zone_id
    name    = "sub1.sangchul.kr"
    type    = "A"
    ttl     = "300"
    records = ["111.111.111.111"]
}

####################Route 53 CNAME Record(서브 도메인) 등록
resource "aws_route53_record" "sangchulkr_sub2" {
    zone_id = aws_route53_zone.sangchulkr.zone_id
    name    = "sub2.sangchul.kr"
    type    = "CNAME"
    ttl     = "300"
    records = ["sub1.sangchul.kr"]
}

####################Route 53 네임서버 출력
output "nameservers" {
    value = aws_route53_zone.sangchulkr.name_servers
}

terraform apply 명령 실행

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

...


Plan: 4 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_route53_zone.sangchulkr: Creating...
aws_route53_zone.sangchulkr: Still creating... [10s elapsed]
aws_route53_zone.sangchulkr: Still creating... [20s elapsed]
aws_route53_zone.sangchulkr: Still creating... [30s elapsed]
aws_route53_zone.sangchulkr: Creation complete after 34s [id]
aws_route53_record.sangchulkr_sub1: Creating...
aws_route53_record.sangchulkr_sub2: Creating...
aws_route53_record.sangchulkr_mx: Creating...
aws_route53_record.sangchulkr_sub2: Still creating... [10s elapsed]
aws_route53_record.sangchulkr_sub1: Still creating... [10s elapsed]
aws_route53_record.sangchulkr_mx: Still creating... [10s elapsed]
aws_route53_record.sangchulkr_sub1: Still creating... [20s elapsed]
aws_route53_record.sangchulkr_mx: Still creating... [20s elapsed]
aws_route53_record.sangchulkr_sub2: Still creating... [20s elapsed]
aws_route53_record.sangchulkr_mx: Still creating... [30s elapsed]
aws_route53_record.sangchulkr_sub1: Still creating... [30s elapsed]
aws_route53_record.sangchulkr_sub2: Still creating... [30s elapsed]
aws_route53_record.sangchulkr_mx: Creation complete after 36s [id=sangchul.kr_MX]
aws_route53_record.sangchulkr_sub1: Creation complete after 36s [id=sub1.sangchul.kr_A]
aws_route53_record.sangchulkr_sub2: Creation complete after 37s [id=sub2.sangchul.kr_CNAME]

Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

 

 

728x90
반응형