Route53のレコードをTerraformでimport

概要

もし手動でRoute53へレコードを追加していても、Terraformを使っている場合にimportでコード管理することが可能です。

手順

terraform準備

  name    = "_xxxxxxxxxx.dev.example.com"
  type    = "CNAME"
  zone_id = aws_route53_zone.example-com.zone_id
  records = ["_XXXXX.acm-validations.aws"]
  ttl     = 300
}

実行の仕方

import

Acquiring state lock. This may take a few moments...
aws_route53_record.dev-example-com_acm-validate: Importing from ID "A12345XXX__xxxxxxxxxx.dev.example.com_CNAME"...
aws_route53_record.dev-example-com_acm-validate: Import prepared!
  Prepared aws_route53_record for import
aws_route53_record.dev-example-com_acm-validate: Refreshing state... [id=A12345XXX__xxxxxxxxxx.dev.example.com_CNAME]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.