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

Migrate Route 53 Recovery Readiness to AWS SDK v2 #38801

Merged
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 @@ -294,6 +294,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.16 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 // indirect
github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/boombuler/barcode v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3 h1:VGLIgiClxmwxBpGzH
github.com/aws/aws-sdk-go-v2/service/route53domains v1.25.3/go.mod h1:Kgq5O7ZaDk0mTZmX6YCL+ZtZ1YcJHtGsVubp0OT77MA=
github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3 h1:N4f5sliNiWcp3abC+8YpcaVjXuaNJIlz/dBd+saimm0=
github.com/aws/aws-sdk-go-v2/service/route53profiles v1.2.3/go.mod h1:r2B4BvTn3zSMK+BFHGl0q63B/nJMOk9/NukLZzqO8sY=
github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3 h1:M6D+IRT6YdeL+qLIdy4u4zEoMOqq3lJnNUGt0cxEI04=
github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness v1.19.3/go.mod h1:y4m7VlTWV77mBzMdAZWjudnobe0E77tKy5Z9+IQIku0=
github.com/aws/aws-sdk-go-v2/service/rum v1.19.3 h1:DR+GYJRPL7eEZknnGdwm+lH686LmUBB/X2YVQDHLNY4=
github.com/aws/aws-sdk-go-v2/service/rum v1.19.3/go.mod h1:5jFxbuc05P/+BbJvVbBspMbzDR2IFU0LegQG3iUvj8g=
github.com/aws/aws-sdk-go-v2/service/s3 v1.58.3 h1:hT8ZAZRIfqBqHbzKTII+CIiY8G2oC9OpLedkZ51DWl8=
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.

81 changes: 49 additions & 32 deletions internal/service/route53recoveryreadiness/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53recoveryreadiness"
"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/route53recoveryreadiness"
awstypes "github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"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"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand All @@ -26,7 +27,7 @@ import (

