Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow size edition in resource ovh_cloud_project_volume #804

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
21 changes: 19 additions & 2 deletions ovh/resource_cloud_project_volume.go
Original file line number Diff line number Diff line change
@@ -156,12 +156,29 @@ func (r *cloudProjectVolumeResource) Update(ctx context.Context, req resource.Up
endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())
if err := r.config.OVHClient.Put(endpoint, planData.ToUpdate(), nil); err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error calling Post %s", endpoint),
fmt.Sprintf("Error calling Put %s", endpoint),
err.Error(),
)
return
}

// Check if size has been modified as updating it requires a specific call
if !planData.Size.Equal(data.Size) {
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString()) + "/upsize"
if err := r.config.OVHClient.Post(endpoint, map[string]any{
"size": planData.Size.ValueInt64(),
}, nil); err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error calling Post %s", endpoint),
err.Error(),
)
return
}

// Here we need to wait for some time to make sure the size is correctly updated on backend side
time.Sleep(1 * time.Minute)
}

// Read updated resource
endpoint = "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/volume/" + url.PathEscape(data.VolumeId.ValueString())
if err := r.config.OVHClient.Get(endpoint, &responseData); err != nil {
@@ -173,6 +190,7 @@ func (r *cloudProjectVolumeResource) Update(ctx context.Context, req resource.Up
}

responseData.MergeWith(&planData)
responseData.MergeWith(&data)

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

// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}
26 changes: 0 additions & 26 deletions ovh/resource_cloud_project_volume_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions ovh/resource_cloud_project_volume_test.go
Original file line number Diff line number Diff line change
@@ -34,9 +34,34 @@ func TestAccCloudProjectVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "region_name", regionName),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", serviceName),
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "volume_id"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "type"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "description"),
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "name"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "type", "classic"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "description", "test"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "name", "test"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "size", "15"),
),
},
{
Config: fmt.Sprintf(`
resource "ovh_cloud_project_volume" "volume" {
region_name = "%s"
service_name = "%s"
description = "test_updated"
name = "test_updated"
size = 20
type = "classic"
}
`,
regionName,
serviceName,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "region_name", regionName),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "service_name", serviceName),
resource.TestCheckResourceAttrSet("ovh_cloud_project_volume.volume", "volume_id"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "type", "classic"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "description", "test_updated"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "name", "test_updated"),
resource.TestCheckResourceAttr("ovh_cloud_project_volume.volume", "size", "20"),
),
},
},
4 changes: 2 additions & 2 deletions website/docs/r/cloud_project_region_volume.markdown
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
subcategory : "Managed update"
subcategory : "Cloud Project"
---

# ovh_cloud_project_volume
@@ -29,7 +29,7 @@ The following arguments are supported:
* `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.**
* `description` - A description of the volume
* `name` - Name of the volume
* `size` - Size (GB) of the volume **Changing this value recreates the resource.**
* `size` - Size (GB) of the volume
* `type` - Type of the volume **Changing this value recreates the resource.**

## Attributes Reference