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

ecs: Migrate to AWS SDK v2 #38016

Merged
merged 63 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
334286c
ecs: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
a91da09
Run make gen
mattburgess Jun 13, 2024
1d7af07
r/ecs_account_setting_default: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
c5bbf42
r/ecs_capacity_provider: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
e53d516
r/cluster_capacity_providers: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
1b3457b
d/ecs_cluster, r/ecs_cluster: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
0d4a4a2
d/container_definition: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
67804c9
d/ecs_service: Migrate to AWS SDK v2
mattburgess Jun 13, 2024
5f12a37
r/ecs_task_set: Migrate to AWS SDK v2
mattburgess Jun 17, 2024
ec8eb53
d/ecs_task_execution: Migrate to AWS SDK v2
mattburgess Jun 17, 2024
cb7a2ff
d/ecs_task_definition, r/ecs_task_definition: Migrate to AWS SDK v2
mattburgess Jun 17, 2024
e3233fe
r/ecs_service: Migrate to AWS SDK v2
mattburgess Jun 17, 2024
f152335
Fix lint
mattburgess Jun 17, 2024
00a919d
Merge branch 'main' into HEAD
ewbankkit Jul 15, 2024
fa7cf55
ecs: Comment out ContainerDefinitionsAreEquivalent tests.
ewbankkit Jul 15, 2024
b9a8294
Merge branch 'main' into HEAD
ewbankkit Jul 16, 2024
4bbfea2
r/aws_ecs_account_setting_default: Reduce visibility.
ewbankkit Jul 16, 2024
e09bd20
Acceptance test output:
ewbankkit Jul 16, 2024
252baa7
Add 'json.DecodeFromString' and 'json.DecodeFromReader'.
ewbankkit Jul 16, 2024
6f47839
Replace 'internal/vault/sdk/helper/jsonutil' with 'internal/json'.
ewbankkit Jul 16, 2024
00a7ca6
Add 'acctest/jsoncmp' package.
ewbankkit Jul 16, 2024
77c976c
Add 'json.EncodeToString' and 'json.EncodeToBytes'.
ewbankkit Jul 16, 2024
35a3734
dynamodb: Use 'tfjson' functions.
ewbankkit Jul 16, 2024
e3444e3
Acceptance test output:
ewbankkit Jul 16, 2024
ed4e16f
Add 'json.DecodeFromBytes'.
ewbankkit Jul 16, 2024
b811e73
Add 'json.EqualBytes' and 'json.EqualStrings'.
ewbankkit Jul 16, 2024
5b63982
Some tweaks.
ewbankkit Jul 16, 2024
bb0e0a5
ContainerDefinitionsAreEquivalent: Restore unit tests.
ewbankkit Jul 16, 2024
1165b8f
Global 'fargateTaskRetirementWaitPeriodValue' is unused.
ewbankkit Jul 16, 2024
2ce7f18
r/aws_dms_certificate: Remove use of 'tfslices.ToPointers'.
ewbankkit Jul 16, 2024
db22363
Acceptance test output:
ewbankkit Jul 16, 2024
c02be8c
r/aws_apprunner_connection: Remove use of 'tfslices.ToPointers'.
ewbankkit Jul 16, 2024
b7e160e
Acceptance test output:
ewbankkit Jul 16, 2024
5b993e0
r/aws_appstream_user: Remove use of 'tfslices.ToPointers'.
ewbankkit Jul 17, 2024
e7bf251
r/aws_appstream_image_builder: 'AppStream-WinServer2022-03-24-2024' -…
ewbankkit Jul 17, 2024
498f83d
Acceptance test output:
ewbankkit Jul 17, 2024
c872312
r/aws_autoscaling_lifecycle_hook: Remove use of 'tfslices.ToPointers'.
ewbankkit Jul 17, 2024
41510be
Acceptance test output:
ewbankkit Jul 17, 2024
2a373f5
r/aws_ecr_lifecycle_policy: Eliminate use of 'github.com/aws/aws-sdk-…
ewbankkit Jul 17, 2024
b21e242
Acceptance test output:
ewbankkit Jul 17, 2024
0b51dfc
r/aws_ecs_task_definition: Eliminate use of 'github.com/aws/aws-sdk-g…
ewbankkit Jul 17, 2024
eec09dc
r/aws_ecs_capacity_provider: Reduce visibility.
ewbankkit Jul 17, 2024
59dfb26
r/aws_ecs_cluster_capacity_providers: Reduce visibility.
ewbankkit Jul 17, 2024
61fd393
r/aws_ecs+cluster: Reduce visibility.
ewbankkit Jul 17, 2024
40d7c91
d/aws_ecs_cluster: Reduce visibility.
ewbankkit Jul 17, 2024
27f0618
d/aws_ecs_container_definition: Reduce visibility.
ewbankkit Jul 17, 2024
10e8a0a
r/aws_ecs_service: Reduce visibility.
ewbankkit Jul 17, 2024
5289211
r/aws_ecs_task_definition: Reduce visibility.
ewbankkit Jul 17, 2024
9559009
d/aws_ecs_task_definition: Reduce visibility.
ewbankkit Jul 17, 2024
6afe79d
Eliminate use of 'github.com/aws/aws-sdk-go/private/protocol/json/jso…
ewbankkit Jul 17, 2024
ddfed7c
d/aws_ecs_task_execution: Reduce visibility.
ewbankkit Jul 17, 2024
9b43382
r/aws_ecs_task_set: Reduce visibility.
ewbankkit Jul 17, 2024
dc56bb3
Fix golangci-lint 'unparam'.
ewbankkit Jul 17, 2024
1ada017
Fix golangci-lint 'unparam'.
ewbankkit Jul 17, 2024
51ef973
Merge branch 'main' into HEAD
ewbankkit Jul 17, 2024
e7fd913
Cosmetics.
ewbankkit Jul 17, 2024
86bfb11
ecs: Tidy up sweepers.
ewbankkit Jul 17, 2024
2476b3e
r/aws_ecs_task_definition: Set 'arn' in Create.
ewbankkit Jul 17, 2024
dd157df
Fix 'taskSetParseResourceID'.
ewbankkit Jul 17, 2024
7f700dd
Fix 'TestAccECSService_PlacementStrategy_missing'.
ewbankkit Jul 17, 2024
1b56aa7
ecs: Skip acceptance test errors like 'InvalidParameterException: ECS…
ewbankkit Jul 17, 2024
8887eba
Fix 'TestAccECSService_PlacementStrategy_missing'.
ewbankkit Jul 18, 2024
3c94609
Fix 'TestAccECSTaskDefinition_invalidContainerDefinition'.
ewbankkit Jul 18, 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
32 changes: 32 additions & 0 deletions internal/acctest/jsoncmp/compare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package jsoncmp

