Skip to content

Commit

Permalink
resource/server: support boot_type
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolai86 committed Apr 26, 2018
1 parent 6aec6e1 commit 900eea4
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 3 deletions.
17 changes: 17 additions & 0 deletions scaleway/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
api "github.com/nicolai86/scaleway-sdk"
)

Expand Down Expand Up @@ -41,6 +42,17 @@ func resourceScalewayServer() *schema.Resource {
Description: "The instance type of the server",
ValidateFunc: validateServerType,
},
"boot_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The boot_type of the server",
ValidateFunc: validation.StringInSlice([]string{
"bootscript",
"local",
}, false),
},
"bootscript": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -159,6 +171,10 @@ func resourceScalewayServerCreate(d *schema.ResourceData, m interface{}) error {
EnableIPV6: d.Get("enable_ipv6").(bool),
SecurityGroup: d.Get("security_group").(string),
}
bootType, ok := d.GetOk("boot_type")
if ok {
req.BootType = bootType.(string)
}

req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool))
req.CommercialType = d.Get("type").(string)
Expand Down Expand Up @@ -249,6 +265,7 @@ func resourceScalewayServerRead(d *schema.ResourceData, m interface{}) error {
d.Set("enable_ipv6", server.EnableIPV6)
d.Set("private_ip", server.PrivateIP)
d.Set("public_ip", server.PublicAddress.IP)
d.Set("boot_type", server.BootType)

if server.EnableIPV6 && server.IPV6 != nil {
d.Set("public_ipv6", server.IPV6.Address)
Expand Down
30 changes: 30 additions & 0 deletions scaleway/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func TestAccScalewayServer_Basic(t *testing.T) {
"scaleway_server.base", "name", "test"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "tags.0", "terraform-test"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "boot_type", "bootscript"),
),
},
resource.TestStep{
Expand All @@ -81,6 +83,23 @@ func TestAccScalewayServer_Basic(t *testing.T) {
})
}

func TestAccScalewayServer_BootType(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayServerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewayServerConfig_LocalBoot,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"scaleway_server.base", "boot_type", "local"),
),
},
},
})
}

func TestAccScalewayServer_ExistingIP(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -301,6 +320,7 @@ func testAccCheckScalewayServerExists(n string) resource.TestCheckFunc {
}

var armImageIdentifier = "5faef9cd-ea9b-4a63-9171-9e26bec03dbc"
var x86_64ImageIdentifier = "e20532c4-1fa0-4c97-992f-436b8d372c07"

var testAccCheckScalewayServerConfig = fmt.Sprintf(`
resource "scaleway_server" "base" {
Expand All @@ -311,6 +331,16 @@ resource "scaleway_server" "base" {
tags = [ "terraform-test" ]
}`, armImageIdentifier)

var testAccCheckScalewayServerConfig_LocalBoot = fmt.Sprintf(`
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "VC1S"
tags = [ "terraform-test" ]
boot_type = "local"
}`, x86_64ImageIdentifier)

var testAccCheckScalewayServerConfig_IPAttachment = fmt.Sprintf(`
resource "scaleway_ip" "base" {}
Expand Down
191 changes: 191 additions & 0 deletions vendor/github.com/hashicorp/terraform/helper/validation/validation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/nicolai86/scaleway-sdk/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@
"version": "v0.10.0",
"versionExact": "v0.10.0"
},
{
"checksumSHA1": "jdwWpJZbTSU87GUlwLTuf6FwpmE=",
"path": "github.com/hashicorp/terraform/helper/validation",
"revision": "90e986348ad914b0fffb67feddd0924c0e741c4f",
"revisionTime": "2017-12-01T22:04:31Z"
},
{
"checksumSHA1": "yFWmdS6yEJZpRJzUqd/mULqCYGk=",
"path": "github.com/hashicorp/terraform/moduledeps",
Expand Down Expand Up @@ -558,10 +564,10 @@
"revisionTime": "2016-10-03T17:45:16Z"
},
{
"checksumSHA1": "qPUxUkRxA0nnbZ9Pb7yUor1P7Fg=",
"checksumSHA1": "n8j/CVEarUKArSLFjbZ4vMcxKf4=",
"path": "github.com/nicolai86/scaleway-sdk",
"revision": "d749f7b83389f1afe19b81a610fad5ebb7a12744",
"revisionTime": "2018-04-01T05:36:48Z"
"revision": "514d84f85641e74c600b56fb9ec5083cd4803a73",
"revisionTime": "2018-04-25T16:23:49Z"
},
{
"checksumSHA1": "u5s2PZ7fzCOqQX7bVPf9IJ+qNLQ=",
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following arguments are supported:
* `image` - (Required) base image of server
* `type` - (Required) type of server
* `bootscript` - (Optional) server bootscript
* `boot_type` - (Optional) server boot_type (`local`, `bootscript`)
* `tags` - (Optional) list of tags for server
* `enable_ipv6` - (Optional) enable ipv6
* `dynamic_ip_required` - (Optional) make server publicly available
Expand Down

0 comments on commit 900eea4

Please sign in to comment.