5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【小ネタ】Terraformで256文字以上の長いTXTレコード(DKIMなど)をRoute53に定義したい場合は

Last updated at Posted at 2022-10-03

Terraformで長いDKIMなどのTXTレコードをRoute53に定義したい場合、長すぎるせいでRoute53に拒否されます。

そもそもTXTレコードは255文字を超えてデータを保持できません。

The format of each constituent string within the DNS TXT record is a single length byte, followed by 0-255 bytes of text data.

RFC 6763. DNS-Based Service Discovery

こういう場合、Route53のヘルプ では下記のように記載されていますが、

DKIM キーの値を 2 つの部分に分割し、各部分を二重引用符で囲みます。例えば、"long_string" の値は "long_""string" に分割します。

これをやろうとして、いざTerraformでの書き方となると、「ちょっとよくわからない」となるので、下記を参考にしてください。

resource "aws_route53_record" "too_long_dkim" {
  // ...

  type = "TXT"
  records = [
    # 255文字に入り切らないので、分割する
    format("%s\"\"%s",
      "適当に255文字を超えない範囲の文字列",
      "残りの文字列"
    )
  ]
}

結局、foobar という文字列を分割する場合、 records = ["foo\"\"bar"] という文字列を入れればいいということです。records = ["foo", "bar"] とやってはいけません。

5
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?