Skip to content

Commit d1efe0c

Browse files
committed
feat(instance): add support for tags in volume (scaleway#1129)
1 parent 47c8148 commit d1efe0c

File tree

3 files changed

+204
-148
lines changed

3 files changed

+204
-148
lines changed

docs/resources/instance_volume.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The following arguments are supported:
3030
- `name` - (Optional) The name of the volume. If not provided it will be randomly generated.
3131
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the volume should be created.
3232
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the volume is associated with.
33+
- `tags` - (Optional) A list of tags to apply to the volume.
3334

3435
## Attributes Reference
3536

scaleway/resource_instance_volume.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func resourceScalewayInstanceVolume() *schema.Resource {
6868
Computed: true,
6969
Description: "The server associated with this volume",
7070
},
71+
"tags": {
72+
Type: schema.TypeList,
73+
Elem: &schema.Schema{
74+
Type: schema.TypeString,
75+
},
76+
Optional: true,
77+
Description: "The tags associated with the volume",
78+
},
7179
"organization_id": organizationIDSchema(),
7280
"project_id": projectIDSchema(),
7381
"zone": zoneSchema(),
@@ -86,6 +94,7 @@ func resourceScalewayInstanceVolumeCreate(ctx context.Context, d *schema.Resourc
8694
Name: expandOrGenerateString(d.Get("name"), "vol"),
8795
VolumeType: instance.VolumeVolumeType(d.Get("type").(string)),
8896
Project: expandStringPtr(d.Get("project_id")),
97+
Tags: expandStrings(d.Get("tags")),
8998
}
9099

91100
if size, ok := d.GetOk("size_in_gb"); ok {
@@ -134,6 +143,7 @@ func resourceScalewayInstanceVolumeRead(ctx context.Context, d *schema.ResourceD
134143
_ = d.Set("project_id", res.Volume.Project)
135144
_ = d.Set("zone", string(zone))
136145
_ = d.Set("type", res.Volume.VolumeType.String())
146+
_ = d.Set("tags", res.Volume.Tags)
137147

138148
_, fromVolume := d.GetOk("from_volume_id")
139149
_, fromSnapshot := d.GetOk("from_snapshot_id")
@@ -156,17 +166,18 @@ func resourceScalewayInstanceVolumeUpdate(ctx context.Context, d *schema.Resourc
156166
return diag.FromErr(err)
157167
}
158168

169+
req := &instance.UpdateVolumeRequest{
170+
VolumeID: id,
171+
Zone: zone,
172+
}
173+
159174
if d.HasChange("name") {
160175
newName := d.Get("name").(string)
176+
req.Name = &newName
177+
}
161178

162-
_, err = instanceAPI.UpdateVolume(&instance.UpdateVolumeRequest{
163-
VolumeID: id,
164-
Zone: zone,
165-
Name: &newName,
166-
}, scw.WithContext(ctx))
167-
if err != nil {
168-
return diag.FromErr(fmt.Errorf("couldn't update volume: %s", err))
169-
}
179+
if d.HasChange("tags") {
180+
req.Tags = scw.StringsPtr(expandStrings(d.Get("tags")))
170181
}
171182

172183
if d.HasChange("size_in_gb") {
@@ -204,6 +215,11 @@ func resourceScalewayInstanceVolumeUpdate(ctx context.Context, d *schema.Resourc
204215
}
205216
}
206217

218+
_, err = instanceAPI.UpdateVolume(req, scw.WithContext(ctx))
219+
if err != nil {
220+
return diag.FromErr(fmt.Errorf("couldn't update volume: %s", err))
221+
}
222+
207223
return resourceScalewayInstanceVolumeRead(ctx, d, meta)
208224
}
209225

0 commit comments

Comments
 (0)