// Inspired by https://github.com/hgsgtk/jsoncmp.

import (
"encoding/json"
"fmt"

"github.com/google/go-cmp/cmp"
)

func Diff(x, y string) string {
xform := cmp.Transformer("jsoncmp", func(s string) (m map[string]any) {
if err := json.Unmarshal([]byte(s), &m); err != nil {
panic(fmt.Sprintf("json.Unmarshal(%s): %s", s, err))
}
return m
})
opt := cmp.FilterPath(func(p cmp.Path) bool {
for _, ps := range p {
if tr, ok := ps.(cmp.Transform); ok && tr.Option() == xform {
return false
}
}
return true
}, xform)

return cmp.Diff(x, y, opt)
}
44 changes: 44 additions & 0 deletions internal/acctest/jsoncmp/compare_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package jsoncmp_test

import (
"testing"

"github.com/hashicorp/terraform-provider-aws/internal/acctest/jsoncmp"
)

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

testCases := []struct {
testName string
x, y string
wantDiff bool
}{
{
testName: "no diff",
x: `{"A": "test1", "D": ["test2", "test3"], "C": {"A": true}, "B": 42}`,
y: `{"A":"test1", "B":42, "C":{"A":true}, "D": ["test2", "test3"]}`,
},
{
testName: "has diff",
x: `{"A": "test1", "D": ["test2", "test3"], "C": {"A": true}, "B": 42}`,
y: `{"A":"test1", "B":41, "C":{"A":true}, "D": ["test3"]}`,
wantDiff: true,
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.testName, func(t *testing.T) {
t.Parallel()

output := jsoncmp.Diff(testCase.x, testCase.y)
if got, want := output != "", testCase.wantDiff; got != want {
t.Errorf("Diff(%s, %s) = %t, want %t", testCase.x, testCase.y, got, want)
}
})
}
}
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.

4 changes: 2 additions & 2 deletions internal/errs/unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package errs

import (
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
tfawserr_sdkv2 "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
"github.com/hashicorp/terraform-provider-aws/names"
)

