diff --git a/.changelog/1.txt b/.changelog/1.txt new file mode 100644 index 000000000000..cab245f1d6fb --- /dev/null +++ b/.changelog/1.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_s3_bucket_lifecycle_configuration: Normalize empty prefix values when reading lifecycle configurations from S3-compatible services +``` diff --git a/internal/service/s3/bucket_lifecycle_configuration.go b/internal/service/s3/bucket_lifecycle_configuration.go index fe2014ccaa35..9471ac098309 100644 --- a/internal/service/s3/bucket_lifecycle_configuration.go +++ b/internal/service/s3/bucket_lifecycle_configuration.go @@ -627,6 +627,17 @@ func findBucketLifecycleConfiguration(ctx context.Context, conn *s3.Client, buck } } + // For legacy-mode reasons, we normalize empty `prefix` is nil when making requests to S3 and storing internal state. + // Some S3 compatible services might return empty string as an equivalent representation. To maintain a consistent state we should normalize that back to nil. + for i := range output.Rules { + rule := &output.Rules[i] + //nolint:staticcheck // Yes the attribute Prefix is deprecated, but the following functionality is required for compatibility with non AWS systems + if aws.ToString((*rule).Prefix) == "" { + //nolint:staticcheck // Yes the attribute Prefix is deprecated, but the following functionality is required for compatibility with non AWS systems + (*rule).Prefix = nil + } + } + if err != nil { return nil, err }