Skip to content

Commit 10a6b16

Browse files
authored
Merge pull request #37024 from mattburgess/cognitoidp-awssdkv2-migration
cognitoidp: Migrate to AWS SDK v2
2 parents 05c56fa + 1d2432c commit 10a6b16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3104
-3011
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ require (
6565
github.com/aws/aws-sdk-go-v2/service/codestarconnections v1.26.1
6666
github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.23.1
6767
github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.24.1
68+
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.40.1
6869
github.com/aws/aws-sdk-go-v2/service/comprehend v1.32.1
6970
github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.36.0
7071
github.com/aws/aws-sdk-go-v2/service/configservice v1.47.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.23.1 h1:Y6zYm5uoyV
150150
github.com/aws/aws-sdk-go-v2/service/codestarnotifications v1.23.1/go.mod h1:eLxEKHbDZAZ21Kd9MoiVwTHuKNBfYSNgqp9IvtqodsA=
151151
github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.24.1 h1:grnSpw0UYD7mZpV4cbIrHroG5geUkLdZG9Nw6y+2mY4=
152152
github.com/aws/aws-sdk-go-v2/service/cognitoidentity v1.24.1/go.mod h1:GjlJPEWhuchMZu+5ANvFJ40v2D/Yf15GKtSQrEii9g8=
153+
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.40.1 h1:5jYRvUIEI0LVOUYbI6ixev/ctOb8/0eJDFa6k39cMCk=
154+
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.40.1/go.mod h1:im0buuAzIxokGb9JH/bXAhiDxp9OElYL6jSQXTLiRcA=
153155
github.com/aws/aws-sdk-go-v2/service/comprehend v1.32.1 h1:aaO83HGlxNkzuusYpfQKLb5p8Nh5fT9Z0AZGOMCgV0s=
154156
github.com/aws/aws-sdk-go-v2/service/comprehend v1.32.1/go.mod h1:sceZD+zPJMiCXh57FxceWpqgNsNWST11mkCKKOxPzus=
155157
github.com/aws/aws-sdk-go-v2/service/computeoptimizer v1.36.0 h1:M4beLC7La5LbQmUU+NCp4dOJ+1PDeJB7sxkvMREv5L4=

internal/acctest/acctest.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
accounttypes "github.com/aws/aws-sdk-go-v2/service/account/types"
2525
"github.com/aws/aws-sdk-go-v2/service/acmpca"
2626
acmpcatypes "github.com/aws/aws-sdk-go-v2/service/acmpca/types"
27+
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
2728
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
2829
"github.com/aws/aws-sdk-go-v2/service/iam"
2930
awstypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
@@ -40,6 +41,7 @@ import (
4041
"github.com/aws/aws-sdk-go/service/directoryservice"
4142
"github.com/aws/aws-sdk-go/service/ec2"
4243
"github.com/aws/aws-sdk-go/service/outposts"
44+
"github.com/aws/aws-sdk-go/service/pinpoint"
4345
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
4446
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
4547
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -979,6 +981,26 @@ func PreCheckPartitionNot(t *testing.T, partitions ...string) {
979981
}
980982
}
981983

984+
func PreCheckCognitoIdentityProvider(ctx context.Context, t *testing.T) {
985+
t.Helper()
986+
987+
conn := Provider.Meta().(*conns.AWSClient).CognitoIDPClient(ctx)
988+
989+
input := &cognitoidentityprovider.ListUserPoolsInput{
990+
MaxResults: aws.Int32(1),
991+
}
992+
993+
_, err := conn.ListUserPools(ctx, input)
994+
995+
if PreCheckSkipError(err) {
996+
t.Skipf("skipping acceptance testing: %s", err)
997+
}
998+
999+
if err != nil {
1000+
t.Fatalf("unexpected PreCheck error: %s", err)
1001+
}
1002+
}
1003+
9821004
func PreCheckInspector2(ctx context.Context, t *testing.T) {
9831005
t.Helper()
9841006

@@ -1077,6 +1099,22 @@ func PreCheckOrganizationMemberAccountWithProvider(ctx context.Context, t *testi
10771099
}
10781100
}
10791101

1102+
func PreCheckPinpointApp(ctx context.Context, t *testing.T) {
1103+
conn := Provider.Meta().(*conns.AWSClient).PinpointConn(ctx)
1104+
1105+
input := &pinpoint.GetAppsInput{}
1106+
1107+
_, err := conn.GetAppsWithContext(ctx, input)
1108+
1109+
if PreCheckSkipError(err) {
1110+
t.Skipf("skipping acceptance testing: %s", err)
1111+
}
1112+
1113+
if err != nil {
1114+
t.Fatalf("unexpected PreCheck error: %s", err)
1115+
}
1116+
}
1117+
10801118
func PreCheckRegionOptIn(ctx context.Context, t *testing.T, region string) {
10811119
t.Helper()
10821120

internal/conns/awsclient_gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/framework/flex/bool.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ func BoolFromFramework(ctx context.Context, v basetypes.BoolValuable) *bool {
2121
return output
2222
}
2323

24+
func BoolValueFromFramework(ctx context.Context, v basetypes.BoolValuable) bool {
25+
var output bool
26+
27+
must(Expand(ctx, v, &output))
28+
29+
return output
30+
}
31+
2432
// BoolToFramework converts a bool pointer to a Framework Bool value.
2533
// A nil bool pointer is converted to a null Bool.
2634
func BoolToFramework(ctx context.Context, v *bool) types.Bool {

internal/framework/flex/bool_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ func TestBoolFromFramework(t *testing.T) {
4949
}
5050
}
5151

52+
func TestBoolValueFromFramework(t *testing.T) {
53+
t.Parallel()
54+
55+
type testCase struct {
56+
input types.Bool
57+
expected bool
58+
}
59+
tests := map[string]testCase{
60+
"valid bool": {
61+
input: types.BoolValue(true),
62+
expected: true,
63+
},
64+
"null bool": {
65+
input: types.BoolNull(),
66+
expected: false,
67+
},
68+
"unknown bool": {
69+
input: types.BoolUnknown(),
70+
expected: false,
71+
},
72+
}
73+
74+
for name, test := range tests {
75+
name, test := name, test
76+
t.Run(name, func(t *testing.T) {
77+
t.Parallel()
78+
79+
got := flex.BoolValueFromFramework(context.Background(), test.input)
80+
81+
if diff := cmp.Diff(got, test.expected); diff != "" {
82+
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
83+
}
84+
})
85+
}
86+
}
87+
5288
func TestBoolToFramework(t *testing.T) {
5389
t.Parallel()
5490

internal/framework/flex/int.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ func Int32ValueToFramework(ctx context.Context, v int32) types.Int64 {
6666
return output
6767
}
6868

69+
// Int32ToFrameworkLegacy converts an int32 pointer to a Framework Int64 value.
70+
// A nil int32 pointer is converted to a zero Int64.
71+
func Int32ToFrameworkLegacy(_ context.Context, v *int32) types.Int64 {
72+
return types.Int64Value(int64(aws.ToInt32(v)))
73+
}
74+
6975
// Int32FromFramework coverts a Framework Int64 value to an int32 pointer.
7076
// A null Int64 is converted to a nil int32 pointer.
7177
func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {
@@ -76,6 +82,19 @@ func Int32FromFramework(ctx context.Context, v types.Int64) *int32 {
7682
return output
7783
}
7884

85+
func Int32FromFrameworkLegacy(_ context.Context, v types.Int64) *int32 {
86+
if v.IsNull() || v.IsUnknown() {
87+
return nil
88+
}
89+
90+
i := v.ValueInt64()
91+
if i == 0 {
92+
return nil
93+
}
94+
95+
return aws.Int32(int32(i))
96+
}
97+
7998
// Int32ValueFromFramework coverts a Framework Int64 value to an int32 pointer.
8099
// A null Int64 is converted to a nil int32 pointer.
81100
func Int32ValueFromFramework(ctx context.Context, v types.Int64) int32 {

internal/framework/flex/int_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,42 @@ func TestInt32ToFramework(t *testing.T) {
161161
}
162162
}
163163

164+
func TestInt32ToFrameworkLegacy(t *testing.T) {
165+
t.Parallel()
166+
167+
type testCase struct {
168+
input *int32
169+
expected types.Int64
170+
}
171+
tests := map[string]testCase{
172+
"valid int64": {
173+
input: aws.Int32(42),
174+
expected: types.Int64Value(42),
175+
},
176+
"zero int64": {
177+
input: aws.Int32(0),
178+
expected: types.Int64Value(0),
179+
},
180+
"nil int64": {
181+
input: nil,
182+
expected: types.Int64Value(0),
183+
},
184+
}
185+
186+
for name, test := range tests {
187+
name, test := name, test
188+
t.Run(name, func(t *testing.T) {
189+
t.Parallel()
190+
191+
got := flex.Int32ToFrameworkLegacy(context.Background(), test.input)
192+
193+
if diff := cmp.Diff(got, test.expected); diff != "" {
194+
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
195+
}
196+
})
197+
}
198+
}
199+
164200
func TestInt32FromFramework(t *testing.T) {
165201
t.Parallel()
166202

@@ -200,3 +236,43 @@ func TestInt32FromFramework(t *testing.T) {
200236
})
201237
}
202238
}
239+
240+
func TestInt32FromFrameworkLegacy(t *testing.T) {
241+
t.Parallel()
242+
243+
type testCase struct {
244+
input types.Int64
245+
expected *int32
246+
}
247+
tests := map[string]testCase{
248+
"valid int64": {
249+
input: types.Int64Value(42),
250+
expected: aws.Int32(42),
251+
},
252+
"zero int64": {
253+
input: types.Int64Value(0),
254+
expected: nil,
255+
},
256+
"null int64": {
257+
input: types.Int64Null(),
258+
expected: nil,
259+
},
260+
"unknown int64": {
261+
input: types.Int64Unknown(),
262+
expected: nil,
263+
},
264+
}
265+
266+
for name, test := range tests {
267+
name, test := name, test
268+
t.Run(name, func(t *testing.T) {
269+
t.Parallel()
270+
271+
got := flex.Int32FromFrameworkLegacy(context.Background(), test.input)
272+
273+
if diff := cmp.Diff(got, test.expected); diff != "" {
274+
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
275+
}
276+
})
277+
}
278+
}

internal/framework/flex/set.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/attr"
1111
"github.com/hashicorp/terraform-plugin-framework/types"
1212
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
13+
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
1314
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
1415
)
1516

@@ -61,6 +62,14 @@ func ExpandFrameworkStringValueSet(ctx context.Context, v basetypes.SetValuable)
6162
return output
6263
}
6364

