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

DMS: Fix acceptance test failures #33158

Merged
merged 32 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
37f3619
r/aws_dms_replication_instance: Tidy up resource Read.
ewbankkit Aug 22, 2023
4afefab
r/aws_dms_replication_instance: Tidy up resource Delete.
ewbankkit Aug 22, 2023
351cb75
r/aws_dms_replication_instance: Use 'FindReplicationInstanceByID' in …
ewbankkit Aug 22, 2023
b08ac09
r/aws_replication_subnet_group: Add sweeper.
ewbankkit Aug 22, 2023
b5c6c6e
r/aws_dms_replication_instance: Add 'waitReplicationInstanceCreated'.
ewbankkit Aug 22, 2023
ff74f0d
r/aws_dms_replication_instance: Add 'waitReplicationInstanceUpdated'.
ewbankkit Aug 22, 2023
8134908
r/aws_dms_replication_subnet_group: Tidy up resource Create.
ewbankkit Aug 22, 2023
dfd28d7
r/aws_dms_replication_subnet_group: Tidy up resource Read.
ewbankkit Aug 22, 2023
797b819
r/aws_dms_replication_subnet_group: Tidy up resource Update.
ewbankkit Aug 22, 2023
4e50e21
r/aws_dms_replication_subnet_group: Tidy up acceptance tests.
ewbankkit Aug 22, 2023
cf2751f
Add 'TestAccDMSReplicationSubnetGroup_disappears'.
ewbankkit Aug 22, 2023
f933e54
Add 'TestAccDMSReplicationSubnetGroup_tags'.
ewbankkit Aug 22, 2023
987bf1c
Acceptance test output:
ewbankkit Aug 22, 2023
72206fd
d/aws_replication_subnet_group: Tidy up.
ewbankkit Aug 22, 2023
4b6b79f
Acceptance test output:
ewbankkit Aug 22, 2023
550e132
r/aws_dms_replication_instance: Add 'TestAccDMSReplicationInstance_di…
ewbankkit Aug 22, 2023
b8ba86e
r/aws_dms_replication_instance: Tidy up acceptance tests.
ewbankkit Aug 22, 2023
c2ece9e
Fix 'TestAccDMSReplicationInstance_publiclyAccessible'.
ewbankkit Aug 22, 2023
83f37b9
r/aws_dms_replication_instance: Add 'network_type' argument.
ewbankkit Aug 23, 2023
6346b07
d/aws_dms_replication_instance: Add 'network_type' attribute.
ewbankkit Aug 23, 2023
ba8d221
r/aws_dms_replication_instance: 'network_type' is Computed.
ewbankkit Aug 23, 2023
8b63a66
Fix typo.
ewbankkit Aug 23, 2023
a1f28bc
r/aws_dms_endpoint: Move functions around.
ewbankkit Aug 23, 2023
5b0c2e1
Restore 'TestAccDMSReplicationInstance_engineVersion'.
ewbankkit Aug 23, 2023
64f4ab1
Tidy up 'FindEndpointByID'.
ewbankkit Aug 23, 2023
a74bf63
d/aws_dms_endpoint: More attributes are Computed.
ewbankkit Aug 23, 2023
77cf7d1
d/aws_dms_endpoint: Tidy up.
ewbankkit Aug 23, 2023
d8cb2be
Merge branch 'main' into t-dms-failures
ewbankkit Aug 23, 2023
d544c45
Merge branch 'main' into t-dms-failures
ewbankkit Aug 23, 2023
570ea43
Correct CHANGELOG entry file name.
ewbankkit Aug 23, 2023
40d7ce3
Fix terrafmt error.
ewbankkit Aug 23, 2023
69d3615
Additional CHANGELOG entry.
ewbankkit Aug 23, 2023
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
11 changes: 11 additions & 0 deletions .changelog/33158.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_dms_replication_instance: Add `network_type` argument
```

```release-note:enhancement
data-source/aws_dms_replication_instance: Add `network_type` attribute
```

```release-note:enhancement
data-source/aws_dms_endpoint: Fix crash when specified endpoint not found
```
18 changes: 18 additions & 0 deletions internal/service/dms/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ package dms
const (
endpointStatusDeleting = "deleting"

replicationInstanceStatusAvailable = "available"
replicationInstanceStatusCreating = "creating"
replicationInstanceStatusDeleting = "deleting"
replicationInstanceStatusModifying = "modifying"
replicationInstanceStatusUpgrading = "upgrading"

replicationTaskStatusCreating = "creating"
replicationTaskStatusDeleting = "deleting"
replicationTaskStatusFailed = "failed"
Expand Down Expand Up @@ -125,3 +131,15 @@ func encryptionMode_Values() []string {
encryptionModeSseS3,
}
}

const (
networkTypeDual = "DUAL"
networkTypeIPv4 = "IPV4"
)

func networkType_Values() []string {
return []string{
networkTypeDual,
networkTypeIPv4,
}
}
90 changes: 86 additions & 4 deletions internal/service/dms/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"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"
Expand Down Expand Up @@ -959,10 +960,8 @@ func resourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "reading DMS Endpoint (%s): %s", d.Id(), err)
}

err = resourceEndpointSetState(d, endpoint)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading DMS Endpoint (%s): %s", d.Id(), err)
if err := resourceEndpointSetState(d, endpoint); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

return diags
Expand Down Expand Up @@ -2302,3 +2301,86 @@ func flattenTopLevelConnectionInfo(d *schema.ResourceData, endpoint *dms.Endpoin
d.Set("port", endpoint.Port)
d.Set("database_name", endpoint.DatabaseName)
}

func FindEndpointByID(ctx context.Context, conn *dms.DatabaseMigrationService, id string) (*dms.Endpoint, error) {
input := &dms.DescribeEndpointsInput{
Filters: []*dms.Filter{
{
Name: aws.String("endpoint-id"),
Values: aws.StringSlice([]string{id}),
},
},
}

return findEndpoint(ctx, conn, input)
}

func findEndpoint(ctx context.Context, conn *dms.DatabaseMigrationService, input *dms.DescribeEndpointsInput) (*dms.Endpoint, error) {
output, err := findEndpoints(ctx, conn, input)

if err != nil {
return nil, err
}

return tfresource.AssertSinglePtrResult(output)
}

func findEndpoints(ctx context.Context, conn *dms.DatabaseMigrationService, input *dms.DescribeEndpointsInput) ([]*dms.Endpoint, error) {
var output []*dms.Endpoint

err := conn.DescribeEndpointsPagesWithContext(ctx, input, func(page *dms.DescribeEndpointsOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.Endpoints {
if v != nil {
output = append(output, v)
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, dms.ErrCodeResourceNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

return output, nil
}

func statusEndpoint(ctx context.Context, conn *dms.DatabaseMigrationService, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindEndpointByID(ctx, conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
}

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

return output, aws.StringValue(output.Status), nil
}
}

func waitEndpointDeleted(ctx context.Context, conn *dms.DatabaseMigrationService, id string, timeout time.Duration) error {
stateConf := &retry.StateChangeConf{
Pending: []string{endpointStatusDeleting},
Target: []string{},
Refresh: statusEndpoint(ctx, conn, id),
Timeout: timeout,
}

_, err := stateConf.WaitForStateContext(ctx)

return err
}
43 changes: 19 additions & 24 deletions internal/service/dms/endpoint_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_dms_endpoint")
Expand All @@ -31,12 +30,12 @@ func DataSourceEndpoint() *schema.Resource {
},
"elasticsearch_settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"endpoint_uri": {
Type: schema.TypeString,
Required: true,
Computed: true,
},
"error_retry_duration": {
Type: schema.TypeInt,
Expand All @@ -48,7 +47,7 @@ func DataSourceEndpoint() *schema.Resource {
},
"service_access_role_arn": {
Type: schema.TypeString,
Required: true,
Computed: true,
},
},
},
Expand All @@ -71,16 +70,16 @@ func DataSourceEndpoint() *schema.Resource {
},
"extra_connection_attributes": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"kafka_settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"broker": {
Type: schema.TypeString,
Required: true,
Computed: true,
},
"include_control_details": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -203,7 +202,7 @@ func DataSourceEndpoint() *schema.Resource {
},
"mongodb_settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auth_mechanism": {
Expand Down Expand Up @@ -494,26 +493,23 @@ func DataSourceEndpoint() *schema.Resource {
}
}

const (
DSNameEndpoint = "Endpoint Data Source"
)

func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DMSConn(ctx)
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

endptID := d.Get("endpoint_id").(string)

out, err := FindEndpointByID(ctx, conn, endptID)

if err != nil {
create.DiagError(names.DMS, create.ErrActionReading, DSNameEndpoint, d.Id(), err)
return sdkdiag.AppendErrorf(diags, "reading DMS Endpoint (%s): %s", endptID, err)
}

d.SetId(aws.StringValue(out.EndpointIdentifier))

d.Set("endpoint_id", out.EndpointIdentifier)
d.Set("endpoint_arn", out.EndpointArn)
arn := aws.StringValue(out.EndpointArn)
d.Set("endpoint_arn", arn)
d.Set("endpoint_type", out.EndpointType)
d.Set("database_name", out.DatabaseName)
d.Set("engine_name", out.EngineName)
Expand All @@ -522,22 +518,21 @@ func dataSourceEndpointRead(ctx context.Context, d *schema.ResourceData, meta in
d.Set("ssl_mode", out.SslMode)
d.Set("username", out.Username)

err = resourceEndpointSetState(d, out)
if err != nil {
create.DiagError(names.DMS, create.ErrActionReading, DSNameEndpoint, d.Id(), err)
if err := resourceEndpointSetState(d, out); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

tags, err := listTags(ctx, conn, aws.StringValue(out.EndpointArn))
tags, err := listTags(ctx, conn, arn)
if err != nil {
return create.DiagError(names.DMS, create.ErrActionReading, DSNameEndpoint, d.Id(), err)
return sdkdiag.AppendErrorf(diags, "listing tags for DMS Endpoint (%s): %s", arn, err)
}

tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig)

//lintignore:AWSR002
if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil {
return create.DiagError(names.DMS, create.ErrActionSetting, DSNameEndpoint, d.Id(), err)
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)
}

return nil
return diags
}
4 changes: 0 additions & 4 deletions internal/service/dms/endpoint_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
)

func TestAccDMSEndpointDataSource_basic(t *testing.T) {
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_dms_endpoint.test"
Expand Down
34 changes: 0 additions & 34 deletions internal/service/dms/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,6 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func FindEndpointByID(ctx context.Context, conn *dms.DatabaseMigrationService, id string) (*dms.Endpoint, error) {
input := &dms.DescribeEndpointsInput{
Filters: []*dms.Filter{
{
Name: aws.String("endpoint-id"),
Values: aws.StringSlice([]string{id}),
},
},
}

output, err := conn.DescribeEndpointsWithContext(ctx, input)

if tfawserr.ErrCodeEquals(err, dms.ErrCodeResourceNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.Endpoints) == 0 || output.Endpoints[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(output.Endpoints); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return output.Endpoints[0], nil
}

func FindReplicationTaskByID(ctx context.Context, conn *dms.DatabaseMigrationService, id string) (*dms.ReplicationTask, error) {
input := &dms.DescribeReplicationTasksInput{
Filters: []*dms.Filter{
Expand Down
Loading