mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
terraform/provider: report bucket configuration settings SeaweedFS did not store
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c0c08bd06
commit
ed5ef96d35
2 files changed
+48
-2
No files matched your search
@@ -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)...)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user