Skip to content

Commit

Permalink
Merge pull request #73 from jbe-dw/fixZoneUpdate
Browse files Browse the repository at this point in the history
Enable more fields to be updated with zone update
  • Loading branch information
mbag authored Feb 8, 2022
2 parents 25d9507 + 94a95fe commit 7432364
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
10 changes: 9 additions & 1 deletion powerdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ type ZoneInfo struct {
SoaEditAPI string `json:"soa_edit_api"`
}

// ZoneInfoUpd is a limited subset for supported updates
type ZoneInfoUpd struct {
Name string `json:"name"`
Kind string `json:"kind"`
SoaEditAPI string `json:"soa_edit_api,omitempty"`
Account string `json:"account"`
}

// Record represents a PowerDNS record object
type Record struct {
Name string `json:"name"`
Expand Down Expand Up @@ -388,7 +396,7 @@ func (client *Client) CreateZone(zoneInfo ZoneInfo) (ZoneInfo, error) {
}

// UpdateZone updates a zone
func (client *Client) UpdateZone(name string, zoneInfo ZoneInfo) error {
func (client *Client) UpdateZone(name string, zoneInfo ZoneInfoUpd) error {
body, err := json.Marshal(zoneInfo)
if err != nil {
return err
Expand Down
16 changes: 9 additions & 7 deletions powerdns/resource_powerdns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func resourcePDNSZoneCreate(d *schema.ResourceData, meta interface{}) error {
}

d.SetId(createdZoneInfo.ID)
resourcePDNSZoneRead(d, meta)

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

client := meta.(*Client)

zoneInfo := ZoneInfo{}
shouldUpdate := false
if d.HasChange("kind") {
zoneInfo := ZoneInfoUpd{}
if d.HasChange("kind") || d.HasChange("account") || d.HasChange("soa_edit_api") {
zoneInfo.Name = d.Get("name").(string)
zoneInfo.Kind = d.Get("kind").(string)
shouldUpdate = true
}
zoneInfo.Account = d.Get("account").(string)
zoneInfo.SoaEditAPI = d.Get("soa_edit_api").(string)

if shouldUpdate {
return client.UpdateZone(d.Id(), zoneInfo)
c := client.UpdateZone(d.Id(), zoneInfo)
resourcePDNSZoneRead(d, meta)
return c
}
return nil
}
Expand Down

0 comments on commit 7432364

Please sign in to comment.