Merge pull request #9387 from nicolai86/feat/scaleway-import
provider/scaleway: add support for importing resources
This commit is contained in:
commit
fc2d973e26
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue