Skip to content

Commit 9ffb499

Browse files
author
Stanislau Petrusiou
committed
Added RRSet comments support
1 parent c97d5a1 commit 9ffb499

File tree

4 files changed

+109
-5
lines changed

4 files changed

+109
-5
lines changed

powerdns/client.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,17 @@ type Record struct {
178178

179179
// ResourceRecordSet represents a PowerDNS RRSet object
180180
type ResourceRecordSet struct {
181-
Name string `json:"name"`
182-
Type string `json:"type"`
183-
ChangeType string `json:"changetype"`
184-
TTL int `json:"ttl"` // For API v1
185-
Records []Record `json:"records,omitempty"`
181+
Name string `json:"name"`
182+
Type string `json:"type"`
183+
ChangeType string `json:"changetype"`
184+
TTL int `json:"ttl"` // For API v1
185+
Records []Record `json:"records,omitempty"`
186+
Comments []Comment `json:"comments,omitempty"`
187+
}
188+
189+
type Comment struct {
190+
Content string `json:"content,omitempty"`
191+
Account string `json:"account,omitempty"`
186192
}
187193

188194
type zonePatchRequest struct {

powerdns/resource_powerdns_record.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ func resourcePDNSRecord() *schema.Resource {
5757
ForceNew: true,
5858
Description: "For A and AAAA records, if true, create corresponding PTR.",
5959
},
60+
61+
"comment": {
62+
Type: schema.TypeSet,
63+
Elem: &schema.Resource{
64+
Schema: map[string]*schema.Schema{
65+
"content": {
66+
Type: schema.TypeString,
67+
Required: true,
68+
ForceNew: true,
69+
},
70+
"account": {
71+
Type: schema.TypeString,
72+
Required: true,
73+
ForceNew: true,
74+
},
75+
},
76+
},
77+
Optional: true,
78+
ForceNew: true,
79+
Description: "A comment about an RRSet.",
80+
},
6081
},
6182
}
6283
}
@@ -70,6 +91,21 @@ func resourcePDNSRecordCreate(d *schema.ResourceData, meta interface{}) error {
7091
TTL: d.Get("ttl").(int),
7192
}
7293

94+
comments := d.Get("comment").(*schema.Set).List()
95+
if len(comments) > 0 {
96+
commentObjs := make([]Comment, 0, len(comments))
97+
for _, comment := range comments {
98+
commentMap := comment.(map[string]interface{})
99+
commentObjs = append(
100+
commentObjs,
101+
Comment{
102+
Content: commentMap["content"].(string),
103+
Account: commentMap["account"].(string),
104+
})
105+
}
106+
rrSet.Comments = commentObjs
107+
}
108+
73109
zone := d.Get("zone").(string)
74110
ttl := d.Get("ttl").(int)
75111
recs := d.Get("records").(*schema.Set).List()

powerdns/resource_powerdns_record_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,22 @@ func TestAccPDNSRecord_TXT(t *testing.T) {
394394
})
395395
}
396396

397+
func TestAccPDNSRecord_WithComments(t *testing.T) {
398+
resource.Test(t, resource.TestCase{
399+
PreCheck: func() { testAccPreCheck(t) },
400+
Providers: testAccProviders,
401+
CheckDestroy: testAccCheckPDNSRecordDestroy,
402+
Steps: []resource.TestStep{
403+
{
404+
Config: testPDSNRecordWithComments,
405+
Check: resource.ComposeTestCheckFunc(
406+
testAccCheckPDNSRecordExists("powerdns_record.test-comments"),
407+
),
408+
},
409+
},
410+
})
411+
}
412+
397413
func TestAccPDNSRecord_ALIAS(t *testing.T) {
398414
resourceName := "powerdns_record.test-alias"
399415
resourceID := `{"zone":"sysa.xyz.","id":"alias.sysa.xyz.:::ALIAS"}`
@@ -654,3 +670,22 @@ resource "powerdns_record" "test-soa" {
654670
ttl = 3600
655671
records = [ "something.something. hostmaster.sysa.xyz. 2019090301 10800 3600 604800 3600" ]
656672
}`
673+
674+
const testPDSNRecordWithComments = `
675+
resource "powerdns_record" "test-comments" {
676+
zone = "sysa.xyz."
677+
name = "comment.sysa.xyz."
678+
type = "A"
679+
ttl = 60
680+
records = [ "1.1.1.1" ]
681+
682+
comment {
683+
content = "Test comment #1"
684+
account = "Test account #1"
685+
}
686+
687+
comment {
688+
content = "Test comment #2"
689+
account = "Test account #2"
690+
}
691+
}`

website/docs/r/record.html.markdown

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ resource "powerdns_record" "foobar" {
4242
}
4343
```
4444

45+
### Record with comments
46+
An example creating a record with comments:
47+
48+
```hcl
49+
# Add a record with comments
50+
resource "powerdns_record" "foobar" {
51+
zone = "example.com."
52+
name = "www.example.com."
53+
type = "A"
54+
ttl = 60
55+
records = [ "1.1.1.1" ]
56+
57+
comment {
58+
content = "Example comment #1"
59+
account = "Example account #1"
60+
}
61+
62+
comment {
63+
content = "Example comment #2"
64+
account = "Example account #2"
65+
}
66+
}
67+
```
68+
4569
### MX record example
4670
The following example shows, how to setup MX record with a priority of `10`.
4771
Please note that priority is not set as other `powerdns_record` properties; rather, it's part of the string that goes into `records` list.
@@ -145,6 +169,9 @@ The following arguments are supported:
145169
* `ttl` - (Required) The TTL of the record.
146170
* `records` - (Required) A string list of records.
147171
* `set_ptr` - (Optional) [**_Deprecated in PowerDNS 4.3.0_**] A boolean (true/false), determining whether API server should automatically create PTR record in the matching reverse zone. Existing PTR records are replaced. If no matching reverse zone, an error is thrown.
172+
* `comment` - (Optional) A comment about an RRSet.
173+
* `content` - (Required) The content of the comment.
174+
* `account` - (Required) The account of the comment.
148175

149176
### Attribute Reference
150177

0 commit comments

Comments
 (0)