65+
func ExpandFrameworkStringyValueSet[T ~string](ctx context.Context, v basetypes.SetValuable) itypes.Set[T] {
66+
vs := ExpandFrameworkStringValueSet(ctx, v)
67+
if vs == nil {
68+
return nil
69+
}
70+
return tfslices.ApplyToAll(vs, func(s string) T { return T(s) })
71+
}
72+
6473
// FlattenFrameworkInt64Set converts a slice of int32 pointers to a framework Set value.
6574
//
6675
// A nil slice is converted to a null Set.

internal/framework/flex/set_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,59 @@ func TestExpandFrameworkStringValueSet(t *testing.T) {
309309
}
310310
}
311311

312+
func TestExpandFrameworkStringyValueSet(t *testing.T) {
313+
t.Parallel()
314+
315+
type testEnum string
316+
var testVal1 testEnum = "testVal1"
317+
var testVal2 testEnum = "testVal2"
318+
319+
type testCase struct {
320+
input types.Set
321+
expected itypes.Set[testEnum]
322+
}
323+
tests := map[string]testCase{
324+
"null": {
325+
input: types.SetNull(types.StringType),
326+
expected: nil,
327+
},
328+
"unknown": {
329+
input: types.SetUnknown(types.StringType),
330+
expected: nil,
331+
},
332+
"two elements": {
333+
input: types.SetValueMust(types.StringType, []attr.Value{
334+
types.StringValue(string(testVal1)),
335+
types.StringValue(string(testVal2)),
336+
}),
337+
expected: []testEnum{testVal1, testVal2},
338+
},
339+
"zero elements": {
340+
input: types.SetValueMust(types.StringType, []attr.Value{}),
341+
expected: []testEnum{},
342+
},
343+
"invalid element type": {
344+
input: types.SetValueMust(types.Int64Type, []attr.Value{
345+
types.Int64Value(42),
346+
}),
347+
expected: nil,
348+
},
349+
}
350+
351+
for name, test := range tests {
352+
name, test := name, test
353+
t.Run(name, func(t *testing.T) {
354+
t.Parallel()
355+
356+
got := flex.ExpandFrameworkStringyValueSet[testEnum](context.Background(), test.input)
357+
358+
if diff := cmp.Diff(got, test.expected); diff != "" {
359+
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
360+
}
361+
})
362+
}
363+
}
364+
312365
func TestFlattenFrameworkInt32Set(t *testing.T) {
313366
t.Parallel()
314367

internal/service/cognitoidentity/pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,19 @@ func resourcePoolUpdate(ctx context.Context, d *schema.ResourceData, meta interf
248248
func resourcePoolDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
249249
var diags diag.Diagnostics
250250
conn := meta.(*conns.AWSClient).CognitoIdentityClient(ctx)
251-
log.Printf("[DEBUG] Deleting Cognito Identity Pool: %s", d.Id())
252251

252+
log.Printf("[DEBUG] Deleting Cognito Identity Pool: %s", d.Id())
253253
_, err := conn.DeleteIdentityPool(ctx, &cognitoidentity.DeleteIdentityPoolInput{
254254
IdentityPoolId: aws.String(d.Id()),
255255
})
256256

257257
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
258-
log.Printf("[DEBUG] Resource Pool already deleted: %s", d.Id())
259258
return diags
260259
}
261260

262261
if err != nil {
263-
return sdkdiag.AppendErrorf(diags, "deleting Cognito identity pool (%s): %s", d.Id(), err)
262+
return sdkdiag.AppendErrorf(diags, "deleting Cognito Identity Pool (%s): %s", d.Id(), err)
264263
}
264+
265265
return diags
266266
}

0 commit comments

Comments
 (0)