Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate cloudfront service to aws-sdk-go-v2 #36663

Merged
merged 67 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
09d92fc
Migrate `cloudfront` to `aws-sdk-go-v2`
surajsubramanian Mar 30, 2024
33347d7
[service/cloudfront] Fix failing unit tests
surajsubramanian Apr 14, 2024
8405c09
Revert "[service/cloudfront] Fix failing unit tests"
ewbankkit Apr 20, 2024
2d6a730
Revert "Migrate `cloudfront` to `aws-sdk-go-v2`"
ewbankkit Apr 20, 2024
5da2056
Merge branch 'main' into HEAD
ewbankkit Apr 20, 2024
c27b7a5
Solely use AWS SDK for Go v2 for cloudfront service.
ewbankkit Apr 20, 2024
916734d
cloudfront: Generate AWS SDK for Go v2 tagging code.
ewbankkit Apr 20, 2024
518baa2
Run 'make gen'.
ewbankkit Apr 20, 2024
3a5ded1
cloudfront: Tweak AWS SDK for Go v2 tagging code.
ewbankkit Apr 20, 2024
729f6db
r/aws_cloudfront_cache_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 20, 2024
47e57ef
d/aws_cloudfront_cache_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 20, 2024
496a47e
r/aws_cloudfront_field_level_encryption_config: Migrate to AWS SDK fo…
ewbankkit Apr 20, 2024
d7d4834
r/aws_cloudfront_field_level_encryption_profile: Migrate to AWS SDK f…
ewbankkit Apr 20, 2024
b6697f4
r/aws_cloudfront_function: Migrate to AWS SDK for Go v2.
ewbankkit Apr 20, 2024
712ba93
d/aws_cloudfront_function: Migrate to AWS SDK for Go v2.
ewbankkit Apr 20, 2024
6502be5
d/aws_cloudfront_log_delivery_canonical_user_id: Migrate to AWS SDK f…
ewbankkit Apr 20, 2024
2662cc0
[service/cloudfront] Fix failing unit and acceptance tests
surajsubramanian Apr 14, 2024
7d709f8
r/aws_cloudfront_key_group: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
ec5e46a
r/aws_cloudfront_monitoring_subscription: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
788b402
r/aws_cloudfront_origin_access_control: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
41e8b8a
r/aws_cloudfront_origin_access_identity: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
8963640
d/aws_cloudfront_origin_access_identity: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
996a227
d/aws_cloudfront_origin_access_identities: Migrate to AWS SDK for Go v2.
ewbankkit Apr 21, 2024
6aff661
Run make gen
surajsubramanian Apr 22, 2024
bcbe447
r/aws_cloudfront_origin_request_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
5d2ef2f
d/aws_cloudfront_origin_request_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
95aefe6
r/aws_cloudfront_public_key: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
a40a88b
r/aws_cloudfront_realtime_log_config: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
3627215
d/aws_cloudfront_realtime_log_config: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
fa4fb66
r/aws_cloudfront_response_headers_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
4379670
d/aws_cloudfront_response_headers_policy: Migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
b80592d
r/aws_cloudfront_distribution: Start to migrate to AWS SDK for Go v2.
ewbankkit Apr 22, 2024
32cdedb
r/aws_cloudfront_continuous_deployment_policy: Migrate to AWS SDK for…
ewbankkit Apr 22, 2024
ef8c5e9
r/aws_cloudfront_distribution: Migrate to AWS SDK for Go v2.
ewbankkit Apr 24, 2024
8100e25
d/aws_cloudfront_distribution: Migrate to AWS SDK for Go v2.
ewbankkit Apr 24, 2024
93dcfa8
cloudfront: Generate paginators.
ewbankkit Apr 24, 2024
21a6ad2
cloudfront: Migrate sweepers to AWS SDK for Go v2.
ewbankkit Apr 24, 2024
62c0722
r/aws_cloudfront_distribution: Tidy up acceptance tests.
ewbankkit Apr 24, 2024
7a0b943
cloudfront: Reduce visibility.
ewbankkit Apr 24, 2024
fbd6f67
Use 'flex.IntValueToString'.
ewbankkit Apr 24, 2024
086d910
r/aws_cloudfront_distribution: Consolidate source files.
ewbankkit Apr 24, 2024
eb4056b
Fix semgrep errors.
ewbankkit Apr 24, 2024
0de3412
Merge commit 'eb4056bbd1145aa3b067de76825e913020a58b6d' into HEAD
ewbankkit Apr 24, 2024
2656122
Merge branch 'main' into HEAD
ewbankkit Apr 24, 2024
fb86cd6
d/aws_cloudfront_distribution: 'tags' is Computed.
ewbankkit Apr 24, 2024
0c98f8e
Tweak 'acctest.Provider' initialization.
ewbankkit Apr 24, 2024
e6f9ba0
Acceptance test output:
ewbankkit Apr 24, 2024
7f8fce2
r/aws_cloudfront_monitoring_subscription: Handle 'NoSuchMonitoringSub…
ewbankkit Apr 24, 2024
15a1ba0
r/aws_cloudformation_distribution: Make resource Delete more resilient.
ewbankkit Apr 24, 2024
14c2dae
r/aws_cloudformation_distribution: Fix acceptance tests failing in CI.
ewbankkit Apr 24, 2024
c37e8f9
cloudfront: Correct deprecation suppression.
ewbankkit Apr 24, 2024
bc563c3
Fix 'panic: runtime error: invalid memory address or nil pointer dere…
ewbankkit Apr 24, 2024
11c12e8
Fix golangci-lint 'whitespace'.
ewbankkit Apr 25, 2024
58407b0
Fix golangci-lint 'staticcheck/SA4017'.
ewbankkit Apr 25, 2024
fa49a64
Fix golangci-lint 'ineffassign'.
ewbankkit Apr 25, 2024
7e28497
r/aws_cloudfront_response_headers_policy: Fix flattening of StringEnums.
ewbankkit Apr 25, 2024
673ff5c
d/aws_cloudfront_origin_access_identity: Don't forget 'd.SetId'.
ewbankkit Apr 25, 2024
f771ba8
Tweak 'verify.ValidRegionName'.
ewbankkit Apr 25, 2024
e5739e4
Remove 'TestAccCloudFrontDistribution_retainOnDelete' -- "Error: Save…
ewbankkit Apr 25, 2024
9e504ad
r/aws_cloudfront_distribution: Fix some expanders of empty lists.
ewbankkit Apr 25, 2024
1509de1
Skip 'TestAccCloudFrontMonitoringSubscription_update'.
ewbankkit Apr 25, 2024
9a3f3b0
r/aws_cloudfront_continuous_deployment_policy: Correct CustomTypes. f…
ewbankkit Apr 25, 2024
e745fe4
r/aws_cloudfront_continuous_deployment_policy: Fix resource Read.
ewbankkit Apr 25, 2024
73e93e5
Add 'TestFlattenSimpleNestedBlockWithFloat32' and 'TestFlattenComplex…
ewbankkit Apr 25, 2024
e2cd007
Remove 'float64(float32())' conversions that were hiding the issue.
ewbankkit Apr 25, 2024
eae63e1
AutoFlEx: Avoid loss of equivalence when flattening float32.
ewbankkit Apr 25, 2024
84e70c3
Merge remote-tracking branch 'origin/b-autoflex-flatten-float32' into…
ewbankkit Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/.golangci2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ issues:
- linters:
- staticcheck
path: "internal/service/cloudfront"
text: "SA1019: \\w+.(\\w+) is deprecated: (\\w+) has been deprecated"
text: "SA1019: \\w+.(\\w+) is deprecated: This member has been deprecated"
- linters:
- staticcheck
path: "internal/service/cloudtrail"
Expand Down
13 changes: 3 additions & 10 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ var (
// the use of saving and referencing specific ProviderFactories instances.
//
// PreCheck(t) must be called before using this provider instance.
var Provider *schema.Provider
var (
Provider *schema.Provider = errs.Must(provider.New(context.Background()))
)

type ProviderFunc func() *schema.Provider

Expand All @@ -128,15 +130,6 @@ type ProviderFunc func() *schema.Provider
// Provider be errantly reused in ProviderFactories.
var testAccProviderConfigure sync.Once

func init() {
var err error
Provider, err = provider.New(context.Background())

if err != nil {
panic(err)
}
}

func protoV5ProviderFactoriesInit(ctx context.Context, providerNames ...string) map[string]func() (tfprotov5.ProviderServer, error) {
factories := make(map[string]func() (tfprotov5.ProviderServer, error), len(providerNames))

Expand Down
5 changes: 0 additions & 5 deletions internal/conns/awsclient_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func ExpandFloat64List(configured []interface{}) []*float64 {
})
}

