Skip to content

Commit

Permalink
Merge pull request #41159 from hashicorp/b-s3-bucket-lifecycle-min-size
Browse files Browse the repository at this point in the history
resource/aws_s3_bucket_lifecycle_configuration: Set `transition_default_minimum_object_size` to default when removing from Terraform configuration
  • Loading branch information
gdavison authored Feb 6, 2025
2 parents 870961c + dd04ca5 commit 65ec3bc
Show file tree
Hide file tree
Showing 20 changed files with 4,584 additions and 1,014 deletions.
7 changes: 7 additions & 0 deletions .changelog/41159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_s3_bucket_lifecycle_configuration: Properly handle default value of `transition_default_minimum_object_size`
```

```release-note:note
resource/aws_s3_bucket_lifecycle_configuration: When upgrading existing resources with no defined `prefix`, the Terraform plan will show the removal of `prefix` from state. This is expected, and should not occur on subsequent plans.
```
6 changes: 3 additions & 3 deletions internal/framework/flex/auto_flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (flattener autoFlattener) float64(ctx context.Context, vFrom reflect.Value,
case basetypes.Float32Typable:
// Only returns an error when the target type is Float32Typable to prevent breaking existing resources
tflog.SubsystemError(ctx, subsystemName, "Flattening incompatible types")
diags.Append(diagFlatteningIncompatibleTypes(sourceType, vTo.Type()))
diags.Append(DiagFlatteningIncompatibleTypes(sourceType, vTo.Type()))
return diags
}

Expand Down Expand Up @@ -405,7 +405,7 @@ func (flattener autoFlattener) int64(ctx context.Context, vFrom reflect.Value, s
case basetypes.Int32Typable:
// Only returns an error when the target type is Int32Typeable to prevent breaking existing resources
tflog.SubsystemError(ctx, subsystemName, "Flattening incompatible types")
diags.Append(diagFlatteningIncompatibleTypes(sourceType, vTo.Type()))
diags.Append(DiagFlatteningIncompatibleTypes(sourceType, vTo.Type()))
return diags
}

Expand Down Expand Up @@ -1671,7 +1671,7 @@ func diagFlatteningMarshalSmithyDocument(sourceType reflect.Type, err error) dia
)
}

func diagFlatteningIncompatibleTypes(sourceType, targetType reflect.Type) diag.ErrorDiagnostic {
func DiagFlatteningIncompatibleTypes(sourceType, targetType reflect.Type) diag.ErrorDiagnostic {
return diag.NewErrorDiagnostic(
"Incompatible Types",
"An unexpected error occurred while flattening configuration. "+
Expand Down
20 changes: 10 additions & 10 deletions internal/framework/flex/auto_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ func TestFlattenFloat32(t *testing.T) {
},
Target: &tfSingleFloat32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[float64](), reflect.TypeFor[types.Float32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[float64](), reflect.TypeFor[types.Float32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleFloat64Value](), reflect.TypeFor[*tfSingleFloat32Field]()),
Expand All @@ -1614,7 +1614,7 @@ func TestFlattenFloat32(t *testing.T) {
},
Target: &tfSingleFloat32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[float64](), reflect.TypeFor[types.Float32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[float64](), reflect.TypeFor[types.Float32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleFloat64Value](), reflect.TypeFor[*tfSingleFloat32Field]()),
Expand All @@ -1633,7 +1633,7 @@ func TestFlattenFloat32(t *testing.T) {
},
Target: &tfSingleFloat32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleFloat64Pointer](), reflect.TypeFor[*tfSingleFloat32Field]()),
Expand All @@ -1649,7 +1649,7 @@ func TestFlattenFloat32(t *testing.T) {
},
Target: &tfSingleFloat32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleFloat64Pointer](), reflect.TypeFor[*tfSingleFloat32Field]()),
Expand All @@ -1665,7 +1665,7 @@ func TestFlattenFloat32(t *testing.T) {
},
Target: &tfSingleFloat32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*float64](), reflect.TypeFor[types.Float32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleFloat64Pointer](), reflect.TypeFor[*tfSingleFloat32Field]()),
Expand Down Expand Up @@ -2110,7 +2110,7 @@ func TestFlattenInt32(t *testing.T) {
},
Target: &tfSingleInt32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[int64](), reflect.TypeFor[types.Int32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[int64](), reflect.TypeFor[types.Int32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleInt64Value](), reflect.TypeFor[*tfSingleInt32Field]()),
Expand All @@ -2126,7 +2126,7 @@ func TestFlattenInt32(t *testing.T) {
},
Target: &tfSingleInt32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[int64](), reflect.TypeFor[types.Int32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[int64](), reflect.TypeFor[types.Int32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleInt64Value](), reflect.TypeFor[*tfSingleInt32Field]()),
Expand All @@ -2145,7 +2145,7 @@ func TestFlattenInt32(t *testing.T) {
},
Target: &tfSingleInt32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleInt64Pointer](), reflect.TypeFor[*tfSingleInt32Field]()),
Expand All @@ -2161,7 +2161,7 @@ func TestFlattenInt32(t *testing.T) {
},
Target: &tfSingleInt32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleInt64Pointer](), reflect.TypeFor[*tfSingleInt32Field]()),
Expand All @@ -2177,7 +2177,7 @@ func TestFlattenInt32(t *testing.T) {
},
Target: &tfSingleInt32Field{},
expectedDiags: diag.Diagnostics{
diagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
DiagFlatteningIncompatibleTypes(reflect.TypeFor[*int64](), reflect.TypeFor[types.Int32]()),
},
expectedLogLines: []map[string]any{
infoFlattening(reflect.TypeFor[awsSingleInt64Pointer](), reflect.TypeFor[*tfSingleInt32Field]()),
Expand Down
29 changes: 27 additions & 2 deletions internal/framework/flex/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,37 @@ func Int32FromFramework(ctx context.Context, v basetypes.Int64Valuable) *int32 {
return output
}

// Int32ValueFromFramework coverts a Framework Int64 value to an int32 pointer.
// Int32FromFrameworkInt32 coverts a Framework Int32 value to an int32 pointer.
// A null Int32 is converted to a nil int32 pointer.
// TODO: Rename to Int32FromFramework
func Int32FromFrameworkInt32(ctx context.Context, v basetypes.Int32Valuable) *int32 {
var output *int32

must(Expand(ctx, v, &output))

return output
}

// Int32ValueFromFrameworkInt64 coverts a Framework Int64 value to an int32 value.
// A null Int64 is converted to a nil int32 pointer.
func Int32ValueFromFramework(ctx context.Context, v basetypes.Int64Valuable) int32 {
func Int32ValueFromFrameworkInt64(ctx context.Context, v basetypes.Int64Valuable) int32 {
var output int32

must(Expand(ctx, v, &output))

return output
}

var Int32ValueFromFramework = Int32ValueFromFrameworkInt64

func ZeroInt32AsNull(v types.Int32) types.Int32 {
if v.IsNull() || v.IsUnknown() {
return v
}

if v.ValueInt32() == 0 {
return types.Int32Null()
}

return v
}
8 changes: 4 additions & 4 deletions internal/service/s3/bucket_accelerate_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func resourceBucketAccelerateConfigurationCreate(ctx context.Context, d *schema.
return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) Accelerate Configuration: %s", bucket, err)
}

d.SetId(CreateResourceID(bucket, expectedBucketOwner))
d.SetId(createResourceID(bucket, expectedBucketOwner))

_, err = tfresource.RetryWhenNotFound(ctx, bucketPropagationTimeout, func() (interface{}, error) {
return findBucketAccelerateConfiguration(ctx, conn, bucket, expectedBucketOwner)
Expand All @@ -105,7 +105,7 @@ func resourceBucketAccelerateConfigurationRead(ctx context.Context, d *schema.Re
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func resourceBucketAccelerateConfigurationUpdate(ctx context.Context, d *schema.
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func resourceBucketAccelerateConfigurationDelete(ctx context.Context, d *schema.
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/service/s3/bucket_cors_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func resourceBucketCorsConfigurationCreate(ctx context.Context, d *schema.Resour
return sdkdiag.AppendErrorf(diags, "creating S3 Bucket (%s) CORS Configuration: %s", bucket, err)
}

d.SetId(CreateResourceID(bucket, expectedBucketOwner))
d.SetId(createResourceID(bucket, expectedBucketOwner))

_, err = tfresource.RetryWhenNotFound(ctx, bucketPropagationTimeout, func() (interface{}, error) {
return findCORSRules(ctx, conn, bucket, expectedBucketOwner)
Expand All @@ -138,7 +138,7 @@ func resourceBucketCorsConfigurationRead(ctx context.Context, d *schema.Resource
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func resourceBucketCorsConfigurationUpdate(ctx context.Context, d *schema.Resour
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func resourceBucketCorsConfigurationDelete(ctx context.Context, d *schema.Resour
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).S3Client(ctx)

bucket, expectedBucketOwner, err := ParseResourceID(d.Id())
bucket, expectedBucketOwner, err := parseResourceID(d.Id())
if err != nil {
return sdkdiag.AppendFromErr(diags, err)
}
Expand Down
Loading

0 comments on commit 65ec3bc

Please sign in to comment.