Skip to content

Commit 7b7fe08

Browse files
committed
fix(instance): image: remove MaxItems on additional volumes + fix doc
1 parent 27a6b65 commit 7b7fe08

File tree

7 files changed

+6192
-2244
lines changed

7 files changed

+6192
-2244
lines changed

docs/resources/instance_image.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "scaleway_instance_snapshot" "server_snapshot" {
6969
resource "scaleway_instance_image" "image" {
7070
name = "image_with_extra_volumes"
7171
root_volume_id = scaleway_instance_snapshot.server_snapshot.id
72-
additional_volumes = [
72+
additional_volume_ids = [
7373
scaleway_instance_snapshot.volume_snapshot.id
7474
]
7575
}
@@ -83,9 +83,6 @@ The following arguments are supported:
8383
- `name` - (Optional) The name of the image. If not provided it will be randomly generated.
8484
- `architecture` - (Optional, default `x86_64`) The architecture the image is compatible with. Possible values are: `x86_64` or `arm`.
8585
- `additional_volume_ids` - (Optional) List of IDs of the snapshots of the additional volumes to be attached to the image.
86-
87-
-> **Important:** For now it is only possible to have 1 additional_volume.
88-
8986
- `tags` - (Optional) A list of tags to apply to the image.
9087
- `public` - (Optional) Set to `true` if the image is public.
9188
- `zone` - (Defaults to provider `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the image should be created.
@@ -119,11 +116,12 @@ In addition to all arguments above, the following attributes are exported:
119116
- `tags` - List of tags associated with the volume.
120117
- `state` - State of the volume.
121118
- `zone` - The [zone](../guides/regions_and_zones.md#zones) in which the volume is.
122-
- `server` - Description of the server containing the volume (in case the image is a backup from a server).
119+
120+
- `server` - Description of the server containing the volume (in case the image is a backup from a server).
123121

124122
-> The `server` block contains :
125-
- `id` - ID of the server containing the volume.
126-
- `name` - Name of the server containing the volume.
123+
- `id` - ID of the server containing the volume.
124+
- `name` - Name of the server containing the volume.
127125

128126
## Import
129127

internal/services/instance/image.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func ResourceImage() *schema.Resource {
5959
"additional_volume_ids": {
6060
Type: schema.TypeList,
6161
Optional: true,
62-
MaxItems: 1,
6362
Elem: &schema.Schema{
6463
Type: schema.TypeString,
6564
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(),

internal/services/instance/image_test.go

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -130,68 +130,70 @@ func TestAccImage_ExternalBlockVolume(t *testing.T) {
130130
{
131131
Config: `
132132
resource "scaleway_block_volume" "main" {
133-
size_in_gb = 50
133+
size_in_gb = 20
134134
iops = 5000
135135
}
136-
137-
resource "scaleway_block_snapshot" "main" {
138-
volume_id = scaleway_block_volume.main.id
139-
}
140-
`,
141-
},
142-
{
143-
Config: `
144-
resource "scaleway_block_volume" "main" {
145-
size_in_gb = 50
146-
iops = 5000
147-
}
148-
149136
resource "scaleway_block_volume" "additional1" {
150-
size_in_gb = 50
137+
size_in_gb = 20
138+
iops = 15000
139+
}
140+
resource "scaleway_block_volume" "additional2" {
141+
size_in_gb = 40
151142
iops = 5000
152143
}
153144
154145
resource "scaleway_block_snapshot" "main" {
155146
volume_id = scaleway_block_volume.main.id
156147
}
157-
158148
resource "scaleway_block_snapshot" "additional1" {
159149
volume_id = scaleway_block_volume.additional1.id
160150
}
151+
resource "scaleway_block_snapshot" "additional2" {
152+
volume_id = scaleway_block_volume.additional2.id
153+
}
161154
162155
resource "scaleway_instance_image" "main" {
163156
name = "tf-test-image-external-block-volume"
164157
root_volume_id = scaleway_block_snapshot.main.id
165-
additional_volume_ids = [scaleway_block_snapshot.additional1.id]
158+
additional_volume_ids = [
159+
scaleway_block_snapshot.additional1.id,
160+
scaleway_block_snapshot.additional2.id
161+
]
166162
}
167163
`,
168164
Check: resource.ComposeTestCheckFunc(
169165
instancechecks.DoesImageExists(tt, "scaleway_instance_image.main"),
170166
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "root_volume_id", "scaleway_block_snapshot.main", "id"),
171167
resource.TestCheckResourceAttr("scaleway_instance_image.main", "architecture", "x86_64"),
172-
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volume_ids.#", "1"),
168+
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volume_ids.#", "2"),
173169
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "additional_volume_ids.0", "scaleway_block_snapshot.additional1", "id"),
170+
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "additional_volume_ids.1", "scaleway_block_snapshot.additional2", "id"),
174171
),
175172
},
176173
{
177174
Config: `
178175
resource "scaleway_block_volume" "main" {
179-
size_in_gb = 50
176+
size_in_gb = 20
180177
iops = 5000
181178
}
182-
183179
resource "scaleway_block_volume" "additional1" {
184-
size_in_gb = 50
180+
size_in_gb = 20
181+
iops = 15000
182+
}
183+
resource "scaleway_block_volume" "additional2" {
184+
size_in_gb = 40
185185
iops = 5000
186186
}
187187
188188
resource "scaleway_block_snapshot" "main" {
189189
volume_id = scaleway_block_volume.main.id
190190
}
191-
192191
resource "scaleway_block_snapshot" "additional1" {
193192
volume_id = scaleway_block_volume.additional1.id
194193
}
194+
resource "scaleway_block_snapshot" "additional2" {
195+
volume_id = scaleway_block_volume.additional2.id
196+
}
195197
196198
resource "scaleway_instance_image" "main" {
197199
name = "tf-test-image-external-block-volume"
@@ -456,61 +458,56 @@ func TestAccImage_ServerWithLocalVolume(t *testing.T) {
456458
{
457459
Config: `
458460
resource "scaleway_instance_server" "server01" {
461+
name = "root-vol0"
459462
image = "ubuntu_focal"
460463
type = "DEV1-S"
461464
root_volume {
462465
size_in_gb = 15
463466
volume_type = "l_ssd"
464467
}
465468
}
466-
resource "scaleway_instance_snapshot" "local01" {
467-
volume_id = scaleway_instance_server.server01.root_volume.0.volume_id
468-
depends_on = [ scaleway_instance_server.server01 ]
469-
}
470-
`,
471-
Check: resource.ComposeTestCheckFunc(
472-
isServerPresent(tt, "scaleway_instance_server.server01"),
473-
isSnapshotPresent(tt, "scaleway_instance_snapshot.local01"),
474-
),
475-
},
476-
{
477-
Config: `
478-
resource "scaleway_instance_server" "server01" {
469+
resource "scaleway_instance_server" "server02" {
470+
name = "add-vol1"
479471
image = "ubuntu_focal"
480472
type = "DEV1-S"
481473
root_volume {
482-
size_in_gb = 15
474+
size_in_gb = 10
483475
volume_type = "l_ssd"
484476
}
485477
}
486-
resource "scaleway_instance_server" "server02" {
478+
resource "scaleway_instance_server" "server03" {
479+
name = "add-vol2"
487480
image = "ubuntu_focal"
488481
type = "DEV1-S"
489482
root_volume {
490-
size_in_gb = 10
483+
size_in_gb = 20
491484
volume_type = "l_ssd"
492485
}
493486
}
494487
495488
resource "scaleway_instance_snapshot" "local01" {
496489
volume_id = scaleway_instance_server.server01.root_volume.0.volume_id
497-
depends_on = [ scaleway_instance_server.server01 ]
498490
}
499491
resource "scaleway_instance_snapshot" "local02" {
500492
volume_id = scaleway_instance_server.server02.root_volume.0.volume_id
501-
depends_on = [ scaleway_instance_server.server02 ]
493+
}
494+
resource "scaleway_instance_snapshot" "local03" {
495+
volume_id = scaleway_instance_server.server03.root_volume.0.volume_id
502496
}
503497
`,
504498
Check: resource.ComposeTestCheckFunc(
505499
isServerPresent(tt, "scaleway_instance_server.server01"),
506500
isServerPresent(tt, "scaleway_instance_server.server02"),
501+
isServerPresent(tt, "scaleway_instance_server.server03"),
507502
isSnapshotPresent(tt, "scaleway_instance_snapshot.local01"),
508503
isSnapshotPresent(tt, "scaleway_instance_snapshot.local02"),
504+
isSnapshotPresent(tt, "scaleway_instance_snapshot.local03"),
509505
),
510506
},
511507
{
512508
Config: `
513509
resource "scaleway_instance_server" "server01" {
510+
name = "root-vol0"
514511
image = "ubuntu_focal"
515512
type = "DEV1-S"
516513
root_volume {
@@ -519,42 +516,54 @@ func TestAccImage_ServerWithLocalVolume(t *testing.T) {
519516
}
520517
}
521518
resource "scaleway_instance_server" "server02" {
519+
name = "add-vol1"
522520
image = "ubuntu_focal"
523521
type = "DEV1-S"
524522
root_volume {
525523
size_in_gb = 10
526524
volume_type = "l_ssd"
527525
}
528526
}
527+
resource "scaleway_instance_server" "server03" {
528+
name = "add-vol2"
529+
image = "ubuntu_focal"
530+
type = "DEV1-S"
531+
root_volume {
532+
size_in_gb = 20
533+
volume_type = "l_ssd"
534+
}
535+
}
529536
530537
resource "scaleway_instance_snapshot" "local01" {
531538
volume_id = scaleway_instance_server.server01.root_volume.0.volume_id
532-
depends_on = [ scaleway_instance_server.server01 ]
533539
}
534540
resource "scaleway_instance_snapshot" "local02" {
535541
volume_id = scaleway_instance_server.server02.root_volume.0.volume_id
536-
depends_on = [ scaleway_instance_server.server02 ]
542+
}
543+
resource "scaleway_instance_snapshot" "local03" {
544+
volume_id = scaleway_instance_server.server03.root_volume.0.volume_id
537545
}
538546
539547
resource "scaleway_instance_image" "main" {
540548
root_volume_id = scaleway_instance_snapshot.local01.id
541-
additional_volume_ids = [ scaleway_instance_snapshot.local02.id ]
542-
depends_on = [
543-
scaleway_instance_snapshot.local01,
544-
scaleway_instance_snapshot.local02,
549+
additional_volume_ids = [
550+
scaleway_instance_snapshot.local02.id,
551+
scaleway_instance_snapshot.local03.id
545552
]
546553
}
547554
`,
548555
Check: resource.ComposeTestCheckFunc(
549-
isServerPresent(tt, "scaleway_instance_server.server01"),
550-
isServerPresent(tt, "scaleway_instance_server.server02"),
551556
isSnapshotPresent(tt, "scaleway_instance_snapshot.local01"),
552557
isSnapshotPresent(tt, "scaleway_instance_snapshot.local02"),
558+
isSnapshotPresent(tt, "scaleway_instance_snapshot.local03"),
553559
instancechecks.DoesImageExists(tt, "scaleway_instance_image.main"),
554560
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "root_volume_id", "scaleway_instance_snapshot.local01", "id"),
555-
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "additional_volumes.0.id", "scaleway_instance_snapshot.local02", "id"),
556561
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volumes.0.volume_type", "l_ssd"),
557562
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volumes.0.size", "10000000000"),
563+
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "additional_volumes.0.id", "scaleway_instance_snapshot.local02", "id"),
564+
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volumes.1.volume_type", "l_ssd"),
565+
resource.TestCheckResourceAttr("scaleway_instance_image.main", "additional_volumes.1.size", "20000000000"),
566+
resource.TestCheckResourceAttrPair("scaleway_instance_image.main", "additional_volumes.1.id", "scaleway_instance_snapshot.local03", "id"),
558567
),
559568
},
560569
},

internal/services/instance/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func ResourceServer() *schema.Resource {
290290
Type: schema.TypeMap,
291291
Optional: true,
292292
Computed: true,
293-
Description: "The user data associated with the server", // TODO: document reserved keys (`cloud-init`)
293+
Description: "The user data associated with the server",
294294
Elem: &schema.Schema{
295295
Type: schema.TypeString,
296296
},

0 commit comments

Comments
 (0)