DEV Community

Fred Richards
Fred Richards

Posted on • Edited on

4

DNS Haiku with TXT Records and Terraform

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.\""]
}
Enter fullscreen mode Exit fullscreen mode

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     = "http://127.0.0.1:8087"
}
Enter fullscreen mode Exit fullscreen mode

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 @172.29.100.102
;; 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

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1680
;; QUESTION SECTION:
;text.geexology.org.            IN      TXT

;; ANSWER SECTION:
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
;; SERVER: 172.29.100.102#53(172.29.100.102)

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

Enter fullscreen mode Exit fullscreen mode

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

powerdns_record.text: Refreshing state... [id=text.geexology.org.:::TXT]
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay