Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/resources/instance_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ attached to the server. Updates to this field will trigger a stop/start of the s

- `value` - (Required) The user data content. It could be a string or a file content using [file](https://www.terraform.io/docs/configuration/functions/file.html) or [filebase64](https://www.terraform.io/docs/configuration/functions/filebase64.html) for example.

- `boot_type` - The boot Type of the server. Possible values are: `local`, `bootscript` or `rescue`.

- `bootscript_id` - The ID of the bootscript to use (set boot_type to `bootscript`).

- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the server should be created.

- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the server is associated with.
Expand Down
35 changes: 34 additions & 1 deletion scaleway/resource_instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,20 @@ func resourceScalewayInstanceServer() *schema.Resource {
},
"boot_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The boot type of the server",
Default: instance.BootTypeLocal,
ValidateFunc: validation.StringInSlice([]string{
instance.BootTypeLocal.String(),
instance.BootTypeRescue.String(),
instance.BootTypeBootscript.String(),
}, false),
},
"bootscript_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the target bootscript (set boot_type to bootscript)",
ValidateFunc: validationUUID(),
},
"cloud_init": {
Type: schema.TypeString,
Expand Down Expand Up @@ -259,6 +271,15 @@ func resourceScalewayInstanceServerCreate(ctx context.Context, d *schema.Resourc
Tags: expandStrings(d.Get("tags")),
}

if bootScriptID, ok := d.GetOk("bootscript_id"); ok {
req.Bootscript = expandStringPtr(bootScriptID)
}

if bootType, ok := d.GetOk("boot_type"); ok {
bootType := instance.BootType(bootType.(string))
req.BootType = &bootType
}

if ipID, ok := d.GetOk("ip_id"); ok {
req.PublicIP = expandStringPtr(expandZonedID(ipID).ID)
}
Expand Down Expand Up @@ -360,6 +381,7 @@ func resourceScalewayInstanceServerRead(ctx context.Context, d *schema.ResourceD
_ = d.Set("zone", string(zone))
_ = d.Set("name", response.Server.Name)
_ = d.Set("boot_type", response.Server.BootType)
_ = d.Set("bootscript_id", response.Server.Bootscript.ID)
_ = d.Set("type", response.Server.CommercialType)
_ = d.Set("tags", response.Server.Tags)
_ = d.Set("security_group_id", newZonedID(zone, response.Server.SecurityGroup.ID).String())
Expand Down Expand Up @@ -579,6 +601,17 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
}
}

if d.HasChanges("boot_type") {
bootType := instance.BootType(d.Get("boot_type").(string))
updateRequest.BootType = &bootType
forceReboot = true
}

if d.HasChanges("bootscript_id") {
updateRequest.Bootscript = expandStringPtr(d.Get("bootscript_id").(string))
forceReboot = true
}

////
// Update server user data
////
Expand Down
33 changes: 33 additions & 0 deletions scaleway/resource_instance_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,36 @@ resource "scaleway_instance_server" "base" {
additional_volume_ids = [ %s ]
}`, additionalVolumeResources, baseVolume, strings.Join(additionalVolumeIDs, ","))
}

func TestAccScalewayInstanceServer_Bootscript(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
// Quick tip to get all the different bootscript:
// curl -sH "X-Auth-Token: $(scw config get secret-key)" https://api.scaleway.com/instance/v1/zones/fr-par-1/bootscripts | jq -r '.bootscripts[] | [.id, .architecture, .title] | @tsv'
bootscript := "7decf961-d3e9-4711-93c7-b16c254e99b9"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
CheckDestroy: testAccCheckScalewayInstanceServerDestroy(tt),
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
data "scaleway_instance_image" "ubuntu_focal" {
name = "Ubuntu 20.04 Focal Fossa"
}

resource "scaleway_instance_server" "base" {
type = "DEV1-S"
image = data.scaleway_instance_image.ubuntu_focal.id
boot_type = "bootscript"
bootscript_id = "%s"
}
`, bootscript),
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceServerExists(tt, "scaleway_instance_server.base"),
resource.TestCheckResourceAttr("scaleway_instance_server.base", "bootscript_id", bootscript),
),
},
},
})
}
Loading