Skip to content

Commit

Permalink
fix: minor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
azrod committed Oct 19, 2023
1 parent f25fc53 commit 0f57505
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/resources/s3_bucket_cors_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions internal/provider/s3/bucket_cors_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions internal/provider/s3/bucket_cors_configuration_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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{
Expand All @@ -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{
Expand Down
13 changes: 5 additions & 8 deletions internal/provider/s3/bucket_cors_configuration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -58,4 +56,3 @@ func Test3BucketCorsConfigurationDataSourceSchema(t *testing.T) {
t.Fatalf("Schema validation diagnostics: %+v", diagnostics)
}
}
*/

0 comments on commit 0f57505

Please sign in to comment.