DEV Community

Fred Richards
Fred Richards

Posted on • Updated on

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    = ""
  name    = ""
  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


// cat 

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

variable "pdns_server_url" {
  description = "current api url"
  default     = ""
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 @
;; 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
;            IN      TXT

;; ANSWER SECTION:     900     IN      TXT     "It's not DNS."     900     IN      TXT     "There's no way it's DNS."     900     IN      TXT     "Oh no, DNS."

;; Query time: 76 msec

;; 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... []
Enter fullscreen mode Exit fullscreen mode

Top comments (0)