diff --git a/scaleway/resource_ip.go b/scaleway/resource_ip.go index cfcd99bf3..c9accd149 100644 --- a/scaleway/resource_ip.go +++ b/scaleway/resource_ip.go @@ -29,6 +29,11 @@ func resourceScalewayIP() *schema.Resource { Computed: true, Description: "The ipv4 address of the ip", }, + "reverse": { + Type: schema.TypeString, + Optional: true, + Description: "The ipv4 reverse dns", + }, }, } } @@ -67,6 +72,9 @@ func resourceScalewayIPRead(d *schema.ResourceData, m interface{}) error { if resp.IP.Server != nil { d.Set("server", resp.IP.Server.Identifier) } + if resp.IP.Reverse != nil { + d.Set("reverse", *resp.IP.Reverse) + } return nil } @@ -76,6 +84,22 @@ func resourceScalewayIPUpdate(d *schema.ResourceData, m interface{}) error { mu.Lock() defer mu.Unlock() + if d.HasChange("reverse") { + log.Printf("[DEBUG] Updating IP %q reverse to %q\n", d.Id(), d.Get("reverse").(string)) + ip, err := scaleway.UpdateIP(api.UpdateIPRequest{ + ID: d.Id(), + Reverse: d.Get("reverse").(string), + }) + if err != nil { + return err + } + if ip.IP.Reverse != nil { + d.Set("reverse", *ip.IP.Reverse) + } else { + d.Set("reverse", "") + } + } + if d.HasChange("server") { if d.Get("server").(string) != "" { log.Printf("[DEBUG] Attaching IP %q to server %q\n", d.Id(), d.Get("server").(string)) diff --git a/scaleway/resource_ip_test.go b/scaleway/resource_ip_test.go index 685ff405d..a08838bfb 100644 --- a/scaleway/resource_ip_test.go +++ b/scaleway/resource_ip_test.go @@ -68,6 +68,14 @@ func TestAccScalewayIP_Basic(t *testing.T) { testAccCheckScalewayIPExists("scaleway_ip.base"), ), }, + resource.TestStep{ + Config: testAccCheckScalewayIPConfig_Reverse, + Check: resource.ComposeTestCheckFunc( + testAccCheckScalewayIPExists("scaleway_ip.base"), + resource.TestCheckResourceAttr( + "scaleway_ip.base", "reverse", "www.google.de"), + ), + }, resource.TestStep{ Config: testAccCheckScalewayIPAttachConfig, Check: resource.ComposeTestCheckFunc( @@ -75,6 +83,8 @@ func TestAccScalewayIP_Basic(t *testing.T) { testAccCheckScalewayIPAttachment("scaleway_ip.base", func(serverID string) bool { return serverID != "" }, "attachment failed"), + resource.TestCheckResourceAttr( + "scaleway_ip.base", "reverse", ""), ), }, resource.TestStep{ @@ -172,11 +182,16 @@ func testAccCheckScalewayIPAttachment(n string, check func(string) bool, msg str } } -var testAccCheckScalewayIPConfig = ` +var testAccCheckScalewayIPConfig_Reverse = ` resource "scaleway_ip" "base" { + reverse = "www.google.de" } ` +var testAccCheckScalewayIPConfig = ` +resource "scaleway_ip" "base" {} +` + var testAccCheckScalewayIPConfig_Count = ` resource "scaleway_ip" "base" { count = 2 diff --git a/vendor/github.com/nicolai86/scaleway-sdk/ip.go b/vendor/github.com/nicolai86/scaleway-sdk/ip.go index 21f8c5884..f462bc5b6 100644 --- a/vendor/github.com/nicolai86/scaleway-sdk/ip.go +++ b/vendor/github.com/nicolai86/scaleway-sdk/ip.go @@ -68,6 +68,46 @@ func (s *API) GetIP(ipID string) (*GetIP, error) { return &ip, nil } +type UpdateIPRequest struct { + ID string + Reverse string +} + +func (s *API) UpdateIP(req UpdateIPRequest) (*GetIP, error) { + var update struct { + Address string `json:"address"` + ID string `json:"id"` + Reverse *string `json:"reverse"` + Organization string `json:"organization"` + Server *string `json:"server"` + } + + ip, err := s.GetIP(req.ID) + if err != nil { + return nil, err + } + update.Address = ip.IP.Address + update.ID = ip.IP.ID + update.Organization = ip.IP.Organization + update.Server = nil + if ip.IP.Server != nil { + update.Server = &ip.IP.Server.Identifier + } + update.Reverse = nil + if req.Reverse != "" { + update.Reverse = &req.Reverse + } + resp, err := s.PutResponse(s.computeAPI, fmt.Sprintf("ips/%s", req.ID), update) + if err != nil { + return nil, err + } + body, err := s.handleHTTPError([]int{http.StatusOK}, resp) + if err = json.Unmarshal(body, &ip); err != nil { + return nil, err + } + return ip, nil +} + // GetIPS returns a GetIPS func (s *API) GetIPS() (*GetIPS, error) { resp, err := s.GetResponsePaginate(s.computeAPI, "ips", url.Values{}) diff --git a/vendor/vendor.json b/vendor/vendor.json index 250f5e6f3..ae093de72 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -558,10 +558,10 @@ "revisionTime": "2016-10-03T17:45:16Z" }, { - "checksumSHA1": "HHM/BHbGWERr3u0mwCsj+587zBY=", + "checksumSHA1": "TFoFErx/R+wtqKsYAY+mzbLtbCA=", "path": "github.com/nicolai86/scaleway-sdk", - "revision": "1a18b6a1c6a3434c88b908254958f1281cf3ac2c", - "revisionTime": "2018-03-15T02:26:51Z" + "revision": "1e466487c486466a8ba2cfb48fac56788a8095ea", + "revisionTime": "2018-03-15T04:05:42Z" }, { "checksumSHA1": "u5s2PZ7fzCOqQX7bVPf9IJ+qNLQ=", diff --git a/website/docs/r/ip.html.markdown b/website/docs/r/ip.html.markdown index 33630e34a..50ae31d59 100644 --- a/website/docs/r/ip.html.markdown +++ b/website/docs/r/ip.html.markdown @@ -22,15 +22,16 @@ resource "scaleway_ip" "test_ip" {} The following arguments are supported: * `server` - (Optional) ID of server to associate IP with - -Field `server` is editable. +* `reverse` - (Optional) Reverse DNS of the IP ## Attributes Reference The following attributes are exported: -* `id` - id of the new resource +* `id` - ID of the new resource * `ip` - IP of the new resource +* `server` - ID of the associated server resource +* `reverse` - reverse DNS setting of the IP resource ## Import