// @SDKResource("aws_route53recoveryreadiness_cell", name="Cell")
// @Tags(identifierAttribute="arn")
func ResourceCell() *schema.Resource {
func resourceCell() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceCellCreate,
ReadWithoutTimeout: resourceCellRead,
Expand Down Expand Up @@ -75,23 +76,23 @@ func ResourceCell() *schema.Resource {

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

name := d.Get("cell_name").(string)
input := &route53recoveryreadiness.CreateCellInput{
CellName: aws.String(name),
Cells: flex.ExpandStringList(d.Get("cells").([]interface{})),
Cells: flex.ExpandStringValueList(d.Get("cells").([]interface{})),
}

output, err := conn.CreateCellWithContext(ctx, input)
output, err := conn.CreateCell(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating Route53 Recovery Readiness Cell (%s): %s", name, err)
}

d.SetId(aws.StringValue(output.CellName))
d.SetId(aws.ToString(output.CellName))

if err := createTags(ctx, conn, aws.StringValue(output.CellArn), getTagsIn(ctx)); err != nil {
if err := createTags(ctx, conn, aws.ToString(output.CellArn), getTagsIn(ctx)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting Route53 Recovery Readiness Cell (%s) tags: %s", d.Id(), err)
}

Expand All @@ -100,15 +101,11 @@ func resourceCellCreate(ctx context.Context, d *schema.ResourceData, meta interf

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

input := &route53recoveryreadiness.GetCellInput{
CellName: aws.String(d.Id()),
}
output, err := findCellByName(ctx, conn, d.Id())

resp, err := conn.GetCellWithContext(ctx, input)

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, route53recoveryreadiness.ErrCodeResourceNotFoundException) {
if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Route53 Recovery Readiness Cell (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
Expand All @@ -118,25 +115,25 @@ func resourceCellRead(ctx context.Context, d *schema.ResourceData, meta interfac
return sdkdiag.AppendErrorf(diags, "reading Route53 Recovery Readiness Cell (%s): %s", d.Id(), err)
}

d.Set(names.AttrARN, resp.CellArn)
d.Set("cell_name", resp.CellName)
d.Set("cells", resp.Cells)
d.Set("parent_readiness_scopes", resp.ParentReadinessScopes)
d.Set(names.AttrARN, output.CellArn)
d.Set("cell_name", output.CellName)
d.Set("cells", output.Cells)
d.Set("parent_readiness_scopes", output.ParentReadinessScopes)

return diags
}

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

if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
input := &route53recoveryreadiness.UpdateCellInput{
CellName: aws.String(d.Id()),
Cells: flex.ExpandStringList(d.Get("cells").([]interface{})),
Cells: flex.ExpandStringValueList(d.Get("cells").([]interface{})),
}

_, err := conn.UpdateCellWithContext(ctx, input)
_, err := conn.UpdateCell(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating Route53 Recovery Readiness Cell (%s): %s", d.Id(), err)
Expand All @@ -148,40 +145,60 @@ func resourceCellUpdate(ctx context.Context, d *schema.ResourceData, meta interf

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

log.Printf("[DEBUG] Deleting Route53 Recovery Readiness Cell: %s", d.Id())
_, err := conn.DeleteCellWithContext(ctx, &route53recoveryreadiness.DeleteCellInput{
_, err := conn.DeleteCell(ctx, &route53recoveryreadiness.DeleteCellInput{
CellName: aws.String(d.Id()),
})

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

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Route53 Recovery Readiness Cell (%s): %s", d.Id(), err)
}

gcinput := &route53recoveryreadiness.GetCellInput{
CellName: aws.String(d.Id()),
}
err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError {
_, err := conn.GetCellWithContext(ctx, gcinput)
_, err := findCellByName(ctx, conn, d.Id())
if err != nil {
if tfawserr.ErrCodeEquals(err, route53recoveryreadiness.ErrCodeResourceNotFoundException) {
if tfresource.NotFound(err) {
return nil
}
return retry.NonRetryableError(err)
}
return retry.RetryableError(fmt.Errorf("Route 53 Recovery Readiness Cell (%s) still exists", d.Id()))
})
if tfresource.TimedOut(err) {
_, err = conn.GetCellWithContext(ctx, gcinput)
_, err = findCellByName(ctx, conn, d.Id())
}
if err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Route 53 Recovery Readiness Cell (%s) deletion: %s", d.Id(), err)
}

return diags
}

func findCellByName(ctx context.Context, conn *route53recoveryreadiness.Client, name string) (*route53recoveryreadiness.GetCellOutput, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And new finders! 🥇 🎉

input := &route53recoveryreadiness.GetCellInput{
CellName: aws.String(name),
}

output, err := conn.GetCell(ctx, input)
if errs.IsA[*awstypes.ResourceNotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}
if err != nil {
return nil, err
}

if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output, nil
}
31 changes: 15 additions & 16 deletions internal/service/route53recoveryreadiness/cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"testing"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53recoveryreadiness"
"github.com/aws/aws-sdk-go-v2/service/route53recoveryreadiness"
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"
tfroute53recoveryreadiness "github.com/hashicorp/terraform-provider-aws/internal/service/route53recoveryreadiness"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -202,21 +202,24 @@ func TestAccRoute53RecoveryReadinessCell_timeout(t *testing.T) {

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

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53recoveryreadiness_cell" {
continue
}

input := &route53recoveryreadiness.GetCellInput{
CellName: aws.String(rs.Primary.ID),
_, err := tfroute53recoveryreadiness.FindCellByName(ctx, conn, rs.Primary.ID)

if tfresource.NotFound(err) {
continue
}

_, err := conn.GetCellWithContext(ctx, input)
if err == nil {
return fmt.Errorf("Route53RecoveryReadiness Channel (%s) not deleted", rs.Primary.ID)
if err != nil {
return err
}

return fmt.Errorf("Route53 Recovery Readiness Cell %s still exists", rs.Primary.ID)
}

return nil
Expand All @@ -231,24 +234,20 @@ func testAccCheckCellExists(ctx context.Context, name string) resource.TestCheck
return fmt.Errorf("Not found: %s", name)
}

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

input := &route53recoveryreadiness.GetCellInput{
CellName: aws.String(rs.Primary.ID),
}
conn := acctest.Provider.Meta().(*conns.AWSClient).Route53RecoveryReadinessClient(ctx)

_, err := conn.GetCellWithContext(ctx, input)
_, err := tfroute53recoveryreadiness.FindCellByName(ctx, conn, rs.Primary.ID)

return err
}
}

func testAccPreCheck(ctx context.Context, t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).Route53RecoveryReadinessConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).Route53RecoveryReadinessClient(ctx)

input := &route53recoveryreadiness.ListCellsInput{}

_, err := conn.ListCellsWithContext(ctx, input)
_, err := conn.ListCells(ctx, input)

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
Expand Down
17 changes: 17 additions & 0 deletions internal/service/route53recoveryreadiness/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package route53recoveryreadiness

// Exports for use in tests only.
var (
ResourceCell = resourceCell
ResourceReadinessCheck = resourceReadinessCheck
ResourceRecoveryGroup = resourceRecoveryGroup
ResourceResourceSet = resourceResourceSet

FindCellByName = findCellByName
FindReadinessCheckByName = findReadinessCheckByName
FindRecoveryGroupByName = findRecoveryGroupByName
FindResourceSetByName = findResourceSetByName
)
2 changes: 1 addition & 1 deletion internal/service/route53recoveryreadiness/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 -ListTags -ListTagsOp=ListTagsForResources -ServiceTagsMap -UpdateTags -CreateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTagsForResources -UpdateTags -CreateTags -ServiceTagsMap -KVTValues -SkipTypesImp
//go:generate go run ../../generate/servicepackage/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
Loading
Loading