func FlattenInt32ValueList(list []int32) []interface{} {
return tfslices.ApplyToAll(list, func(v int32) any {
return int(v)
})
}

// Takes list of pointers to int64s. Expand to an array
// of raw ints and returns a []interface{}
// to keep compatibility w/ schema.NewSet
Expand Down
9 changes: 8 additions & 1 deletion internal/framework/flex/auto_flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
smithyjson "github.com/hashicorp/terraform-provider-aws/internal/json"
"github.com/shopspring/decimal"
)

// Flatten = AWS --> TF
Expand Down Expand Up @@ -143,7 +144,13 @@ func (flattener autoFlattener) float(ctx context.Context, vFrom reflect.Value, i
case basetypes.Float64Typable:
float64Value := types.Float64Null()
if !isNullFrom {
float64Value = types.Float64Value(vFrom.Float())
switch from := vFrom.Interface().(type) {
// Avoid loss of equivalence.
case float32:
float64Value = types.Float64Value(decimal.NewFromFloat32(from).InexactFloat64())
default:
float64Value = types.Float64Value(vFrom.Float())
}
}
v, d := tTo.ValueFromFloat64(ctx, float64Value)
diags.Append(d...)
Expand Down
129 changes: 120 additions & 9 deletions internal/framework/flex/auto_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,14 @@ func TestFlatten(t *testing.T) {
},
Target: &TestFlexTF03{},
WantTarget: &TestFlexTF03{
Field1: types.StringValue("field1"),
Field2: types.StringValue("field2"),
Field3: types.Int64Value(3),
Field4: types.Int64Value(-4),
Field5: types.Int64Value(5),
Field6: types.Int64Value(-6),
// float32 -> float64 precision problems.
Field7: types.Float64Value(float64(float32(7.7))),
Field8: types.Float64Value(float64(float32(-8.8))),
Field1: types.StringValue("field1"),
Field2: types.StringValue("field2"),
Field3: types.Int64Value(3),
Field4: types.Int64Value(-4),
Field5: types.Int64Value(5),
Field6: types.Int64Value(-6),
Field7: types.Float64Value(7.7),
Field8: types.Float64Value(-8.8),
Field9: types.Float64Value(9.99),
Field10: types.Float64Value(-10.101),
Field11: types.BoolValue(true),
Expand Down Expand Up @@ -905,6 +904,118 @@ func TestFlattenComplexSingleNestedBlock(t *testing.T) {
runAutoFlattenTestCases(ctx, t, testCases)
}

func TestFlattenSimpleNestedBlockWithFloat32(t *testing.T) {
t.Parallel()

type tf01 struct {
Field1 types.Int64 `tfsdk:"field1"`
Field2 types.Float64 `tfsdk:"field2"`
}
type aws01 struct {
Field1 int64
Field2 *float32
}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "single nested valid value",
Source: &aws01{Field1: 1, Field2: aws.Float32(0.01)},
Target: &tf01{},
WantTarget: &tf01{Field1: types.Int64Value(1), Field2: types.Float64Value(0.01)},
},
}
runAutoFlattenTestCases(ctx, t, testCases)
}

