Skip to content

Commit

Permalink
Merge pull request #48 from terraform-providers/reverse-ip
Browse files Browse the repository at this point in the history
add support for managing ip reverse attribute
  • Loading branch information
nicolai86 authored Mar 15, 2018
2 parents 38a7b39 + c79b921 commit 2d9b42d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
24 changes: 24 additions & 0 deletions scaleway/resource_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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))
Expand Down
17 changes: 16 additions & 1 deletion scaleway/resource_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,23 @@ 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(
testAccCheckScalewayIPExists("scaleway_ip.base"),
testAccCheckScalewayIPAttachment("scaleway_ip.base", func(serverID string) bool {
return serverID != ""
}, "attachment failed"),
resource.TestCheckResourceAttr(
"scaleway_ip.base", "reverse", ""),
),
},
resource.TestStep{
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions vendor/github.com/nicolai86/scaleway-sdk/ip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=",
Expand Down
7 changes: 4 additions & 3 deletions website/docs/r/ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2d9b42d

Please sign in to comment.