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 May 6, 2018
1 parent 7ab3f91 commit abf0430
Show file tree
Hide file tree
Showing 10 changed files with 332 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

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

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

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

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

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.

Loading

0 comments on commit abf0430

Please sign in to comment.