diff --git a/docs/resources/s3_bucket_cors_configuration.md b/docs/resources/s3_bucket_cors_configuration.md index 622ca3cec..9f9c851a9 100644 --- a/docs/resources/s3_bucket_cors_configuration.md +++ b/docs/resources/s3_bucket_cors_configuration.md @@ -11,7 +11,7 @@ The `cloudavenue_s3_bucket_cors_configuration` resource allows you to manage the ~> S3 Buckets only support a single CORS configuration. Declaring multiple `cloudavenue_s3_bucket_cors_configuration` resources to the same S3 Bucket will cause a perpetual difference in configuration. -## Example Usage +## Examples Usage ### Basic example @@ -51,7 +51,7 @@ resource "cloudavenue_s3_bucket_cors_configuration" "example" { ### Required -- `bucket` (String) The name of the bucket. +- `bucket` (String) (ForceNew) The name of the bucket. - `cors_rules` (Attributes Set) Set of origins and methods (cross-origin access that you want to allow). Set must contain at least 1 elements and at most 100 elements. (see [below for nested schema](#nestedatt--cors_rules)) ### Optional diff --git a/internal/provider/s3/bucket_cors_configuration_resource.go b/internal/provider/s3/bucket_cors_configuration_resource.go index 35fe20738..38f2f82a6 100644 --- a/internal/provider/s3/bucket_cors_configuration_resource.go +++ b/internal/provider/s3/bucket_cors_configuration_resource.go @@ -246,10 +246,9 @@ func (r *BucketCorsConfigurationResource) Delete(ctx context.Context, req resour ctx, cancel := context.WithTimeout(ctx, deleteTimeout) defer cancel() - _, err := r.s3Client.DeleteBucketCorsWithContext(ctx, &s3.DeleteBucketCorsInput{ + if _, err := r.s3Client.DeleteBucketCorsWithContext(ctx, &s3.DeleteBucketCorsInput{ Bucket: state.Bucket.GetPtr(), - }) - if err != nil { + }); err != nil { resp.Diagnostics.AddError("Error deleting CORS policy", err.Error()) return } diff --git a/internal/provider/s3/bucket_cors_configuration_schema.go b/internal/provider/s3/bucket_cors_configuration_schema.go index 224031ed0..9f04a1043 100644 --- a/internal/provider/s3/bucket_cors_configuration_schema.go +++ b/internal/provider/s3/bucket_cors_configuration_schema.go @@ -8,6 +8,9 @@ import ( schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema" schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -18,10 +21,10 @@ import ( func bucketCorsConfigurationSchema(_ context.Context) superschema.Schema { return superschema.Schema{ Resource: superschema.SchemaDetails{ - MarkdownDescription: "The `cloudavenue_s3_bucket_cors_configuration` resource allows you to manage the CORS configuration of an S3 bucket.", + MarkdownDescription: "The `cloudavenue_s3_bucket_cors_configuration` resource allows you to manage the [Cross-Origin Resource Sharing](https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html) configuration of an S3 bucket.", }, DataSource: superschema.SchemaDetails{ - MarkdownDescription: "The `cloudavenue_s3_bucket_cors_configuration` data source allows you to retrieve information about an S3 bucket's CORS configuration.", + MarkdownDescription: "The `cloudavenue_s3_bucket_cors_configuration` data source allows you to retrieve information about an S3 bucket's [Cross-Origin Resource Sharing](https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html) configuration.", }, Attributes: map[string]superschema.Attribute{ "timeouts": superschema.TimeoutAttribute{ @@ -46,6 +49,11 @@ func bucketCorsConfigurationSchema(_ context.Context) superschema.Schema { MarkdownDescription: "The name of the bucket.", Required: true, }, + Resource: &schemaR.StringAttribute{ + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, }, "cors_rules": superschema.SuperSetNestedAttribute{ Common: &schemaR.SetNestedAttribute{ diff --git a/internal/provider/s3/bucket_cors_configuration_schema_test.go b/internal/provider/s3/bucket_cors_configuration_schema_test.go index 1d2b8afb5..21b0dceb3 100644 --- a/internal/provider/s3/bucket_cors_configuration_schema_test.go +++ b/internal/provider/s3/bucket_cors_configuration_schema_test.go @@ -7,14 +7,13 @@ import ( // The fwresource import alias is so there is no collistion // with the more typical acceptance testing import: // "github.com/hashicorp/terraform-plugin-testing/helper/resource". + fwdatasource "github.com/hashicorp/terraform-plugin-framework/datasource" fwresource "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/provider/s3" ) -// TODO : Comment or uncomment the following imports if you are using resources or/and datasources - -// Unit test for the schema of the resource cloudavenue_s3_3BucketCorsConfiguration. +// Unit test for the schema of the resource cloudavenue_s3_bucket_cors_configuration. func Test3BucketCorsConfigurationResourceSchema(t *testing.T) { t.Parallel() @@ -36,16 +35,15 @@ func Test3BucketCorsConfigurationResourceSchema(t *testing.T) { } } -// Unit test for the schema of the datasource cloudavenue_s3_3BucketCorsConfiguration -/* +// Unit test for the schema of the datasource cloudavenue_s3_bucket_cors_configuration. func Test3BucketCorsConfigurationDataSourceSchema(t *testing.T) { t.Parallel() ctx := context.Background() - schemaResponse := &fwresource.SchemaResponse{} + schemaResponse := &fwdatasource.SchemaResponse{} // Instantiate the datasource.Datasource and call its Schema method - s3.New3BucketCorsConfigurationDataSource().Schema(ctx, fwresource.SchemaRequest{}, schemaResponse) + s3.NewBucketCorsConfigurationDatasource().Schema(ctx, fwdatasource.SchemaRequest{}, schemaResponse) if schemaResponse.Diagnostics.HasError() { t.Fatalf("Schema method diagnostics: %+v", schemaResponse.Diagnostics) @@ -58,4 +56,3 @@ func Test3BucketCorsConfigurationDataSourceSchema(t *testing.T) { t.Fatalf("Schema validation diagnostics: %+v", diagnostics) } } -*/