Skip to content

Commit

Permalink
Merge pull request #54 from terraform-providers/update-dependency
Browse files Browse the repository at this point in the history
update the dependecy for scaleway sdk
  • Loading branch information
nicolai86 authored Mar 31, 2018
2 parents 5c61352 + 62ead2b commit 492a5f3
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 280 deletions.
20 changes: 10 additions & 10 deletions scaleway/resource_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ func resourceScalewayIPCreate(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway

mu.Lock()
resp, err := scaleway.NewIP()
ip, err := scaleway.CreateIP()
mu.Unlock()
if err != nil {
return err
}

d.SetId(resp.IP.ID)
d.SetId(ip.ID)
return resourceScalewayIPUpdate(d, m)
}

func resourceScalewayIPRead(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway
log.Printf("[DEBUG] Reading IP\n")

resp, err := scaleway.GetIP(d.Id())
ip, err := scaleway.GetIP(d.Id())
if err != nil {
log.Printf("[DEBUG] Error reading ip: %q\n", err)
if serr, ok := err.(api.APIError); ok {
Expand All @@ -68,12 +68,12 @@ func resourceScalewayIPRead(d *schema.ResourceData, m interface{}) error {
return err
}

d.Set("ip", resp.IP.Address)
if resp.IP.Server != nil {
d.Set("server", resp.IP.Server.Identifier)
d.Set("ip", ip.Address)
if ip.Server != nil {
d.Set("server", ip.Server.Identifier)
}
if resp.IP.Reverse != nil {
d.Set("reverse", *resp.IP.Reverse)
if ip.Reverse != nil {
d.Set("reverse", *ip.Reverse)
}
return nil
}
Expand All @@ -93,8 +93,8 @@ func resourceScalewayIPUpdate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return err
}
if ip.IP.Reverse != nil {
d.Set("reverse", *ip.IP.Reverse)
if ip.Reverse != nil {
d.Set("reverse", *ip.Reverse)
} else {
d.Set("reverse", "")
}
Expand Down
8 changes: 4 additions & 4 deletions scaleway/resource_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testSweepIP(region string) error {
return fmt.Errorf("Error describing IPs in Sweeper: %s", err)
}

for _, ip := range ips.IPS {
for _, ip := range ips {
if err := scaleway.DeleteIP(ip.ID); err != nil {
return fmt.Errorf("Error deleting ip in Sweeper: %s", err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func testAccCheckScalewayIPExists(n string) resource.TestCheckFunc {
return err
}

if ip.IP.ID != rs.Primary.ID {
if ip.ID != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

Expand Down Expand Up @@ -171,8 +171,8 @@ func testAccCheckScalewayIPAttachment(n string, check func(string) bool, msg str
}

var serverID = ""
if ip.IP.Server != nil {
serverID = ip.IP.Server.Identifier
if ip.Server != nil {
serverID = ip.Server.Identifier
}
if !check(serverID) {
return fmt.Errorf("IP check failed: %q", msg)
Expand Down
28 changes: 9 additions & 19 deletions scaleway/resource_security_group.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scaleway

import (
"fmt"
"errors"
"log"

"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -53,7 +53,7 @@ func resourceScalewaySecurityGroupCreate(d *schema.ResourceData, m interface{})
EnableDefaultSecurity: d.Get("enable_default_security").(bool),
}

err := scaleway.PostSecurityGroup(req)
group, err := scaleway.CreateSecurityGroup(req)
if err != nil {
if serr, ok := err.(api.APIError); ok {
log.Printf("[DEBUG] Error creating security group: %q\n", serr.APIMessage)
Expand All @@ -62,28 +62,18 @@ func resourceScalewaySecurityGroupCreate(d *schema.ResourceData, m interface{})
return err
}

resp, err := scaleway.GetSecurityGroups()
if err != nil {
return err
}

for _, group := range resp.SecurityGroups {
if group.Name == req.Name {
d.SetId(group.ID)
break
}
}
d.SetId(group.ID)

if d.Id() == "" {
return fmt.Errorf("Failed to find created security group.")
return errors.New("failed to find created security group")
}

return resourceScalewaySecurityGroupRead(d, m)
}

func resourceScalewaySecurityGroupRead(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway
resp, err := scaleway.GetASecurityGroup(d.Id())
group, err := scaleway.GetSecurityGroup(d.Id())

if err != nil {
if serr, ok := err.(api.APIError); ok {
Expand All @@ -98,9 +88,9 @@ func resourceScalewaySecurityGroupRead(d *schema.ResourceData, m interface{}) er
return err
}

d.Set("name", resp.SecurityGroups.Name)
d.Set("description", resp.SecurityGroups.Description)
d.Set("enable_default_security", resp.SecurityGroups.EnableDefaultSecurity)
d.Set("name", group.Name)
d.Set("description", group.Description)
d.Set("enable_default_security", group.EnableDefaultSecurity)

return nil
}
Expand All @@ -117,7 +107,7 @@ func resourceScalewaySecurityGroupUpdate(d *schema.ResourceData, m interface{})
Description: d.Get("description").(string),
}

if err := scaleway.PutSecurityGroup(req, d.Id()); err != nil {
if _, err := scaleway.UpdateSecurityGroup(req, d.Id()); err != nil {
log.Printf("[DEBUG] Error reading security group: %q\n", err)

return err
Expand Down
16 changes: 8 additions & 8 deletions scaleway/resource_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func resourceScalewaySecurityGroupRuleCreate(d *schema.ResourceData, m interface
DestPortFrom: d.Get("port").(int),
}

rule, err := scaleway.PostSecurityGroupRule(d.Get("security_group").(string), req)
rule, err := scaleway.CreateSecurityGroupRule(d.Get("security_group").(string), req)
if err != nil {
if serr, ok := err.(api.APIError); ok {
log.Printf("[DEBUG] Error creating Security Group Rule: %q\n", serr.APIMessage)
Expand All @@ -104,7 +104,7 @@ func resourceScalewaySecurityGroupRuleCreate(d *schema.ResourceData, m interface

func resourceScalewaySecurityGroupRuleRead(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway
rule, err := scaleway.GetASecurityGroupRule(d.Get("security_group").(string), d.Id())
rule, err := scaleway.GetSecurityGroupRule(d.Get("security_group").(string), d.Id())

if err != nil {
if serr, ok := err.(api.APIError); ok {
Expand All @@ -119,11 +119,11 @@ func resourceScalewaySecurityGroupRuleRead(d *schema.ResourceData, m interface{}
return err
}

d.Set("action", rule.Rules.Action)
d.Set("direction", rule.Rules.Direction)
d.Set("ip_range", rule.Rules.IPRange)
d.Set("protocol", rule.Rules.Protocol)
d.Set("port", rule.Rules.DestPortFrom)
d.Set("action", rule.Action)
d.Set("direction", rule.Direction)
d.Set("ip_range", rule.IPRange)
d.Set("protocol", rule.Protocol)
d.Set("port", rule.DestPortFrom)

return nil
}
Expand All @@ -142,7 +142,7 @@ func resourceScalewaySecurityGroupRuleUpdate(d *schema.ResourceData, m interface
DestPortFrom: d.Get("port").(int),
}

if err := scaleway.PutSecurityGroupRule(req, d.Get("security_group").(string), d.Id()); err != nil {
if _, err := scaleway.UpdateSecurityGroupRule(req, d.Get("security_group").(string), d.Id()); err != nil {
log.Printf("[DEBUG] error updating Security Group Rule: %q", err)

return err
Expand Down
36 changes: 18 additions & 18 deletions scaleway/resource_security_group_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
var group api.SecurityGroups
var group api.SecurityGroup

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
}

func TestAccScalewaySecurityGroupRule_Count(t *testing.T) {
var group api.SecurityGroups
var group api.SecurityGroup

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -59,7 +59,7 @@ func TestAccScalewaySecurityGroupRule_Count(t *testing.T) {
})
}

func testAccCheckScalewaySecurityGroupsExists(n string, group *api.SecurityGroups) resource.TestCheckFunc {
func testAccCheckScalewaySecurityGroupsExists(n string, group *api.SecurityGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -71,14 +71,14 @@ func testAccCheckScalewaySecurityGroupsExists(n string, group *api.SecurityGroup
}

conn := testAccProvider.Meta().(*Client).scaleway
resp, err := conn.GetASecurityGroup(rs.Primary.ID)
resp, err := conn.GetSecurityGroup(rs.Primary.ID)

if err != nil {
return err
}

if resp.SecurityGroups.ID == rs.Primary.ID {
*group = resp.SecurityGroups
if resp.ID == rs.Primary.ID {
*group = *resp
return nil
}

Expand All @@ -100,8 +100,8 @@ func testAccCheckScalewaySecurityGroupRuleDestroy(s *terraform.State) error {
}

all_err := true
for _, group := range groups.SecurityGroups {
_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
for _, group := range groups {
_, err := client.GetSecurityGroupRule(group.ID, rs.Primary.ID)
all_err = all_err && err != nil
}

Expand All @@ -113,40 +113,40 @@ func testAccCheckScalewaySecurityGroupRuleDestroy(s *terraform.State) error {
return nil
}

func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.SecurityGroups) resource.TestCheckFunc {
func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.SecurityGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Unknown resource: %s", n)
}

client := testAccProvider.Meta().(*Client).scaleway
rule, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
rule, err := client.GetSecurityGroupRule(group.ID, rs.Primary.ID)
if err != nil {
return err
}

if rule.Rules.Action != "accept" {
if rule.Action != "accept" {
return fmt.Errorf("Wrong rule action")
}
if rule.Rules.Direction != "inbound" {
if rule.Direction != "inbound" {
return fmt.Errorf("wrong rule direction")
}
if rule.Rules.IPRange != "0.0.0.0/0" {
if rule.IPRange != "0.0.0.0/0" {
return fmt.Errorf("wrong rule IP Range")
}
if rule.Rules.Protocol != "TCP" {
if rule.Protocol != "TCP" {
return fmt.Errorf("wrong rule protocol")
}
if rule.Rules.DestPortFrom != 80 {
if rule.DestPortFrom != 80 {
return fmt.Errorf("Wrong port")
}

return nil
}
}

func testAccCheckScalewaySecurityGroupRuleExists(n string, group *api.SecurityGroups) resource.TestCheckFunc {
func testAccCheckScalewaySecurityGroupRuleExists(n string, group *api.SecurityGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]

Expand All @@ -159,13 +159,13 @@ func testAccCheckScalewaySecurityGroupRuleExists(n string, group *api.SecurityGr
}

client := testAccProvider.Meta().(*Client).scaleway
rule, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
rule, err := client.GetSecurityGroupRule(group.ID, rs.Primary.ID)

if err != nil {
return err
}

if rule.Rules.ID != rs.Primary.ID {
if rule.ID != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

Expand Down
14 changes: 7 additions & 7 deletions scaleway/resource_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testSweepSecurityGroup(region string) error {
return fmt.Errorf("Error describing security groups in Sweeper: %s", err)
}

for _, sg := range sgs.SecurityGroups {
for _, sg := range sgs {
if sg.OrganizationDefault {
continue
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func testAccCheckScalewaySecurityGroupDestroy(s *terraform.State) error {
continue
}

_, err := client.GetASecurityGroup(rs.Primary.ID)
_, err := client.GetSecurityGroup(rs.Primary.ID)

if err == nil {
return fmt.Errorf("Security Group still exists")
Expand All @@ -88,15 +88,15 @@ func testAccCheckScalewaySecurityGroupAttributes(n string) resource.TestCheckFun
}

client := testAccProvider.Meta().(*Client).scaleway
group, err := client.GetASecurityGroup(rs.Primary.ID)
group, err := client.GetSecurityGroup(rs.Primary.ID)
if err != nil {
return err
}

if group.SecurityGroups.Name != "public" {
if group.Name != "public" {
return fmt.Errorf("Security Group has wrong name")
}
if group.SecurityGroups.Description != "public gateway" {
if group.Description != "public gateway" {
return fmt.Errorf("Security Group has wrong description")
}

Expand All @@ -117,13 +117,13 @@ func testAccCheckScalewaySecurityGroupExists(n string) resource.TestCheckFunc {
}

client := testAccProvider.Meta().(*Client).scaleway
group, err := client.GetASecurityGroup(rs.Primary.ID)
group, err := client.GetSecurityGroup(rs.Primary.ID)

if err != nil {
return err
}

if group.SecurityGroups.ID != rs.Primary.ID {
if group.ID != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

Expand Down
Loading

0 comments on commit 492a5f3

Please sign in to comment.