Skip to content

Commit

Permalink
Merge pull request #9387 from nicolai86/feat/scaleway-import
Browse files Browse the repository at this point in the history
provider/scaleway: add support for importing resources
  • Loading branch information
jen20 authored Oct 18, 2016
2 parents 7fb8abd + fc4c848 commit fc2d973
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 13 deletions.
28 changes: 28 additions & 0 deletions builtin/providers/scaleway/import_scaleway_ip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package scaleway

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccScalewayIP_importBasic(t *testing.T) {
resourceName := "scaleway_ip.base"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewayIPConfig,
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
28 changes: 28 additions & 0 deletions builtin/providers/scaleway/import_scaleway_security_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package scaleway

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccScalewaySecurityGroup_importBasic(t *testing.T) {
resourceName := "scaleway_security_group.base"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewaySecurityGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewaySecurityGroupConfig,
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
28 changes: 28 additions & 0 deletions builtin/providers/scaleway/import_scaleway_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package scaleway

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccScalewayServer_importBasic(t *testing.T) {
resourceName := "scaleway_server.base"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayServerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewayServerConfig,
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
28 changes: 28 additions & 0 deletions builtin/providers/scaleway/import_scaleway_volume_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package scaleway

import (
"testing"

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccScalewayVolume_importBasic(t *testing.T) {
resourceName := "scaleway_volume.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayVolumeDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewayVolumeConfig,
},

resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
4 changes: 4 additions & 0 deletions builtin/providers/scaleway/resource_scaleway_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func resourceScalewayIP() *schema.Resource {
Read: resourceScalewayIPRead,
Update: resourceScalewayIPUpdate,
Delete: resourceScalewayIPDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"server": &schema.Schema{
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func resourceScalewaySecurityGroup() *schema.Resource {
Read: resourceScalewaySecurityGroupRead,
Update: resourceScalewaySecurityGroupUpdate,
Delete: resourceScalewaySecurityGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewaySecurityGroupRuleDestroy(&group),
CheckDestroy: testAccCheckScalewaySecurityGroupRuleDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewaySecurityGroupRuleConfig,
Expand Down Expand Up @@ -66,24 +66,31 @@ func testAccCheckScalewaySecurityGroupsExists(n string, group *api.ScalewaySecur
}
}

func testAccCheckScalewaySecurityGroupRuleDestroy(group *api.ScalewaySecurityGroups) func(*terraform.State) error {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*Client).scaleway
func testAccCheckScalewaySecurityGroupRuleDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*Client).scaleway

for _, rs := range s.RootModule().Resources {
if rs.Type != "scaleway" {
continue
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "scaleway" {
continue
}

_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
groups, err := client.GetSecurityGroups()
if err != nil {
return err
}

if err == nil {
return fmt.Errorf("Security Group still exists")
}
all_err := true
for _, group := range groups.SecurityGroups {
_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
all_err = all_err && err != nil
}

return nil
if !all_err {
return fmt.Errorf("Security Group still exists")
}
}

return nil
}

func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.ScalewaySecurityGroups) resource.TestCheckFunc {
Expand Down
8 changes: 8 additions & 0 deletions builtin/providers/scaleway/resource_scaleway_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func resourceScalewayServer() *schema.Resource {
Read: resourceScalewayServerRead,
Update: resourceScalewayServerUpdate,
Delete: resourceScalewayServerDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -138,6 +142,10 @@ func resourceScalewayServerRead(d *schema.ResourceData, m interface{}) error {
return err
}

d.Set("name", server.Name)
d.Set("image", server.Image.Identifier)
d.Set("type", server.CommercialType)
d.Set("enable_ipv6", server.EnableIPV6)
d.Set("private_ip", server.PrivateIP)
d.Set("public_ip", server.PublicAddress.IP)

Expand Down
4 changes: 4 additions & 0 deletions builtin/providers/scaleway/resource_scaleway_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func resourceScalewayVolume() *schema.Resource {
Read: resourceScalewayVolumeRead,
Update: resourceScalewayVolumeUpdate,
Delete: resourceScalewayVolumeDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down
8 changes: 8 additions & 0 deletions website/source/docs/providers/scaleway/r/ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ The following attributes are exported:

* `id` - id of the new resource
* `ip` - IP of the new resource

## Import

Instances can be imported using the `id`, e.g.

```
$ terraform import scaleway_ip.jump_host 5faef9cd-ea9b-4a63-9171-9e26bec03dbc
```
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ Field `name`, `description` are editable.
The following attributes are exported:

* `id` - id of the new resource

## Import

Instances can be imported using the `id`, e.g.

```
$ terraform import scaleway_security_group.test 5faef9cd-ea9b-4a63-9171-9e26bec03dbc
```
8 changes: 8 additions & 0 deletions website/source/docs/providers/scaleway/r/server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ The following attributes are exported:
* `id` - id of the new resource
* `private_ip` - private ip of the new resource
* `public_ip` - public ip of the new resource

## Import

Instances can be imported using the `id`, e.g.

```
$ terraform import scaleway_server.web 5faef9cd-ea9b-4a63-9171-9e26bec03dbc
```
8 changes: 8 additions & 0 deletions website/source/docs/providers/scaleway/r/volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ The following arguments are supported:
The following attributes are exported:

* `id` - id of the new resource

## Import

Instances can be imported using the `id`, e.g.

```
$ terraform import scaleway_volume.test 5faef9cd-ea9b-4a63-9171-9e26bec03dbc
```

0 comments on commit fc2d973

Please sign in to comment.