Skip to content

Commit

Permalink
Merge pull request #37192 from mattburgess/datapipeline-awssdkv2-migr…
Browse files Browse the repository at this point in the history
…ation

datapipeline: Migrate to AWS SDK v2
  • Loading branch information
jar-b authored Jul 16, 2024
2 parents a870353 + bfb16df commit b853218
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 258 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.40.3
github.com/aws/aws-sdk-go-v2/service/databrew v1.31.3
github.com/aws/aws-sdk-go-v2/service/dataexchange v1.30.3
github.com/aws/aws-sdk-go-v2/service/datapipeline v1.23.3
github.com/aws/aws-sdk-go-v2/service/datasync v1.40.3
github.com/aws/aws-sdk-go-v2/service/datazone v1.13.2
github.com/aws/aws-sdk-go-v2/service/dax v1.21.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ github.com/aws/aws-sdk-go-v2/service/databrew v1.31.3 h1:tFFs24+oIWlHLbTyluhnQIH
github.com/aws/aws-sdk-go-v2/service/databrew v1.31.3/go.mod h1:WP7xXB608MyVv3yFzduKlLeYmU0AxMo7zeF9Cuwbvwc=
github.com/aws/aws-sdk-go-v2/service/dataexchange v1.30.3 h1:GndlSdjdgcW1r+mGL635+6ZlwXgdu/663aHHyBJ6Jtk=
github.com/aws/aws-sdk-go-v2/service/dataexchange v1.30.3/go.mod h1:xUxKkSfH4sCQixoxh3pYc7C4N+OH2POgS0dhkOzR+u8=
github.com/aws/aws-sdk-go-v2/service/datapipeline v1.23.3 h1:kA26fZh30b6kOZZIkxr/1M4f4TnIsXBw3RcHEFuFxcs=
github.com/aws/aws-sdk-go-v2/service/datapipeline v1.23.3/go.mod h1:9Z4AiKwAlu2eXOPFEDfkLV/wTpI9o2FX09M4l6E4VE4=
github.com/aws/aws-sdk-go-v2/service/datasync v1.40.3 h1:ZrKMl8jsL5YHurOLf0YVLb7JBYxGtqQQAknJ5g4MTz4=
github.com/aws/aws-sdk-go-v2/service/datasync v1.40.3/go.mod h1:+ObRlRcKO/p38yJSkpVZKlCU3t9PqXMORXC+xTkb9NU=
github.com/aws/aws-sdk-go-v2/service/datazone v1.13.2 h1:9l6JiWZz/2Sp3ne9E/AXECwnzi7NASQUJnQ7xts/8oA=
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.

2 changes: 1 addition & 1 deletion internal/service/datapipeline/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:generate go run ../../generate/tags/main.go -ListTagsInIDElem=PipelineId -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=PipelineId -UntagOp=RemoveTags -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTagsInIDElem=PipelineId -ServiceTagsSlice -TagOp=AddTags -TagInIDElem=PipelineId -UntagOp=RemoveTags -UpdateTags
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
47 changes: 22 additions & 25 deletions internal/service/datapipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datapipeline"
"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/datapipeline"
awstypes "github.com/aws/aws-sdk-go-v2/service/datapipeline/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/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"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"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -58,7 +59,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).DataPipelineConn(ctx)
conn := meta.(*conns.AWSClient).DataPipelineClient(ctx)

uniqueID := id.UniqueId()
input := datapipeline.CreatePipelineInput{
Expand All @@ -71,23 +72,23 @@ func resourcePipelineCreate(ctx context.Context, d *schema.ResourceData, meta in
input.Description = aws.String(v.(string))
}

resp, err := conn.CreatePipelineWithContext(ctx, &input)
resp, err := conn.CreatePipeline(ctx, &input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating datapipeline: %s", err)
}

d.SetId(aws.StringValue(resp.PipelineId))
d.SetId(aws.ToString(resp.PipelineId))

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).DataPipelineConn(ctx)
conn := meta.(*conns.AWSClient).DataPipelineClient(ctx)

v, err := PipelineRetrieve(ctx, d.Id(), conn)
if tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineNotFoundException) || tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineDeletedException) || v == nil {
if errs.IsA[*awstypes.PipelineNotFoundException](err) || errs.IsA[*awstypes.PipelineDeletedException](err) || v == nil {
log.Printf("[WARN] DataPipeline (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
Expand All @@ -114,14 +115,14 @@ func resourcePipelineUpdate(ctx context.Context, d *schema.ResourceData, meta in

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

opts := datapipeline.DeletePipelineInput{
PipelineId: aws.String(d.Id()),
}

_, err := conn.DeletePipelineWithContext(ctx, &opts)
if tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineNotFoundException) || tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineDeletedException) {
_, err := conn.DeletePipeline(ctx, &opts)
if errs.IsA[*awstypes.PipelineNotFoundException](err) || errs.IsA[*awstypes.PipelineDeletedException](err) {
return diags
}
if err != nil {
Expand All @@ -134,39 +135,35 @@ func resourcePipelineDelete(ctx context.Context, d *schema.ResourceData, meta in
return diags
}

func PipelineRetrieve(ctx context.Context, id string, conn *datapipeline.DataPipeline) (*datapipeline.PipelineDescription, error) {
func PipelineRetrieve(ctx context.Context, id string, conn *datapipeline.Client) (*awstypes.PipelineDescription, error) {
opts := datapipeline.DescribePipelinesInput{
PipelineIds: []*string{aws.String(id)},
PipelineIds: []string{id},
}

resp, err := conn.DescribePipelinesWithContext(ctx, &opts)
resp, err := conn.DescribePipelines(ctx, &opts)
if err != nil {
return nil, err
}

var pipeline *datapipeline.PipelineDescription
var pipeline awstypes.PipelineDescription

for _, p := range resp.PipelineDescriptionList {
if p == nil {
continue
}

if aws.StringValue(p.PipelineId) == id {
if aws.ToString(p.PipelineId) == id {
pipeline = p
break
}
}

return pipeline, nil
return &pipeline, nil
}

func WaitForDeletion(ctx context.Context, conn *datapipeline.DataPipeline, pipelineID string) error {
func WaitForDeletion(ctx context.Context, conn *datapipeline.Client, pipelineID string) error {
params := &datapipeline.DescribePipelinesInput{
PipelineIds: []*string{aws.String(pipelineID)},
PipelineIds: []string{pipelineID},
}
return retry.RetryContext(ctx, 10*time.Minute, func() *retry.RetryError {
_, err := conn.DescribePipelinesWithContext(ctx, params)
if tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineNotFoundException) || tfawserr.ErrCodeEquals(err, datapipeline.ErrCodePipelineDeletedException) {
_, err := conn.DescribePipelines(ctx, params)
if errs.IsA[*awstypes.PipelineNotFoundException](err) || errs.IsA[*awstypes.PipelineDeletedException](err) {
return nil
}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/datapipeline/pipeline_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func DataSourcePipeline() *schema.Resource {
func dataSourcePipelineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

conn := meta.(*conns.AWSClient).DataPipelineConn(ctx)
conn := meta.(*conns.AWSClient).DataPipelineClient(ctx)
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

Expand Down
Loading

0 comments on commit b853218

Please sign in to comment.