From ed5ef96d358dac203985a6e32aea7204605fbc47 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 Dec 2026 14:20:01 -0800 Subject: [PATCH] terraform/provider: report bucket configuration settings SeaweedFS did not store Co-Authored-By: Claude Opus 5.5 --- .../resource_bucket_configuration.go | 12 +++++- .../resource_bucket_configuration_test.go | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/terraform/provider/seaweedfs/resource_bucket_configuration.go b/terraform/provider/seaweedfs/resource_bucket_configuration.go index 5f0573ea13..5970f3442f 100644 --- a/terraform/provider/seaweedfs/resource_bucket_configuration.go +++ b/terraform/provider/seaweedfs/resource_bucket_configuration.go @@ -189,7 +189,11 @@ func (r *bucketConfigurationResource) Create(ctx context.Context, req resource.C } return } - state.Configuration = plan.Configuration + if state.Configuration.ValueString() != plan.Configuration.ValueString() { + resp.Diagnostics.AddError("Bucket configuration not fully applied", fmt.Sprintf("SeaweedFS stored %s, which differs from the configured document.", state.Configuration.ValueString())) + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) + return + } resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } @@ -236,7 +240,11 @@ func (r *bucketConfigurationResource) Update(ctx context.Context, req resource.U } return } - state.Configuration = plan.Configuration + if state.Configuration.ValueString() != plan.Configuration.ValueString() { + resp.Diagnostics.AddError("Bucket configuration not fully applied", fmt.Sprintf("SeaweedFS stored %s, which differs from the configured document.", state.Configuration.ValueString())) + resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) + return + } resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } diff --git a/terraform/provider/seaweedfs/resource_bucket_configuration_test.go b/terraform/provider/seaweedfs/resource_bucket_configuration_test.go index df2ee0363c..8c062fa3a9 100644 --- a/terraform/provider/seaweedfs/resource_bucket_configuration_test.go +++ b/terraform/provider/seaweedfs/resource_bucket_configuration_test.go @@ -1,10 +1,14 @@ package seaweedfs import ( + "context" "net/url" "testing" s3types "github.com/aws/aws-sdk-go-v2/service/s3/types" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-go/tftypes" ) func TestDecodeBucketConfiguration(t *testing.T) { @@ -138,3 +142,37 @@ func TestBucketQuotaURL(t *testing.T) { t.Errorf("query = %q, want seaweedfs-quota selector", parsed.RawQuery) } } + +func TestBucketConfigurationCreateReportsUnappliedSettings(t *testing.T) { + ctx := context.Background() + stored := "" + r := &bucketConfigurationResource{ + data: &providerData{}, + ops: bucketConfigurationOperations{ + normalize: normalizeBucketConfiguration[s3types.VersioningConfiguration], + put: func(_ context.Context, _ *iamClient, _ string, configuration string) error { + stored = `{"Status":"Enabled"}` + return nil + }, + get: func(context.Context, *iamClient, string) (string, error) { return stored, nil }, + }, + } + var schemaResp resource.SchemaResponse + r.Schema(ctx, resource.SchemaRequest{}, &schemaResp) + objectType := schemaResp.Schema.Type().TerraformType(ctx).(tftypes.Object) + plan := tfsdk.Plan{Schema: schemaResp.Schema, Raw: tftypes.NewValue(objectType, map[string]tftypes.Value{ + "id": tftypes.NewValue(tftypes.String, tftypes.UnknownValue), + "bucket": tftypes.NewValue(tftypes.String, "b1"), + "configuration": tftypes.NewValue(tftypes.String, `{"Status":"Enabled","MFADelete":"Enabled"}`), + })} + resp := resource.CreateResponse{State: tfsdk.State{Schema: schemaResp.Schema, Raw: tftypes.NewValue(objectType, nil)}} + r.Create(ctx, resource.CreateRequest{Plan: plan}, &resp) + if !resp.Diagnostics.HasError() { + t.Fatal("expected a diagnostic for the setting SeaweedFS did not store") + } + var state bucketConfigurationModel + resp.Diagnostics.Append(resp.State.Get(ctx, &state)...) + if got := state.Configuration.ValueString(); got != `{"MFADelete":"","Status":"Enabled"}` { + t.Fatalf("state configuration = %s, want the stored document", got) + } +}