func TestFlattenComplexNestedBlockWithFloat32(t *testing.T) {
t.Parallel()

type tf01 struct {
Field1 types.Float64 `tfsdk:"field1"`
Field2 types.Float64 `tfsdk:"field2"`
}
type tf02 struct {
Field1 types.Int64 `tfsdk:"field1"`
Field2 fwtypes.ListNestedObjectValueOf[tf01] `tfsdk:"field2"`
}
type aws02 struct {
Field1 float32
Field2 *float32
}
type aws01 struct {
Field1 int64
Field2 *aws02
}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "single nested valid value",
Source: &aws01{Field1: 1, Field2: &aws02{Field1: 1.11, Field2: aws.Float32(-2.22)}},
Target: &tf02{},
WantTarget: &tf02{Field1: types.Int64Value(1), Field2: fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &tf01{Field1: types.Float64Value(1.11), Field2: types.Float64Value(-2.22)})},
},
}
runAutoFlattenTestCases(ctx, t, testCases)
}

func TestFlattenSimpleNestedBlockWithFloat64(t *testing.T) {
t.Parallel()

type tf01 struct {
Field1 types.Int64 `tfsdk:"field1"`
Field2 types.Float64 `tfsdk:"field2"`
}
type aws01 struct {
Field1 int64
Field2 *float64
}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "single nested valid value",
Source: &aws01{Field1: 1, Field2: aws.Float64(0.01)},
Target: &tf01{},
WantTarget: &tf01{Field1: types.Int64Value(1), Field2: types.Float64Value(0.01)},
},
}
runAutoFlattenTestCases(ctx, t, testCases)
}

func TestFlattenComplexNestedBlockWithFloat64(t *testing.T) {
t.Parallel()

type tf01 struct {
Field1 types.Float64 `tfsdk:"field1"`
Field2 types.Float64 `tfsdk:"field2"`
}
type tf02 struct {
Field1 types.Int64 `tfsdk:"field1"`
Field2 fwtypes.ListNestedObjectValueOf[tf01] `tfsdk:"field2"`
}
type aws02 struct {
Field1 float64
Field2 *float64
}
type aws01 struct {
Field1 int64
Field2 *aws02
}

ctx := context.Background()
testCases := autoFlexTestCases{
{
TestName: "single nested valid value",
Source: &aws01{Field1: 1, Field2: &aws02{Field1: 1.11, Field2: aws.Float64(-2.22)}},
Target: &tf02{},
WantTarget: &tf02{Field1: types.Int64Value(1), Field2: fwtypes.NewListNestedObjectValueOfPtrMust(ctx, &tf01{Field1: types.Float64Value(1.11), Field2: types.Float64Value(-2.22)})},
},
}
runAutoFlattenTestCases(ctx, t, testCases)
}

func runAutoFlattenTestCases(ctx context.Context, t *testing.T, testCases autoFlexTestCases) {
t.Helper()

Expand Down
Loading
Loading