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

ivs: Migrate to AWS SDK v2 #38422

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/iot v1.55.3
github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3
github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3
github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3
github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.4
github.com/aws/aws-sdk-go-v2/service/kafka v1.35.3
github.com/aws/aws-sdk-go-v2/service/kafkaconnect v1.19.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3 h1:SEt8SRvlGvnOkqDV5PJ
github.com/aws/aws-sdk-go-v2/service/iotanalytics v1.24.3/go.mod h1:XDi19IK0UluaSVnm1mu2AakZKHtWjg6gksitvH7+LQw=
github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3 h1:9Lao6kmD9P+yywuIn9I8hrraJ2jHIztU/GJspIxn6lA=
github.com/aws/aws-sdk-go-v2/service/iotevents v1.25.3/go.mod h1:V2BDVrnP+Tn+MM1xxFI7Qcb+YPhiGgY5PUoKzrKHaCQ=
github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3 h1:gBK4NPueWRWK/zma5K3Hc3/hZhoYuKw00Ed2GzOVhg8=
github.com/aws/aws-sdk-go-v2/service/ivs v1.37.3/go.mod h1:gDKrqL8b+YVQ7C/Y152MZ0AxXP6FaksuQ3dbzGCpD7Y=
github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.4 h1:isEOoNaq94Wh+x1tt8ScUeV+oQUH2I+5zjCmqCkUa/g=
github.com/aws/aws-sdk-go-v2/service/ivschat v1.14.4/go.mod h1:rtw6VOH+4X/TWoOKQlOC+oq/WBDJD4BqaPi930II6Mk=
github.com/aws/aws-sdk-go-v2/service/kafka v1.35.3 h1:MUx27PrqicGxgsiDWo7xv/Zsl4b0X8kHCRvMpX7XrQs=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

54 changes: 28 additions & 26 deletions internal/service/ivs/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"time"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ivs"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ivs"
awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -58,10 +60,10 @@ func ResourceChannel() *schema.Resource {
Computed: true,
},
"latency_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(ivs.ChannelLatencyMode_Values(), false),
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: enum.Validate[awstypes.ChannelLatencyMode](),
},
names.AttrName: {
Type: schema.TypeString,
Expand All @@ -82,10 +84,10 @@ func ResourceChannel() *schema.Resource {
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
names.AttrType: {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(ivs.ChannelType_Values(), false),
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: enum.Validate[awstypes.ChannelType](),
},
},

Expand All @@ -100,18 +102,18 @@ const (
func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).IVSConn(ctx)
conn := meta.(*conns.AWSClient).IVSClient(ctx)

in := &ivs.CreateChannelInput{
Tags: getTagsIn(ctx),
}

if v, ok := d.GetOk("authorized"); ok {
in.Authorized = aws.Bool(v.(bool))
in.Authorized = v.(bool)
}

if v, ok := d.GetOk("latency_mode"); ok {
in.LatencyMode = aws.String(v.(string))
in.LatencyMode = awstypes.ChannelLatencyMode(v.(string))
}

if v, ok := d.GetOk(names.AttrName); ok {
Expand All @@ -123,10 +125,10 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int
}

if v, ok := d.GetOk(names.AttrType); ok {
in.Type = aws.String(v.(string))
in.Type = awstypes.ChannelType(v.(string))
}

out, err := conn.CreateChannelWithContext(ctx, in)
out, err := conn.CreateChannel(ctx, in)
if err != nil {
return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameChannel, d.Get(names.AttrName).(string), err)
}
Expand All @@ -135,7 +137,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int
return create.AppendDiagError(diags, names.IVS, create.ErrActionCreating, ResNameChannel, d.Get(names.AttrName).(string), errors.New("empty output"))
}

d.SetId(aws.StringValue(out.Channel.Arn))
d.SetId(aws.ToString(out.Channel.Arn))

if _, err := waitChannelCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return create.AppendDiagError(diags, names.IVS, create.ErrActionWaitingForCreation, ResNameChannel, d.Id(), err)
Expand All @@ -147,7 +149,7 @@ func resourceChannelCreate(ctx context.Context, d *schema.ResourceData, meta int
func resourceChannelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).IVSConn(ctx)
conn := meta.(*conns.AWSClient).IVSClient(ctx)

out, err := FindChannelByID(ctx, conn, d.Id())

Expand Down Expand Up @@ -176,7 +178,7 @@ func resourceChannelRead(ctx context.Context, d *schema.ResourceData, meta inter
func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).IVSConn(ctx)
conn := meta.(*conns.AWSClient).IVSClient(ctx)

update := false

Expand All @@ -186,12 +188,12 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int
}

if d.HasChanges("authorized") {
in.Authorized = aws.Bool(d.Get("authorized").(bool))
in.Authorized = d.Get("authorized").(bool)
update = true
}

if d.HasChanges("latency_mode") {
in.LatencyMode = aws.String(d.Get("latency_mode").(string))
in.LatencyMode = awstypes.ChannelLatencyMode(d.Get("latency_mode").(string))
update = true
}

Expand All @@ -206,7 +208,7 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int
}

if d.HasChanges(names.AttrType) {
in.Type = aws.String(d.Get(names.AttrType).(string))
in.Type = awstypes.ChannelType(d.Get(names.AttrType).(string))
update = true
}

Expand All @@ -216,7 +218,7 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int

