Skip to content

Commit 009f31a

Browse files
feat: allow configuration of the root volume. (#9)
1 parent 64ae82a commit 009f31a

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ module "my_instance" {
4747

4848
| Name | Description | Type | Default | Required |
4949
|------|-------------|------|---------|:--------:|
50-
| <a name="input_image"></a> [image](#input_image) | UUID or the label of the base image used by the server. | `string` | n/a | yes |
5150
| <a name="input_additional_volume_ids"></a> [additional_volume_ids](#input_additional_volume_ids) | Additional volumes attached to the server. Updates to this field will trigger a stop/start of the server. | `list(string)` | `[]` | no |
5251
| <a name="input_boot_type"></a> [boot_type](#input_boot_type) | The boot Type of the server. Default to 'local'. Possible values are: 'local', 'bootscript' or 'rescue'. | `string` | `"local"` | no |
5352
| <a name="input_bootscript_id"></a> [bootscript_id](#input_bootscript_id) | ID of the bootscript to use (set boot_type to bootscript). | `string` | `null` | no |
5453
| <a name="input_domainname"></a> [domainname](#input_domainname) | Domain name of the instance. If set, instance IPs will be registered in the matching DNS zone. | `string` | `null` | no |
5554
| <a name="input_enable_ipv6"></a> [enable_ipv6](#input_enable_ipv6) | Determines if IPv6 is enabled for the server. | `bool` | `false` | no |
5655
| <a name="input_enable_public_ipv4"></a> [enable_public_ipv4](#input_enable_public_ipv4) | Determines if a public IPv4 will be attached to the server. | `bool` | `false` | no |
5756
| <a name="input_hostname"></a> [hostname](#input_hostname) | Name of the instance. If not set, it will be randomly generated by Scaleway. | `string` | `null` | no |
57+
| <a name="input_image"></a> [image](#input_image) | UUID or the label of the base image used by the server. Must be null if `root_volume.volume_id` is used. | `string` | `null` | no |
5858
| <a name="input_instance_type"></a> [instance_type](#input_instance_type) | Commercial type of the server. Default to 'DEV1-S'. Updates to this field will recreate a new resource. | `string` | `"DEV1-S"` | no |
5959
| <a name="input_placement_group_id"></a> [placement_group_id](#input_placement_group_id) | ID of the placement group the server is attached to. | `string` | `null` | no |
6060
| <a name="input_private_networks"></a> [private_networks](#input_private_networks) | Private networks associated with the server. | `list(string)` | `[]` | no |
6161
| <a name="input_project_id"></a> [project_id](#input_project_id) | ID of the project the namespace is associated with. Ressource will be created in the project set at the provider level if null. | `string` | `null` | no |
62+
| <a name="input_root_volume"></a> [root_volume](#input_root_volume) | Root volume attached to the server on creation. Updates to `root_volume.size_in_gb` will be ignored after the creation of the server. | ```object({ delete_on_termination = bool size_in_gb = number volume_id = optional(string) volume_type = optional(string) })``` | `null` | no |
6263
| <a name="input_security_group_id"></a> [security_group_id](#input_security_group_id) | ID of the security group the server is attached to. | `string` | `null` | no |
6364
| <a name="input_state"></a> [state](#input_state) | State of the server. Default to 'started'. Possible values are: 'started', 'stopped' or 'standby'. | `string` | `"started"` | no |
6465
| <a name="input_tags"></a> [tags](#input_tags) | Tags associated with the server and dedicated ip address. | `list(any)` | `[]` | no |

main.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ resource "scaleway_instance_server" "this" {
3838
tags = var.tags
3939

4040
additional_volume_ids = var.additional_volume_ids
41-
# root_volume = var.root_volume
41+
42+
dynamic "root_volume" {
43+
for_each = var.root_volume != null ? [1] : []
44+
content {
45+
delete_on_termination = var.root_volume["delete_on_termination"]
46+
size_in_gb = var.root_volume["size_in_gb"]
47+
volume_id = var.root_volume["volume_id"]
48+
volume_type = var.root_volume["volume_type"]
49+
}
50+
}
4251

4352
enable_dynamic_ip = var.enable_public_ipv4
4453
enable_ipv6 = var.enable_ipv6

variables.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
variable "image" {
22
type = string
3-
description = "UUID or the label of the base image used by the server."
3+
description = "UUID or the label of the base image used by the server. Must be null if `root_volume.volume_id` is used."
4+
default = null
45
}
56

67
variable "instance_type" {
@@ -47,10 +48,16 @@ variable "additional_volume_ids" {
4748
default = []
4849
}
4950

50-
# variable "root_volume" {
51-
# type = any
52-
# default = null
53-
# }
51+
variable "root_volume" {
52+
description = "Root volume attached to the server on creation. Updates to `root_volume.size_in_gb` will be ignored after the creation of the server."
53+
type = object({
54+
delete_on_termination = bool
55+
size_in_gb = number
56+
volume_id = optional(string)
57+
volume_type = optional(string)
58+
})
59+
default = null
60+
}
5461

5562
# Network
5663

0 commit comments

Comments
 (0)