Skip to content

Commit

Permalink
Merge pull request #38018 from mattburgess/elastictranscoder-awssdkv2…
Browse files Browse the repository at this point in the history
…-migration

elastictranscoder: Migrate to AWS SDK v2
  • Loading branch information
jar-b authored Jul 19, 2024
2 parents 9eaa754 + 11f8df3 commit fb7f045
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 239 deletions.
6 changes: 6 additions & 0 deletions .changelog/38018.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
resource/aws_elastictranscoder_pipeline: Properly handle NotFound exceptions during deletion
```
```release-note:bug
resource/aws_elastictranscoder_preset: Properly handle NotFound exceptions during deletion
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.26.2
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.3
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3
github.com/aws/aws-sdk-go-v2/service/elastictranscoder v1.25.3
github.com/aws/aws-sdk-go-v2/service/emr v1.42.2
github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.3
github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.3 h1:5B2Dq2zy/hg
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.3/go.mod h1:mgU2kG+D5ybtfGhEuZRW8usYOGrNSgsimRt/hOSI65s=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3 h1:yiBmRRlVwehTN2TF0wbUkM7BluYFOLZU/U2SeQHE+q8=
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3/go.mod h1:L5bVuO4PeXuDuMYZfL3IW69E6mz6PDCYpp6IKDlcLMA=
github.com/aws/aws-sdk-go-v2/service/elastictranscoder v1.25.3 h1:zBRYKbRPym+K+eA4gJ5yP4GNZeBgpScuCmNN2E4RV+8=
github.com/aws/aws-sdk-go-v2/service/elastictranscoder v1.25.3/go.mod h1:gcxottKSKiMNTNYkuor9kcKxyt0Z5ZG1SsdvNH6L5o8=
github.com/aws/aws-sdk-go-v2/service/emr v1.42.2 h1:j3aHjEsxFGCNGOCJjJM6AtPhdvn1pw2i2hGqxLU0qeI=
github.com/aws/aws-sdk-go-v2/service/emr v1.42.2/go.mod h1:rN91rXF7gucnSnArDWbv9xDdZjBEetO4LFoJgGK/Wqw=
github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.3 h1:zxpxkpY1h+kPWquiUSG8u2CJ3AtEJPqqBqiMKxLwPjI=
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.

