Skip to content

Commit e8c00aa

Browse files
authored
Merge pull request #804 from ovh/dev/aamstutz/allow-size-edition
fix: Allow size edition in resource ovh_cloud_project_volume
2 parents fa7956c + 9cf350e commit e8c00aa

4 files changed

+49
-33
lines changed

ovh/resource_cloud_project_volume.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,29 @@ func (r *cloudProjectVolumeResource) Update(ctx context.Context, req resource.Up
156156
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())
157157
if err := r.config.OVHClient.Put(endpoint, planData.ToUpdate(), nil); err != nil {
158158
resp.Diagnostics.AddError(
159-
fmt.Sprintf("Error calling Post %s", endpoint),
159+
fmt.Sprintf("Error calling Put %s", endpoint),
160160
err.Error(),
161161
)
162162
return
163163
}
164164

165+
// Check if size has been modified as updating it requires a specific call
166+
if !planData.Size.Equal(data.Size) {
167+
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + "/upsize"
168+
if err := r.config.OVHClient.Post(endpoint, map[string]any{
169+
"size": planData.Size.ValueInt64(),
170+
}, nil); err != nil {
171+
resp.Diagnostics.AddError(
172+
fmt.Sprintf("Error calling Post %s", endpoint),
173+
err.Error(),
174+
)
175+
return
176+
}
177+
178+
// Here we need to wait for some time to make sure the size is correctly updated on backend side
179+
time.Sleep(1 * time.Minute)
180+
}
181+
165182
// Read updated resource
166183
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())
167184
if err := r.config.OVHClient.Get(endpoint, &responseData); err != nil {
@@ -173,6 +190,7 @@ func (r *cloudProjectVolumeResource) Update(ctx context.Context, req resource.Up
173190
}
174191

175192
responseData.MergeWith(&planData)
193+
responseData.MergeWith(&data)
176194

177195
// Save updated data into Terraform state
178196
resp.Diagnostics.Append(resp.State.Set(ctx, &responseData)...)
@@ -183,7 +201,6 @@ func (r *cloudProjectVolumeResource) Delete(ctx context.Context, req resource.De
183201

184202
// Read Terraform prior state data into the model
185203
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
186-
187204
if resp.Diagnostics.HasError() {
188205
return
189206
}

ovh/resource_cloud_project_volume_gen.go

-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ovh/resource_cloud_project_volume_test.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,34 @@ func TestAccCloudProjectVolume_basic(t *testing.T) {
3434
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "region_name", regionName),
3535
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", serviceName),
3636
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "volume_id"),
37-
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "type"),
38-
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "description"),
39-
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "name"),
37+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "type", "classic"),
38+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "description", "test"),
39+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "name", "test"),
40+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "size", "15"),
41+
),
42+
},
43+
{
44+
Config: fmt.Sprintf(`
45+
resource "ovh_cloud_project_volume" "volume" {
46+
region_name = "%s"
47+
service_name = "%s"
48+
description = "test_updated"
49+
name = "test_updated"
50+
size = 20
51+
type = "classic"
52+
}
53+
`,
54+
regionName,
55+
serviceName,
56+
),
57+
Check: resource.ComposeAggregateTestCheckFunc(
58+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "region_name", regionName),
59+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", serviceName),
60+
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "volume_id"),
61+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "type", "classic"),
62+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "description", "test_updated"),
63+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "name", "test_updated"),
64+
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "size", "20"),
4065
),
4166
},
4267
},

website/docs/r/cloud_project_region_volume.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
subcategory : "Managed update"
2+
subcategory : "Cloud Project"
33
---
44

55
# ovh_cloud_project_volume
@@ -29,7 +29,7 @@ The following arguments are supported:
2929
* `region_name` - Required. A valid OVHcloud public cloud region name in which the volume will be available. Ex.: "GRA11". **Changing this value recreates the resource.**
3030
* `description` - A description of the volume
3131
* `name` - Name of the volume
32-
* `size` - Size (GB) of the volume **Changing this value recreates the resource.**
32+
* `size` - Size (GB) of the volume
3333
* `type` - Type of the volume **Changing this value recreates the resource.**
3434

3535
## Attributes Reference

0 commit comments

Comments
 (0)