DNS Haiku with TXT Records and Terraform

flrichar profile image Fred Richards Updated on ・2 min read

Recently, I wanted to test the basic powerdns terraform provider, and whether I could write multiple TXT record entries for one name.

Hey, what do you know, it worked. I just had little test messages in there, and decided, maybe it would be neat to put the "DNS Haiku" in a text record. I used the latest Terraform, 0.12.12.

Here's my code. Notice I changed the haiku just a little.

// don't forget to put vars in separate file
// for pdns_api_key & pdns_server_url

provider "powerdns" {
  api_key    = var.pdns_api_key
  server_url = var.pdns_server_url

// example of multiple TXT records for name
resource "powerdns_record" "text" {
  zone    = "geexology.org."
  name    = "text.geexology.org."
  type    = "TXT"
  ttl     = 900
  records = ["\"It's not DNS.\"","\"There's no way it's DNS.\"","\"Oh no, DNS.\""]

Example tfvars.tf.

// cat tfvars.tf 

variable "pdns_api_key" {
  description = "current api key"
  default     = "notrealzlolputyourkeyheresilly"

variable "pdns_server_url" {
  description = "current api url"
  default     = ""

The reply from the server for the dig query.

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.el7 <<>> txt text.geexology.org @
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22695
;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

; EDNS: version: 0, flags:; udp: 1680
;text.geexology.org.            IN      TXT

text.geexology.org.     900     IN      TXT     "It's not DNS."
text.geexology.org.     900     IN      TXT     "There's no way it's DNS."
text.geexology.org.     900     IN      TXT     "Oh no, DNS."

;; Query time: 76 msec

;; WHEN: Wed Oct 23 06:19:43 EDT 2019
;; MSG SIZE  rcvd: 134

When refreshing state, or performing terraform plan the id looks like this.

powerdns_record.text: Refreshing state... [id=text.geexology.org.:::TXT]

Posted on Oct 23 '19 by:

flrichar profile

Fred Richards


Technologist. Into Cloud Architecture, IaC, ansible, terraform. Docker, Linux, Networking. Like protocols, experimenting with golang. Can non-developers benefit from thinking like developers?


markdown guide