const (
Expand Down Expand Up @@ -34,7 +34,7 @@ const (
// Be careful with a return value of `false`, which means either there is NO error
// or there is an error but not one that suggests an unsupported feature in ISO.
func IsUnsupportedOperationInPartitionError(partition string, err error) bool {
if partition == endpoints.AwsPartitionID {
if partition == names.StandardPartitionID {
return false
}

Expand Down
36 changes: 36 additions & 0 deletions internal/json/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package json

import (
"bytes"
"encoding/json"
"io"
"strings"
)

// DecodeFromBytes decodes (unmarshals) the given byte slice, containing valid JSON, into `to`.
func DecodeFromBytes(b []byte, to any) error {
return DecodeFromReader(bytes.NewReader(b), to)
}

// DecodeFromReader decodes (unmarshals) the given io.Reader, pointing to a JSON stream, into `to`.
func DecodeFromReader(r io.Reader, to any) error {
dec := json.NewDecoder(r)

for {
if err := dec.Decode(to); err == io.EOF {
break
} else if err != nil {
return err
}
}

return nil
}

// DecodeFromString decodes (unmarshals) the given string, containing valid JSON, into `to`.
func DecodeFromString(s string, to any) error {
return DecodeFromReader(strings.NewReader(s), to)
}
77 changes: 77 additions & 0 deletions internal/json/decode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package json_test

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-provider-aws/internal/json"
)

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

type to struct {
A string
B int
C struct {
A bool
}
D []string
}
var to0, to1, to2, to3 to
to4 := to{
A: "test1",
B: 42,
C: struct {
A bool
}{A: true},
D: []string{"test2", "test3"},
}

testCases := []struct {
testName string
input string
output any
wantOutput any
wantErr bool
}{
{
testName: "empty JSON",
input: `{}`,
output: &to1,
wantOutput: &to0,
},
{
testName: "bad JSON",
input: `{test`,
output: &to2,
wantErr: true,
},
{
testName: "full JSON",
input: `{"A": "test1", "D": ["test2", "test3"], "C": {"A": true}, "B": 42}`,
output: &to3,
wantOutput: &to4,
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.testName, func(t *testing.T) {
t.Parallel()

err := json.DecodeFromString(testCase.input, testCase.output)
if got, want := err != nil, testCase.wantErr; !cmp.Equal(got, want) {
t.Errorf("DecodeFromString(%s) err %t, want %t", testCase.input, got, want)
}
if err == nil {
if diff := cmp.Diff(testCase.output, testCase.wantOutput); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
}
})
}
}
42 changes: 42 additions & 0 deletions internal/json/encode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package json

import (
"bytes"
"encoding/json"
)

// EncodeToBytes JSON encodes (marshals) `from` into a byte slice.
func EncodeToBytes(from any) ([]byte, error) {
to, err := encodeToBuffer(from)

if err != nil {
return nil, err
}

return to.Bytes(), nil
}

// EncodeToString JSON encodes (marshals) `from` into a string.
func EncodeToString(from any) (string, error) {
to, err := encodeToBuffer(from)

if err != nil {
return "", err
}

return to.String(), nil
}

func encodeToBuffer(from any) (*bytes.Buffer, error) {
to := new(bytes.Buffer)
enc := json.NewEncoder(to)

if err := enc.Encode(from); err != nil {
return nil, err
}

return to, nil
}
69 changes: 69 additions & 0 deletions internal/json/encode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package json_test

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-provider-aws/internal/acctest/jsoncmp"
"github.com/hashicorp/terraform-provider-aws/internal/json"
)

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

type from struct {
A string
B int
C struct {
A bool
}
D []string
}
var from0 from
from1 := from{
A: "test1",
B: 42,
C: struct {
A bool
}{A: true},
D: []string{"test2", "test3"},
}

testCases := []struct {
testName string
input any
wantOutput string
wantErr bool
}{
{
testName: "empty JSON",
input: &from0,
wantOutput: `{"A": "", "B": 0, "C": {"A": false}, "D": null}`,
},
{
testName: "empty JSON",
input: &from1,
wantOutput: `{"A": "test1", "D": ["test2", "test3"], "C": {"A": true}, "B": 42}`,
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.testName, func(t *testing.T) {
t.Parallel()

output, err := json.EncodeToString(testCase.input)
if got, want := err != nil, testCase.wantErr; !cmp.Equal(got, want) {
t.Errorf("EncodeToString(%v) err %t, want %t", testCase.input, got, want)
}
if err == nil {
if diff := jsoncmp.Diff(output, testCase.wantOutput); diff != "" {
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
}
}
})
}
}
28 changes: 28 additions & 0 deletions internal/json/equal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package json

import (
"reflect"
)

// EqualBytes returns whether the JSON documents in the given byte slices are equal.
func EqualBytes(b1, b2 []byte) bool {
var v1 any
if err := DecodeFromBytes(b1, &v1); err != nil {
return false
}

var v2 any
if err := DecodeFromBytes(b2, &v2); err != nil {
return false
}

return reflect.DeepEqual(v1, v2)
}

// EqualStrings returns whether the JSON documents in the given strings are equal.
func EqualStrings(s1, s2 string) bool {
return EqualBytes([]byte(s1), []byte(s2))
}
Loading
Loading