provider/scaleway: add importer support

This commit is contained in:
Raphael Randschau 2016-10-15 23:49:14 +02:00
parent 18a7d418f8
commit fc4c848778
No known key found for this signature in database
GPG Key ID: ECFD707E1275A182
13 changed files with 186 additions and 15 deletions

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,

View File

@ -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,

View File

@ -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,
@ -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
}
_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
if err == nil {
return fmt.Errorf("Security Group still exists")
}
for _, rs := range s.RootModule().Resources {
if rs.Type != "scaleway" {
continue
}
return nil
groups, err := client.GetSecurityGroups()
if err != nil {
return err
}
all_err := true
for _, group := range groups.SecurityGroups {
_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID)
all_err = all_err && err != nil
}
if !all_err {
return fmt.Errorf("Security Group still exists")
}
}
return nil
}
func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.ScalewaySecurityGroups) resource.TestCheckFunc {

View File

@ -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,
@ -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)

View File

@ -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,

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```

View File

@ -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
```