log.Printf("[DEBUG] Updating IVS Channel (%s): %#v", d.Id(), in)

out, err := conn.UpdateChannelWithContext(ctx, in)
out, err := conn.UpdateChannel(ctx, in)
if err != nil {
return create.AppendDiagError(diags, names.IVS, create.ErrActionUpdating, ResNameChannel, d.Id(), err)
}
Expand All @@ -231,16 +233,16 @@ func resourceChannelUpdate(ctx context.Context, d *schema.ResourceData, meta int
func resourceChannelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).IVSConn(ctx)
conn := meta.(*conns.AWSClient).IVSClient(ctx)

log.Printf("[INFO] Deleting IVS Channel %s", d.Id())

_, err := conn.DeleteChannelWithContext(ctx, &ivs.DeleteChannelInput{
_, err := conn.DeleteChannel(ctx, &ivs.DeleteChannelInput{
Arn: aws.String(d.Id()),
})

if err != nil {
if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) {
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
}

Expand Down
39 changes: 20 additions & 19 deletions internal/service/ivs/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ivs"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ivs"
awstypes "github.com/aws/aws-sdk-go-v2/service/ivs/types"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tfivs "github.com/hashicorp/terraform-provider-aws/internal/service/ivs"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccIVSChannel_basic(t *testing.T) {
ctx := acctest.Context(t)
var channel ivs.Channel
var channel awstypes.Channel

resourceName := "aws_ivs_channel.test"

Expand Down Expand Up @@ -61,7 +62,7 @@ func TestAccIVSChannel_basic(t *testing.T) {

func TestAccIVSChannel_tags(t *testing.T) {
ctx := acctest.Context(t)
var channel ivs.Channel
var channel awstypes.Channel

resourceName := "aws_ivs_channel.test"

Expand Down Expand Up @@ -111,7 +112,7 @@ func TestAccIVSChannel_tags(t *testing.T) {

func TestAccIVSChannel_update(t *testing.T) {
ctx := acctest.Context(t)
var v1, v2 ivs.Channel
var v1, v2 awstypes.Channel

resourceName := "aws_ivs_channel.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -156,14 +157,14 @@ func TestAccIVSChannel_update(t *testing.T) {

func TestAccIVSChannel_disappears(t *testing.T) {
ctx := acctest.Context(t)
var channel ivs.Channel
var channel awstypes.Channel

resourceName := "aws_ivs_channel.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, ivs.EndpointsID)
acctest.PreCheckPartitionHasService(t, names.IVSEndpointID)
testAccChannelPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID),
Expand All @@ -184,15 +185,15 @@ func TestAccIVSChannel_disappears(t *testing.T) {

func TestAccIVSChannel_recordingConfiguration(t *testing.T) {
ctx := acctest.Context(t)
var channel ivs.Channel
var channel awstypes.Channel
bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ivs_channel.test"
recordingConfigurationResourceName := "aws_ivs_recording_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, ivs.EndpointsID)
acctest.PreCheckPartitionHasService(t, names.IVSEndpointID)
testAccChannelPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.IVSServiceID),
Expand All @@ -217,7 +218,7 @@ func TestAccIVSChannel_recordingConfiguration(t *testing.T) {

func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx)

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_ivs_channel" {
Expand All @@ -227,9 +228,9 @@ func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc {
input := &ivs.GetChannelInput{
Arn: aws.String(rs.Primary.ID),
}
_, err := conn.GetChannelWithContext(ctx, input)
_, err := conn.GetChannel(ctx, input)
if err != nil {
if tfawserr.ErrCodeEquals(err, ivs.ErrCodeResourceNotFoundException) {
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return nil
}

Expand All @@ -243,7 +244,7 @@ func testAccCheckChannelDestroy(ctx context.Context) resource.TestCheckFunc {
}
}

func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Channel) resource.TestCheckFunc {
func testAccCheckChannelExists(ctx context.Context, name string, channel *awstypes.Channel) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]

Expand All @@ -255,7 +256,7 @@ func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Ch
return create.Error(names.IVS, create.ErrActionCheckingExistence, tfivs.ResNameChannel, name, errors.New("not set"))
}

conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx)

output, err := tfivs.FindChannelByID(ctx, conn, rs.Primary.ID)

Expand All @@ -270,10 +271,10 @@ func testAccCheckChannelExists(ctx context.Context, name string, channel *ivs.Ch
}

func testAccChannelPreCheck(ctx context.Context, t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).IVSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).IVSClient(ctx)

input := &ivs.ListChannelsInput{}
_, err := conn.ListChannelsWithContext(ctx, input)
_, err := conn.ListChannels(ctx, input)

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
Expand All @@ -284,9 +285,9 @@ func testAccChannelPreCheck(ctx context.Context, t *testing.T) {
}
}

func testAccCheckChannelNotRecreated(before, after *ivs.Channel) resource.TestCheckFunc {
func testAccCheckChannelNotRecreated(before, after *awstypes.Channel) resource.TestCheckFunc {
return func(s *terraform.State) error {
if before, after := aws.StringValue(before.Arn), aws.StringValue(after.Arn); before != after {
if before, after := aws.ToString(before.Arn), aws.ToString(after.Arn); before != after {
return create.Error(names.IVS, create.ErrActionCheckingNotRecreated, tfivs.ResNameChannel, before, errors.New("recreated"))
}

Expand Down
Loading
Loading