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, Read: resourceScalewayIPRead,
Update: resourceScalewayIPUpdate, Update: resourceScalewayIPUpdate,
Delete: resourceScalewayIPDelete, Delete: resourceScalewayIPDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"server": &schema.Schema{ "server": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -14,6 +14,10 @@ func resourceScalewaySecurityGroup() *schema.Resource {
Read: resourceScalewaySecurityGroupRead, Read: resourceScalewaySecurityGroupRead,
Update: resourceScalewaySecurityGroupUpdate, Update: resourceScalewaySecurityGroupUpdate,
Delete: resourceScalewaySecurityGroupDelete, Delete: resourceScalewaySecurityGroupDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -15,7 +15,7 @@ func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckScalewaySecurityGroupRuleDestroy(&group), CheckDestroy: testAccCheckScalewaySecurityGroupRuleDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckScalewaySecurityGroupRuleConfig, Config: testAccCheckScalewaySecurityGroupRuleConfig,
@ -66,8 +66,7 @@ func testAccCheckScalewaySecurityGroupsExists(n string, group *api.ScalewaySecur
} }
} }
func testAccCheckScalewaySecurityGroupRuleDestroy(group *api.ScalewaySecurityGroups) func(*terraform.State) error { func testAccCheckScalewaySecurityGroupRuleDestroy(s *terraform.State) error {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*Client).scaleway client := testAccProvider.Meta().(*Client).scaleway
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
@ -75,16 +74,24 @@ func testAccCheckScalewaySecurityGroupRuleDestroy(group *api.ScalewaySecurityGro
continue continue
} }
_, err := client.GetASecurityGroupRule(group.ID, rs.Primary.ID) groups, err := client.GetSecurityGroups()
if err != nil {
return err
}
if err == nil { 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 fmt.Errorf("Security Group still exists")
} }
} }
return nil return nil
} }
}
func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.ScalewaySecurityGroups) resource.TestCheckFunc { func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.ScalewaySecurityGroups) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {

View File

@ -14,6 +14,10 @@ func resourceScalewayServer() *schema.Resource {
Read: resourceScalewayServerRead, Read: resourceScalewayServerRead,
Update: resourceScalewayServerUpdate, Update: resourceScalewayServerUpdate,
Delete: resourceScalewayServerDelete, Delete: resourceScalewayServerDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
@ -138,6 +142,10 @@ func resourceScalewayServerRead(d *schema.ResourceData, m interface{}) error {
return err 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("private_ip", server.PrivateIP)
d.Set("public_ip", server.PublicAddress.IP) d.Set("public_ip", server.PublicAddress.IP)

View File

@ -16,6 +16,10 @@ func resourceScalewayVolume() *schema.Resource {
Read: resourceScalewayVolumeRead, Read: resourceScalewayVolumeRead,
Update: resourceScalewayVolumeUpdate, Update: resourceScalewayVolumeUpdate,
Delete: resourceScalewayVolumeDelete, Delete: resourceScalewayVolumeDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,

View File

@ -32,3 +32,11 @@ The following attributes are exported:
* `id` - id of the new resource * `id` - id of the new resource
* `ip` - IP 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: The following attributes are exported:
* `id` - id of the new resource * `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 * `id` - id of the new resource
* `private_ip` - private ip of the new resource * `private_ip` - private ip of the new resource
* `public_ip` - public 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: The following attributes are exported:
* `id` - id of the new resource * `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
```