78 changes: 41 additions & 37 deletions internal/service/elastictranscoder/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"log"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elastictranscoder"
"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/elastictranscoder"
awstypes "github.com/aws/aws-sdk-go-v2/service/elastictranscoder/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"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/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -236,7 +237,7 @@ func ResourcePipeline() *schema.Resource {

func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ElasticTranscoderConn(ctx)
conn := meta.(*conns.AWSClient).ElasticTranscoderClient(ctx)

req := &elastictranscoder.CreatePipelineInput{
AwsKmsKeyArn: aws.String(d.Get("aws_kms_key_arn").(string)),
Expand Down Expand Up @@ -264,13 +265,13 @@ func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta in
return sdkdiag.AppendErrorf(diags, "you must specify only one of output_bucket or content_config.bucket")
}

log.Printf("[DEBUG] Elastic Transcoder Pipeline create opts: %s", req)
resp, err := conn.CreatePipelineWithContext(ctx, req)
log.Printf("[DEBUG] Elastic Transcoder Pipeline create opts: %+v", req)
resp, err := conn.CreatePipeline(ctx, req)
if err != nil {
return sdkdiag.AppendErrorf(diags, "creating Elastic Transcoder Pipeline: %s", err)
}

d.SetId(aws.StringValue(resp.Pipeline.Id))
d.SetId(aws.ToString(resp.Pipeline.Id))

for _, w := range resp.Warnings {
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", *w.Code, *w.Message)
Expand All @@ -279,7 +280,7 @@ func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta in
return append(diags, resourcePipelineRead(ctx, d, meta)...)
}

func expandETNotifications(d *schema.ResourceData) *elastictranscoder.Notifications {
func expandETNotifications(d *schema.ResourceData) *awstypes.Notifications {
list, ok := d.GetOk("notifications")
if !ok {
return nil
Expand All @@ -297,22 +298,22 @@ func expandETNotifications(d *schema.ResourceData) *elastictranscoder.Notificati

rN := l[0].(map[string]interface{})

return &elastictranscoder.Notifications{
return &awstypes.Notifications{
Completed: aws.String(rN["completed"].(string)),
Error: aws.String(rN["error"].(string)),
Progressing: aws.String(rN["progressing"].(string)),
Warning: aws.String(rN["warning"].(string)),
}
}

func flattenETNotifications(n *elastictranscoder.Notifications) []map[string]interface{} {
func flattenETNotifications(n *awstypes.Notifications) []map[string]interface{} {
if n == nil {
return nil
}

allEmpty := func(s ...*string) bool {
for _, s := range s {
if aws.StringValue(s) != "" {
if aws.ToString(s) != "" {
return false
}
}
Expand All @@ -325,16 +326,16 @@ func flattenETNotifications(n *elastictranscoder.Notifications) []map[string]int
}

result := map[string]interface{}{
"completed": aws.StringValue(n.Completed),
"error": aws.StringValue(n.Error),
"progressing": aws.StringValue(n.Progressing),
"warning": aws.StringValue(n.Warning),
"completed": aws.ToString(n.Completed),
"error": aws.ToString(n.Error),
"progressing": aws.ToString(n.Progressing),
"warning": aws.ToString(n.Warning),
}

return []map[string]interface{}{result}
}

func expandETPiplineOutputConfig(d *schema.ResourceData, key string) *elastictranscoder.PipelineOutputConfig {
func expandETPiplineOutputConfig(d *schema.ResourceData, key string) *awstypes.PipelineOutputConfig {
list, ok := d.GetOk(key)
if !ok {
return nil
Expand All @@ -347,7 +348,7 @@ func expandETPiplineOutputConfig(d *schema.ResourceData, key string) *elastictra

cc := l[0].(map[string]interface{})

cfg := &elastictranscoder.PipelineOutputConfig{
cfg := &awstypes.PipelineOutputConfig{
Bucket: aws.String(cc[names.AttrBucket].(string)),
StorageClass: aws.String(cc[names.AttrStorageClass].(string)),
}
Expand All @@ -362,21 +363,21 @@ func expandETPiplineOutputConfig(d *schema.ResourceData, key string) *elastictra
return cfg
}

func flattenETPipelineOutputConfig(cfg *elastictranscoder.PipelineOutputConfig) []map[string]interface{} {
func flattenETPipelineOutputConfig(cfg *awstypes.PipelineOutputConfig) []map[string]interface{} {
if cfg == nil {
return nil
}

result := map[string]interface{}{
names.AttrBucket: aws.StringValue(cfg.Bucket),
names.AttrStorageClass: aws.StringValue(cfg.StorageClass),
names.AttrBucket: aws.ToString(cfg.Bucket),
names.AttrStorageClass: aws.ToString(cfg.StorageClass),
}

return []map[string]interface{}{result}
}

func expandETPermList(permissions *schema.Set) []*elastictranscoder.Permission {
var perms []*elastictranscoder.Permission
func expandETPermList(permissions *schema.Set) []awstypes.Permission {
var perms []awstypes.Permission

for _, p := range permissions.List() {
if p == nil {
Expand All @@ -385,8 +386,8 @@ func expandETPermList(permissions *schema.Set) []*elastictranscoder.Permission {

m := p.(map[string]interface{})

perm := &elastictranscoder.Permission{
Access: flex.ExpandStringList(m["access"].([]interface{})),
perm := awstypes.Permission{
Access: flex.ExpandStringValueList(m["access"].([]interface{})),
Grantee: aws.String(m["grantee"].(string)),
GranteeType: aws.String(m["grantee_type"].(string)),
}
Expand All @@ -396,14 +397,14 @@ func expandETPermList(permissions *schema.Set) []*elastictranscoder.Permission {
return perms
}

func flattenETPermList(perms []*elastictranscoder.Permission) []map[string]interface{} {
func flattenETPermList(perms []awstypes.Permission) []map[string]interface{} {
var set []map[string]interface{}

for _, p := range perms {
result := map[string]interface{}{
"access": flex.FlattenStringList(p.Access),
"grantee": aws.StringValue(p.Grantee),
"grantee_type": aws.StringValue(p.GranteeType),
"access": flex.FlattenStringValueList(p.Access),
"grantee": aws.ToString(p.Grantee),
"grantee_type": aws.ToString(p.GranteeType),
}

set = append(set, result)
Expand All @@ -413,7 +414,7 @@ func flattenETPermList(perms []*elastictranscoder.Permission) []map[string]inter

func resourcePipelineUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ElasticTranscoderConn(ctx)
conn := meta.(*conns.AWSClient).ElasticTranscoderClient(ctx)

req := &elastictranscoder.UpdatePipelineInput{
Id: aws.String(d.Id()),
Expand Down Expand Up @@ -448,29 +449,29 @@ func resourcePipelineUpdate(ctx context.Context, d *schema.ResourceData, meta in
}

log.Printf("[DEBUG] Updating Elastic Transcoder Pipeline: %#v", req)
output, err := conn.UpdatePipelineWithContext(ctx, req)
output, err := conn.UpdatePipeline(ctx, req)
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Elastic Transcoder pipeline: %s", err)
}

for _, w := range output.Warnings {
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", aws.StringValue(w.Code),
aws.StringValue(w.Message))
log.Printf("[WARN] Elastic Transcoder Pipeline %v: %v", aws.ToString(w.Code),
aws.ToString(w.Message))
}

return append(diags, resourcePipelineRead(ctx, d, meta)...)
}

func resourcePipelineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ElasticTranscoderConn(ctx)
conn := meta.(*conns.AWSClient).ElasticTranscoderClient(ctx)

resp, err := conn.ReadPipelineWithContext(ctx, &elastictranscoder.ReadPipelineInput{
resp, err := conn.ReadPipeline(ctx, &elastictranscoder.ReadPipelineInput{
Id: aws.String(d.Id()),
})

if err != nil {
if tfawserr.ErrCodeEquals(err, elastictranscoder.ErrCodeResourceNotFoundException) {
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
log.Printf("[WARN] Elastic Transcoder Pipeline (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
Expand Down Expand Up @@ -529,13 +530,16 @@ func resourcePipelineRead(ctx context.Context, d *schema.ResourceData, meta inte

func resourcePipelineDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ElasticTranscoderConn(ctx)
conn := meta.(*conns.AWSClient).ElasticTranscoderClient(ctx)

log.Printf("[DEBUG] Elastic Transcoder Delete Pipeline: %s", d.Id())
_, err := conn.DeletePipelineWithContext(ctx, &elastictranscoder.DeletePipelineInput{
_, err := conn.DeletePipeline(ctx, &elastictranscoder.DeletePipelineInput{
Id: aws.String(d.Id()),
})
if err != nil {
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return diags
}
return sdkdiag.AppendErrorf(diags, "deleting Elastic Transcoder Pipeline: %s", err)
}
return diags
Expand Down
Loading

0 comments on commit fb7f045

Please sign in to comment.