From eaa03d0824017bb187e31ee567e440f7c701ae6a Mon Sep 17 00:00:00 2001 From: Alexander Dahmen Date: Thu, 18 Jun 2026 14:04:57 +0200 Subject: [PATCH] chore(objectstorage): Add warning to inform that it is not possible to delete an object storage which contains content Signed-off-by: Alexander Dahmen --- docs/resources/objectstorage_bucket.md | 3 +++ .../internal/services/objectstorage/bucket/resource.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/resources/objectstorage_bucket.md b/docs/resources/objectstorage_bucket.md index d9af21c47..8eb4c6fa9 100644 --- a/docs/resources/objectstorage_bucket.md +++ b/docs/resources/objectstorage_bucket.md @@ -4,12 +4,15 @@ page_title: "stackit_objectstorage_bucket Resource - stackit" subcategory: "" description: |- ObjectStorage bucket resource schema. Must have a region specified in the provider configuration. If you are creating credentialsgroup and bucket resources simultaneously, please include the depends_on field so that they are created sequentially. This prevents errors from concurrent calls to the service enablement that is done in the background. + ~> This resource cannot be destroyed if the bucket contains objects. Please ensure the bucket is empty before attempting to destroy it. --- # stackit_objectstorage_bucket (Resource) ObjectStorage bucket resource schema. Must have a `region` specified in the provider configuration. If you are creating `credentialsgroup` and `bucket` resources simultaneously, please include the `depends_on` field so that they are created sequentially. This prevents errors from concurrent calls to the service enablement that is done in the background. +~> This resource cannot be destroyed if the bucket contains objects. Please ensure the bucket is empty before attempting to destroy it. + ## Example Usage ```terraform diff --git a/stackit/internal/services/objectstorage/bucket/resource.go b/stackit/internal/services/objectstorage/bucket/resource.go index 7aaed490f..ccf9efa08 100644 --- a/stackit/internal/services/objectstorage/bucket/resource.go +++ b/stackit/internal/services/objectstorage/bucket/resource.go @@ -62,6 +62,12 @@ type bucketResource struct { // ModifyPlan implements resource.ResourceWithModifyPlan. // Use the modifier to set the effective region in the current plan. func (r *bucketResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform + // Note: This resource cannot be destroyed if the bucket contains objects. We added a check here to inform the user about this before accepting the deletion. + if req.Plan.Raw.IsNull() && !req.State.Raw.IsNull() { + core.LogAndAddWarning(ctx, &resp.Diagnostics, "stackit_object_storage", "Note: This resource cannot be destroyed if the bucket contains objects. Please ensure the bucket is empty before attempting to destroy it.") + return + } + var configModel Model // skip initial empty configuration to avoid follow-up errors if req.Config.Raw.IsNull() { @@ -113,7 +119,8 @@ func (r *bucketResource) Configure(ctx context.Context, req resource.ConfigureRe // Schema defines the schema for the resource. func (r *bucketResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { descriptions := map[string]string{ - "main": "ObjectStorage bucket resource schema. Must have a `region` specified in the provider configuration. If you are creating `credentialsgroup` and `bucket` resources simultaneously, please include the `depends_on` field so that they are created sequentially. This prevents errors from concurrent calls to the service enablement that is done in the background.", + "main": "ObjectStorage bucket resource schema. Must have a `region` specified in the provider configuration. If you are creating `credentialsgroup` and `bucket` resources simultaneously, please include the `depends_on` field so that they are created sequentially. This prevents errors from concurrent calls to the service enablement that is done in the background.\n\n" + + "~> This resource cannot be destroyed if the bucket contains objects. Please ensure the bucket is empty before attempting to destroy it.", "id": "Terraform's internal resource identifier. It is structured as \"`project_id`,`region`,`name`\".", "name": "The bucket name. It must be DNS conform.", "project_id": "STACKIT Project ID to which the bucket is associated.",