Skip to content

Commit 7432364

Browse files
authored
Merge pull request #73 from jbe-dw/fixZoneUpdate
Enable more fields to be updated with zone update
2 parents 25d9507 + 94a95fe commit 7432364

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

powerdns/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ type ZoneInfo struct {
185185
SoaEditAPI string `json:"soa_edit_api"`
186186
}
187187

188+
// ZoneInfoUpd is a limited subset for supported updates
189+
type ZoneInfoUpd struct {
190+
Name string `json:"name"`
191+
Kind string `json:"kind"`
192+
SoaEditAPI string `json:"soa_edit_api,omitempty"`
193+
Account string `json:"account"`
194+
}
195+
188196
// Record represents a PowerDNS record object
189197
type Record struct {
190198
Name string `json:"name"`
@@ -388,7 +396,7 @@ func (client *Client) CreateZone(zoneInfo ZoneInfo) (ZoneInfo, error) {
388396
}
389397

390398
// UpdateZone updates a zone
391-
func (client *Client) UpdateZone(name string, zoneInfo ZoneInfo) error {
399+
func (client *Client) UpdateZone(name string, zoneInfo ZoneInfoUpd) error {
392400
body, err := json.Marshal(zoneInfo)
393401
if err != nil {
394402
return err

powerdns/resource_powerdns_zone.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func resourcePDNSZoneCreate(d *schema.ResourceData, meta interface{}) error {
123123
}
124124

125125
d.SetId(createdZoneInfo.ID)
126+
resourcePDNSZoneRead(d, meta)
126127

127128
return nil
128129
}
@@ -167,15 +168,16 @@ func resourcePDNSZoneUpdate(d *schema.ResourceData, meta interface{}) error {
167168

168169
client := meta.(*Client)
169170

170-
zoneInfo := ZoneInfo{}
171-
shouldUpdate := false
172-
if d.HasChange("kind") {
171+
zoneInfo := ZoneInfoUpd{}
172+
if d.HasChange("kind") || d.HasChange("account") || d.HasChange("soa_edit_api") {
173+
zoneInfo.Name = d.Get("name").(string)
173174
zoneInfo.Kind = d.Get("kind").(string)
174-
shouldUpdate = true
175-
}
175+
zoneInfo.Account = d.Get("account").(string)
176+
zoneInfo.SoaEditAPI = d.Get("soa_edit_api").(string)
176177

177-
if shouldUpdate {
178-
return client.UpdateZone(d.Id(), zoneInfo)
178+
c := client.UpdateZone(d.Id(), zoneInfo)
179+
resourcePDNSZoneRead(d, meta)
180+
return c
179181
}
180182
return nil
181183
}

0 commit comments

Comments
 (0)