diff --git a/go.mod b/go.mod index 65e987b641c..0dec2373c30 100644 --- a/go.mod +++ b/go.mod @@ -77,6 +77,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/devopsguru v1.30.9 github.com/aws/aws-sdk-go-v2/service/directoryservice v1.24.9 github.com/aws/aws-sdk-go-v2/service/dlm v1.24.9 + github.com/aws/aws-sdk-go-v2/service/docdb v1.34.6 github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.9.8 github.com/aws/aws-sdk-go-v2/service/drs v1.26.5 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.32.7 diff --git a/go.sum b/go.sum index aa4c17e3791..28bc172aaeb 100644 --- a/go.sum +++ b/go.sum @@ -174,6 +174,8 @@ github.com/aws/aws-sdk-go-v2/service/directoryservice v1.24.9 h1:IUT9X0mSw7nn163 github.com/aws/aws-sdk-go-v2/service/directoryservice v1.24.9/go.mod h1:D4kc1uNcsRFGQTJzZDZiLKU8slsvgeKfFvoLDWahYZQ= github.com/aws/aws-sdk-go-v2/service/dlm v1.24.9 h1:rbCsQ+v8ZhPCyraCMGJ0ryoRNyOST+Epqf7BLFU6juw= github.com/aws/aws-sdk-go-v2/service/dlm v1.24.9/go.mod h1:TDugCcN4kVVjmf3AyrgJxF+bMGo6xE0rIqzekOdBci0= +github.com/aws/aws-sdk-go-v2/service/docdb v1.34.6 h1:6aHlQCKKZt3I/k816Pf9p76ThfBOOFtd3iauHAfnCRQ= +github.com/aws/aws-sdk-go-v2/service/docdb v1.34.6/go.mod h1:b/JbDffezMACPOD8WkqS6zdegurMGSr76fWb69yfbmU= github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.9.8 h1:h2e8qCW13l+HidSl5AL/yyTm7SjG+1rccnL5v0H0DMs= github.com/aws/aws-sdk-go-v2/service/docdbelastic v1.9.8/go.mod h1:sNRGOjnAEBY66qjElTl5VMEv1vm8bCD0HNjheIpsG8g= github.com/aws/aws-sdk-go-v2/service/drs v1.26.5 h1:KGamj85Y3eghj2i/D4Hm72rjkHClGSQv3kiDb/17sUg= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 6ca8252ed30..64e3e5b05cc 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -69,6 +69,7 @@ import ( devopsguru_sdkv2 "github.com/aws/aws-sdk-go-v2/service/devopsguru" directoryservice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/directoryservice" dlm_sdkv2 "github.com/aws/aws-sdk-go-v2/service/dlm" + docdb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdb" docdbelastic_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdbelastic" drs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/drs" dynamodb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/dynamodb" @@ -194,7 +195,6 @@ import ( detective_sdkv1 "github.com/aws/aws-sdk-go/service/detective" directconnect_sdkv1 "github.com/aws/aws-sdk-go/service/directconnect" directoryservice_sdkv1 "github.com/aws/aws-sdk-go/service/directoryservice" - docdb_sdkv1 "github.com/aws/aws-sdk-go/service/docdb" ec2_sdkv1 "github.com/aws/aws-sdk-go/service/ec2" ecs_sdkv1 "github.com/aws/aws-sdk-go/service/ecs" efs_sdkv1 "github.com/aws/aws-sdk-go/service/efs" @@ -570,8 +570,8 @@ func (c *AWSClient) DirectConnectConn(ctx context.Context) *directconnect_sdkv1. return errs.Must(conn[*directconnect_sdkv1.DirectConnect](ctx, c, names.DirectConnect, make(map[string]any))) } -func (c *AWSClient) DocDBConn(ctx context.Context) *docdb_sdkv1.DocDB { - return errs.Must(conn[*docdb_sdkv1.DocDB](ctx, c, names.DocDB, make(map[string]any))) +func (c *AWSClient) DocDBClient(ctx context.Context) *docdb_sdkv2.Client { + return errs.Must(client[*docdb_sdkv2.Client](ctx, c, names.DocDB, make(map[string]any))) } func (c *AWSClient) DocDBElasticClient(ctx context.Context) *docdbelastic_sdkv2.Client { diff --git a/internal/service/docdb/cluster.go b/internal/service/docdb/cluster.go index f8868f7d8e0..e506f017c98 100644 --- a/internal/service/docdb/cluster.go +++ b/internal/service/docdb/cluster.go @@ -7,19 +7,22 @@ import ( "context" "fmt" "log" + "reflect" "strings" "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" "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-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/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -271,7 +274,7 @@ func ResourceCluster() *schema.Resource { func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) identifier := create.NewNameGenerator( create.WithConfiguredName(d.Get(names.AttrClusterIdentifier).(string)), @@ -299,11 +302,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v := d.Get(names.AttrAvailabilityZones).(*schema.Set); v.Len() > 0 { - input.AvailabilityZones = flex.ExpandStringSet(v) + input.AvailabilityZones = flex.ExpandStringValueSet(v) } if v, ok := d.GetOk("backup_retention_period"); ok { - inputM.BackupRetentionPeriod = aws.Int64(int64(v.(int))) + inputM.BackupRetentionPeriod = aws.Int32(int32(v.(int))) requiresModifyDbCluster = true } @@ -317,7 +320,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && len(v.([]interface{})) > 0 { - input.EnableCloudwatchLogsExports = flex.ExpandStringList(v.([]interface{})) + input.EnableCloudwatchLogsExports = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := d.GetOk(names.AttrEngineVersion); ok { @@ -329,7 +332,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk(names.AttrPort); ok { - input.Port = aws.Int64(int64(v.(int))) + input.Port = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("preferred_backup_window"); ok { @@ -347,11 +350,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v := d.Get(names.AttrVPCSecurityGroupIDs).(*schema.Set); v.Len() > 0 { - input.VpcSecurityGroupIds = flex.ExpandStringSet(v) + input.VpcSecurityGroupIds = flex.ExpandStringValueSet(v) } _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) { - return conn.RestoreDBClusterFromSnapshotWithContext(ctx, input) + return conn.RestoreDBClusterFromSnapshot(ctx, input) }, errCodeInvalidParameterValue, "IAM role ARN value is invalid or does not include the required permissions") if err != nil { @@ -382,11 +385,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v := d.Get(names.AttrAvailabilityZones).(*schema.Set); v.Len() > 0 { - input.AvailabilityZones = flex.ExpandStringSet(v) + input.AvailabilityZones = flex.ExpandStringValueSet(v) } if v, ok := d.GetOk("backup_retention_period"); ok { - input.BackupRetentionPeriod = aws.Int64(int64(v.(int))) + input.BackupRetentionPeriod = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("db_cluster_parameter_group_name"); ok { @@ -398,7 +401,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && len(v.([]interface{})) > 0 { - input.EnableCloudwatchLogsExports = flex.ExpandStringList(v.([]interface{})) + input.EnableCloudwatchLogsExports = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := d.GetOk(names.AttrEngineVersion); ok { @@ -414,7 +417,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk(names.AttrPort); ok { - input.Port = aws.Int64(int64(v.(int))) + input.Port = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("preferred_backup_window"); ok { @@ -434,11 +437,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v := d.Get(names.AttrVPCSecurityGroupIDs).(*schema.Set); v.Len() > 0 { - input.VpcSecurityGroupIds = flex.ExpandStringSet(v) + input.VpcSecurityGroupIds = flex.ExpandStringValueSet(v) } _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) { - return conn.CreateDBClusterWithContext(ctx, input) + return conn.CreateDBCluster(ctx, input) }, errCodeInvalidParameterValue, "IAM role ARN value is invalid or does not include the required permissions") if err != nil { @@ -455,7 +458,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int if requiresModifyDbCluster { inputM.DBClusterIdentifier = aws.String(d.Id()) - _, err := conn.ModifyDBClusterWithContext(ctx, inputM) + _, err := conn.ModifyDBCluster(ctx, inputM) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying DocumentDB Cluster (%s): %s", d.Id(), err) @@ -471,9 +474,9 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - dbc, err := FindDBClusterByID(ctx, conn, d.Id()) + dbc, err := findDBClusterByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Cluster (%s) not found, removing from state", d.Id()) @@ -487,7 +490,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter // Ignore the following API error for regions/partitions that do not support DocDB Global Clusters: // InvalidParameterValue: Access Denied to API Version: APIGlobalDatabases - if globalCluster, err := findGlobalClusterByClusterARN(ctx, conn, aws.StringValue(dbc.DBClusterArn)); tfresource.NotFound(err) || tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "Access Denied to API Version: APIGlobalDatabases") { + if globalCluster, err := findGlobalClusterByClusterARN(ctx, conn, aws.ToString(dbc.DBClusterArn)); tfresource.NotFound(err) || tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "Access Denied to API Version: APIGlobalDatabases") { d.Set("global_cluster_identifier", "") } else if err != nil { return sdkdiag.AppendErrorf(diags, "reading DocumentDB Global Cluster information for DocumentDB Cluster (%s): %s", d.Id(), err) @@ -496,20 +499,20 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter } d.Set(names.AttrARN, dbc.DBClusterArn) - d.Set(names.AttrAvailabilityZones, aws.StringValueSlice(dbc.AvailabilityZones)) + d.Set(names.AttrAvailabilityZones, dbc.AvailabilityZones) d.Set("backup_retention_period", dbc.BackupRetentionPeriod) d.Set(names.AttrClusterIdentifier, dbc.DBClusterIdentifier) - d.Set("cluster_identifier_prefix", create.NamePrefixFromName(aws.StringValue(dbc.DBClusterIdentifier))) + d.Set("cluster_identifier_prefix", create.NamePrefixFromName(aws.ToString(dbc.DBClusterIdentifier))) var clusterMembers []string for _, v := range dbc.DBClusterMembers { - clusterMembers = append(clusterMembers, aws.StringValue(v.DBInstanceIdentifier)) + clusterMembers = append(clusterMembers, aws.ToString(v.DBInstanceIdentifier)) } d.Set("cluster_members", clusterMembers) d.Set("cluster_resource_id", dbc.DbClusterResourceId) d.Set("db_cluster_parameter_group_name", dbc.DBClusterParameterGroup) d.Set("db_subnet_group_name", dbc.DBSubnetGroup) d.Set(names.AttrDeletionProtection, dbc.DeletionProtection) - d.Set("enabled_cloudwatch_logs_exports", aws.StringValueSlice(dbc.EnabledCloudwatchLogsExports)) + d.Set("enabled_cloudwatch_logs_exports", dbc.EnabledCloudwatchLogsExports) d.Set(names.AttrEndpoint, dbc.Endpoint) d.Set(names.AttrEngineVersion, dbc.EngineVersion) d.Set(names.AttrEngine, dbc.Engine) @@ -524,7 +527,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set(names.AttrStorageType, dbc.StorageType) var securityGroupIDs []string for _, v := range dbc.VpcSecurityGroups { - securityGroupIDs = append(securityGroupIDs, aws.StringValue(v.VpcSecurityGroupId)) + securityGroupIDs = append(securityGroupIDs, aws.ToString(v.VpcSecurityGroupId)) } d.Set(names.AttrVPCSecurityGroupIDs, securityGroupIDs) @@ -533,7 +536,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll, "global_cluster_identifier", "skip_final_snapshot") { input := &docdb.ModifyDBClusterInput{ @@ -546,7 +549,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChange("backup_retention_period") { - input.BackupRetentionPeriod = aws.Int64(int64(d.Get("backup_retention_period").(int))) + input.BackupRetentionPeriod = aws.Int32(int32(d.Get("backup_retention_period").(int))) } if d.HasChange("db_cluster_parameter_group_name") { @@ -583,26 +586,26 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int if d.HasChange(names.AttrVPCSecurityGroupIDs) { if v := d.Get(names.AttrVPCSecurityGroupIDs).(*schema.Set); v.Len() > 0 { - input.VpcSecurityGroupIds = flex.ExpandStringSet(v) + input.VpcSecurityGroupIds = flex.ExpandStringValueSet(v) } else { - input.VpcSecurityGroupIds = aws.StringSlice([]string{}) + input.VpcSecurityGroupIds = []string{} } } _, err := tfresource.RetryWhen(ctx, 5*time.Minute, func() (interface{}, error) { - return conn.ModifyDBClusterWithContext(ctx, input) + return conn.ModifyDBCluster(ctx, input) }, func(err error) (bool, error) { if tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "IAM role ARN value is invalid or does not include the required permissions") { return true, err } - if tfawserr.ErrMessageContains(err, docdb.ErrCodeInvalidDBClusterStateFault, "is not currently in the available state") { + if errs.IsAErrorMessageContains[*awstypes.InvalidDBClusterStateFault](err, "is not currently in the available state") { return true, err } - if tfawserr.ErrMessageContains(err, docdb.ErrCodeInvalidDBClusterStateFault, "cluster is a part of a global cluster") { + if errs.IsAErrorMessageContains[*awstypes.InvalidDBClusterStateFault](err, "cluster is a part of a global cluster") { return true, err } @@ -641,7 +644,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) skipFinalSnapshot := d.Get("skip_final_snapshot").(bool) input := &docdb.DeleteDBClusterInput{ @@ -666,14 +669,14 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int log.Printf("[DEBUG] Deleting DocumentDB Cluster: %s", d.Id()) _, err := tfresource.RetryWhen(ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { - return conn.DeleteDBClusterWithContext(ctx, input) + return conn.DeleteDBCluster(ctx, input) }, func(err error) (bool, error) { - if tfawserr.ErrMessageContains(err, docdb.ErrCodeInvalidDBClusterStateFault, "is not currently in the available state") { + if errs.IsAErrorMessageContains[*awstypes.InvalidDBClusterStateFault](err, "is not currently in the available state") { return true, err } - if tfawserr.ErrMessageContains(err, docdb.ErrCodeInvalidDBClusterStateFault, "cluster is a part of a global cluster") { + if errs.IsAErrorMessageContains[*awstypes.InvalidDBClusterStateFault](err, "cluster is a part of a global cluster") { return true, err } @@ -681,7 +684,7 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int }, ) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBClusterNotFoundFault) { + if errs.IsA[*awstypes.DBClusterNotFoundFault](err) { return diags } @@ -696,16 +699,16 @@ func resourceClusterDelete(ctx context.Context, d *schema.ResourceData, meta int return diags } -func expandCloudwatchLogsExportConfiguration(d *schema.ResourceData) *docdb.CloudwatchLogsExportConfiguration { // nosemgrep:ci.caps0-in-func-name +func expandCloudwatchLogsExportConfiguration(d *schema.ResourceData) *awstypes.CloudwatchLogsExportConfiguration { // nosemgrep:ci.caps0-in-func-name oraw, nraw := d.GetChange("enabled_cloudwatch_logs_exports") o := oraw.([]interface{}) n := nraw.([]interface{}) create, disable := diffCloudWatchLogsExportConfiguration(o, n) - return &docdb.CloudwatchLogsExportConfiguration{ - EnableLogTypes: flex.ExpandStringList(create), - DisableLogTypes: flex.ExpandStringList(disable), + return &awstypes.CloudwatchLogsExportConfiguration{ + EnableLogTypes: flex.ExpandStringValueList(create), + DisableLogTypes: flex.ExpandStringValueList(disable), } } @@ -728,15 +731,16 @@ func diffCloudWatchLogsExportConfiguration(old, new []interface{}) ([]interface{ return add, disable } -func removeClusterFromGlobalCluster(ctx context.Context, conn *docdb.DocDB, clusterARN, globalClusterID string, timeout time.Duration) error { +func removeClusterFromGlobalCluster(ctx context.Context, conn *docdb.Client, clusterARN, globalClusterID string, timeout time.Duration) error { input := &docdb.RemoveFromGlobalClusterInput{ DbClusterIdentifier: aws.String(clusterARN), GlobalClusterIdentifier: aws.String(globalClusterID), } - _, err := conn.RemoveFromGlobalClusterWithContext(ctx, input) + _, err := conn.RemoveFromGlobalCluster(ctx, input) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBClusterNotFoundFault, docdb.ErrCodeGlobalClusterNotFoundFault) || tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "is not found in global cluster") { + if errs.IsA[*awstypes.DBClusterNotFoundFault](err) || errs.IsA[*awstypes.GlobalClusterNotFoundFault](err) || + tfawserr.ErrMessageContains(err, errCodeInvalidParameterValue, "is not found in global cluster") { return nil } @@ -755,18 +759,18 @@ func removeClusterFromGlobalCluster(ctx context.Context, conn *docdb.DocDB, clus return nil } -func FindDBClusterByID(ctx context.Context, conn *docdb.DocDB, id string) (*docdb.DBCluster, error) { +func findDBClusterByID(ctx context.Context, conn *docdb.Client, id string) (*awstypes.DBCluster, error) { input := &docdb.DescribeDBClustersInput{ DBClusterIdentifier: aws.String(id), } - output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[*docdb.DBCluster]()) + output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[awstypes.DBCluster]()) if err != nil { return nil, err } // Eventual consistency check. - if aws.StringValue(output.DBClusterIdentifier) != id { + if aws.ToString(output.DBClusterIdentifier) != id { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -775,58 +779,55 @@ func FindDBClusterByID(ctx context.Context, conn *docdb.DocDB, id string) (*docd return output, nil } -func findClusterByARN(ctx context.Context, conn *docdb.DocDB, arn string) (*docdb.DBCluster, error) { +func findClusterByARN(ctx context.Context, conn *docdb.Client, arn string) (*awstypes.DBCluster, error) { input := &docdb.DescribeDBClustersInput{} - return findDBCluster(ctx, conn, input, func(v *docdb.DBCluster) bool { - return aws.StringValue(v.DBClusterArn) == arn + return findDBCluster(ctx, conn, input, func(v awstypes.DBCluster) bool { + return aws.ToString(v.DBClusterArn) == arn }) } -func findDBCluster(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClustersInput, filter tfslices.Predicate[*docdb.DBCluster]) (*docdb.DBCluster, error) { +func findDBCluster(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClustersInput, filter tfslices.Predicate[awstypes.DBCluster]) (*awstypes.DBCluster, error) { output, err := findDBClusters(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findDBClusters(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClustersInput, filter tfslices.Predicate[*docdb.DBCluster]) ([]*docdb.DBCluster, error) { - var output []*docdb.DBCluster +func findDBClusters(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClustersInput, filter tfslices.Predicate[awstypes.DBCluster]) ([]awstypes.DBCluster, error) { + var output []awstypes.DBCluster - err := conn.DescribeDBClustersPagesWithContext(ctx, input, func(page *docdb.DescribeDBClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBClusters { - if v != nil && filter(v) { - output = append(output, v) + if errs.IsA[*awstypes.DBClusterNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBClusterNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.DBClusters { + if !reflect.ValueOf(v).IsZero() && filter(v) { + output = append(output, v) + } + } } return output, nil } -func statusDBCluster(ctx context.Context, conn *docdb.DocDB, id string) retry.StateRefreshFunc { +func statusDBCluster(ctx context.Context, conn *docdb.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindDBClusterByID(ctx, conn, id) + output, err := findDBClusterByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -836,11 +837,11 @@ func statusDBCluster(ctx context.Context, conn *docdb.DocDB, id string) retry.St return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } -func waitDBClusterAvailable(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.DBCluster, error) { //nolint:unparam +func waitDBClusterAvailable(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.DBCluster, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{ clusterStatusCreating, @@ -860,14 +861,14 @@ func waitDBClusterAvailable(ctx context.Context, conn *docdb.DocDB, id string, t outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.DBCluster); ok { + if output, ok := outputRaw.(*awstypes.DBCluster); ok { return output, err } return nil, err } -func waitDBClusterDeleted(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.DBCluster, error) { +func waitDBClusterDeleted(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.DBCluster, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ clusterStatusAvailable, @@ -884,7 +885,7 @@ func waitDBClusterDeleted(ctx context.Context, conn *docdb.DocDB, id string, tim outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.DBCluster); ok { + if output, ok := outputRaw.(*awstypes.DBCluster); ok { return output, err } diff --git a/internal/service/docdb/cluster_instance.go b/internal/service/docdb/cluster_instance.go index 23a1f33a8b7..233e752ff8b 100644 --- a/internal/service/docdb/cluster_instance.go +++ b/internal/service/docdb/cluster_instance.go @@ -9,15 +9,16 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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-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/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -183,7 +184,7 @@ func ResourceClusterInstance() *schema.Resource { func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) identifier := create.NewNameGenerator( create.WithConfiguredName(d.Get(names.AttrIdentifier).(string)), @@ -196,7 +197,7 @@ func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, DBInstanceClass: aws.String(d.Get("instance_class").(string)), DBInstanceIdentifier: aws.String(identifier), Engine: aws.String(d.Get(names.AttrEngine).(string)), - PromotionTier: aws.Int64(int64(d.Get("promotion_tier").(int))), + PromotionTier: aws.Int32(int32(d.Get("promotion_tier").(int))), Tags: getTagsIn(ctx), } @@ -221,7 +222,7 @@ func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, } _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) { - return conn.CreateDBInstanceWithContext(ctx, input) + return conn.CreateDBInstance(ctx, input) }, errCodeInvalidParameterValue, "IAM role ARN value is invalid or does not include the required permissions") if err != nil { @@ -239,9 +240,9 @@ func resourceClusterInstanceCreate(ctx context.Context, d *schema.ResourceData, func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - db, err := FindDBInstanceByID(ctx, conn, d.Id()) + db, err := findDBInstanceByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Cluster Instance (%s) not found, removing from state", d.Id()) @@ -253,8 +254,8 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading DocumentDB Cluster Instance (%s): %s", d.Id(), err) } - clusterID := aws.StringValue(db.DBClusterIdentifier) - dbc, err := FindDBClusterByID(ctx, conn, clusterID) + clusterID := aws.ToString(db.DBClusterIdentifier) + dbc, err := findDBClusterByID(ctx, conn, clusterID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading DocumentDB Cluster (%s): %s", clusterID, err) @@ -280,7 +281,7 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me d.Set(names.AttrEngine, db.Engine) d.Set(names.AttrEngineVersion, db.EngineVersion) d.Set(names.AttrIdentifier, db.DBInstanceIdentifier) - d.Set("identifier_prefix", create.NamePrefixFromName(aws.StringValue(db.DBInstanceIdentifier))) + d.Set("identifier_prefix", create.NamePrefixFromName(aws.ToString(db.DBInstanceIdentifier))) d.Set("instance_class", db.DBInstanceClass) d.Set(names.AttrKMSKeyID, db.KmsKeyId) // The AWS API does not expose 'PerformanceInsightsKMSKeyId' the line below should be uncommented @@ -291,8 +292,8 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me d.Set("promotion_tier", db.PromotionTier) d.Set(names.AttrPubliclyAccessible, db.PubliclyAccessible) d.Set(names.AttrStorageEncrypted, db.StorageEncrypted) - if v := tfslices.Filter(dbc.DBClusterMembers, func(v *docdb.DBClusterMember) bool { - return aws.StringValue(v.DBInstanceIdentifier) == d.Id() + if v := tfslices.Filter(dbc.DBClusterMembers, func(v awstypes.DBClusterMember) bool { + return aws.ToString(v.DBInstanceIdentifier) == d.Id() }); len(v) == 1 { d.Set("writer", v[0].IsClusterWriter) } @@ -302,7 +303,7 @@ func resourceClusterInstanceRead(ctx context.Context, d *schema.ResourceData, me func resourceClusterInstanceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &docdb.ModifyDBInstanceInput{ @@ -339,11 +340,11 @@ func resourceClusterInstanceUpdate(ctx context.Context, d *schema.ResourceData, } if d.HasChange("promotion_tier") { - input.PromotionTier = aws.Int64(int64(d.Get("promotion_tier").(int))) + input.PromotionTier = aws.Int32(int32(d.Get("promotion_tier").(int))) } _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) { - return conn.ModifyDBInstanceWithContext(ctx, input) + return conn.ModifyDBInstance(ctx, input) }, errCodeInvalidParameterValue, "IAM role ARN value is invalid or does not include the required permissions") if err != nil { @@ -360,13 +361,17 @@ func resourceClusterInstanceUpdate(ctx context.Context, d *schema.ResourceData, func resourceClusterInstanceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) log.Printf("[DEBUG] Deleting DocumentDB Cluster Instance: %s", d.Id()) - _, err := conn.DeleteDBInstanceWithContext(ctx, &docdb.DeleteDBInstanceInput{ + _, err := conn.DeleteDBInstance(ctx, &docdb.DeleteDBInstanceInput{ DBInstanceIdentifier: aws.String(d.Id()), }) + if errs.IsA[*awstypes.DBInstanceNotFoundFault](err) { + return diags + } + if err != nil { return sdkdiag.AppendErrorf(diags, "deleting DocumentDB Cluster Instance (%s): %s", d.Id(), err) } @@ -378,7 +383,7 @@ func resourceClusterInstanceDelete(ctx context.Context, d *schema.ResourceData, return diags } -func FindDBInstanceByID(ctx context.Context, conn *docdb.DocDB, id string) (*docdb.DBInstance, error) { +func findDBInstanceByID(ctx context.Context, conn *docdb.Client, id string) (*awstypes.DBInstance, error) { input := &docdb.DescribeDBInstancesInput{ DBInstanceIdentifier: aws.String(id), } @@ -389,7 +394,7 @@ func FindDBInstanceByID(ctx context.Context, conn *docdb.DocDB, id string) (*doc } // Eventual consistency check. - if aws.StringValue(output.DBInstanceIdentifier) != id { + if aws.ToString(output.DBInstanceIdentifier) != id { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -398,50 +403,43 @@ func FindDBInstanceByID(ctx context.Context, conn *docdb.DocDB, id string) (*doc return output, nil } -func findDBInstance(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBInstancesInput) (*docdb.DBInstance, error) { +func findDBInstance(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBInstancesInput) (*awstypes.DBInstance, error) { output, err := findDBInstances(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findDBInstances(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBInstancesInput) ([]*docdb.DBInstance, error) { - var output []*docdb.DBInstance +func findDBInstances(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBInstancesInput) ([]awstypes.DBInstance, error) { + var output []awstypes.DBInstance - err := conn.DescribeDBInstancesPagesWithContext(ctx, input, func(page *docdb.DescribeDBInstancesOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBInstancesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBInstances { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.DBInstanceNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastRequest: input, + LastError: err, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBInstanceNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + output = append(output, page.DBInstances...) } return output, nil } -func statusDBInstance(ctx context.Context, conn *docdb.DocDB, id string) retry.StateRefreshFunc { +func statusDBInstance(ctx context.Context, conn *docdb.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindDBInstanceByID(ctx, conn, id) + output, err := findDBInstanceByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -451,11 +449,11 @@ func statusDBInstance(ctx context.Context, conn *docdb.DocDB, id string) retry.S return nil, "", err } - return output, aws.StringValue(output.DBInstanceStatus), nil + return output, aws.ToString(output.DBInstanceStatus), nil } } -func waitDBInstanceAvailable(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.DBInstance, error) { //nolint:unparam +func waitDBInstanceAvailable(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.DBInstance, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{ "backing-up", @@ -472,23 +470,24 @@ func waitDBInstanceAvailable(ctx context.Context, conn *docdb.DocDB, id string, "storage-optimization", "upgrading", }, - Target: []string{"available"}, - Refresh: statusDBInstance(ctx, conn, id), - Timeout: timeout, - MinTimeout: 10 * time.Second, - Delay: 30 * time.Second, + Target: []string{"available"}, + Refresh: statusDBInstance(ctx, conn, id), + Timeout: timeout, + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, + ContinuousTargetOccurence: 2, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.DBInstance); ok { + if output, ok := outputRaw.(*awstypes.DBInstance); ok { return output, err } return nil, err } -func waitDBInstanceDeleted(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.DBInstance, error) { +func waitDBInstanceDeleted(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.DBInstance, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ "configuring-log-exports", @@ -504,7 +503,7 @@ func waitDBInstanceDeleted(ctx context.Context, conn *docdb.DocDB, id string, ti outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.DBInstance); ok { + if output, ok := outputRaw.(*awstypes.DBInstance); ok { return output, err } diff --git a/internal/service/docdb/cluster_instance_test.go b/internal/service/docdb/cluster_instance_test.go index d2b8befda8a..401efa2cfc1 100644 --- a/internal/service/docdb/cluster_instance_test.go +++ b/internal/service/docdb/cluster_instance_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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" @@ -22,7 +22,7 @@ import ( func TestAccDocDBClusterInstance_basic(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -87,7 +87,7 @@ func TestAccDocDBClusterInstance_basic(t *testing.T) { func TestAccDocDBClusterInstance_disappears(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -111,7 +111,7 @@ func TestAccDocDBClusterInstance_disappears(t *testing.T) { func TestAccDocDBClusterInstance_identifierGenerated(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -143,7 +143,7 @@ func TestAccDocDBClusterInstance_identifierGenerated(t *testing.T) { func TestAccDocDBClusterInstance_identifierPrefix(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -176,7 +176,7 @@ func TestAccDocDBClusterInstance_identifierPrefix(t *testing.T) { func TestAccDocDBClusterInstance_tags(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -225,7 +225,7 @@ func TestAccDocDBClusterInstance_tags(t *testing.T) { func TestAccDocDBClusterInstance_performanceInsights(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rNamePrefix := acctest.ResourcePrefix rName := sdkacctest.RandomWithPrefix(rNamePrefix) @@ -261,7 +261,7 @@ func TestAccDocDBClusterInstance_performanceInsights(t *testing.T) { func TestAccDocDBClusterInstance_az(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -293,7 +293,7 @@ func TestAccDocDBClusterInstance_az(t *testing.T) { func TestAccDocDBClusterInstance_kmsKey(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -325,7 +325,7 @@ func TestAccDocDBClusterInstance_kmsKey(t *testing.T) { func TestAccDocDBClusterInstance_copyTagsToSnapshot(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBInstance + var v awstypes.DBInstance resourceName := "aws_docdb_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -364,7 +364,7 @@ func TestAccDocDBClusterInstance_copyTagsToSnapshot(t *testing.T) { func testAccCheckClusterInstanceDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_cluster_instance" { @@ -388,14 +388,14 @@ func testAccCheckClusterInstanceDestroy(ctx context.Context) resource.TestCheckF } } -func testAccCheckClusterInstanceExists(ctx context.Context, n string, v *docdb.DBInstance) resource.TestCheckFunc { +func testAccCheckClusterInstanceExists(ctx context.Context, n string, v *awstypes.DBInstance) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindDBInstanceByID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/docdb/cluster_parameter_group.go b/internal/service/docdb/cluster_parameter_group.go index 31466da1831..d530b2a85c2 100644 --- a/internal/service/docdb/cluster_parameter_group.go +++ b/internal/service/docdb/cluster_parameter_group.go @@ -7,17 +7,19 @@ import ( "context" "fmt" "log" + "reflect" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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-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" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -77,10 +79,10 @@ func ResourceClusterParameterGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "apply_method": { - Type: schema.TypeString, - Optional: true, - Default: docdb.ApplyMethodPendingReboot, - ValidateFunc: validation.StringInSlice(docdb.ApplyMethod_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: awstypes.ApplyMethodPendingReboot, + ValidateDiagFunc: enum.Validate[awstypes.ApplyMethod](), }, names.AttrName: { Type: schema.TypeString, @@ -103,7 +105,7 @@ func ResourceClusterParameterGroup() *schema.Resource { func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &docdb.CreateDBClusterParameterGroupInput{ @@ -113,7 +115,7 @@ func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.Resource Tags: getTagsIn(ctx), } - _, err := conn.CreateDBClusterParameterGroupWithContext(ctx, input) + _, err := conn.CreateDBClusterParameterGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating DocumentDB Cluster Parameter Group (%s): %s", name, err) @@ -134,9 +136,9 @@ func resourceClusterParameterGroupCreate(ctx context.Context, d *schema.Resource func resourceClusterParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - dbClusterParameterGroup, err := FindDBClusterParameterGroupByName(ctx, conn, d.Id()) + dbClusterParameterGroup, err := findDBClusterParameterGroupByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Cluster Parameter Group (%s) not found, removing from state", d.Id()) @@ -152,7 +154,7 @@ func resourceClusterParameterGroupRead(ctx context.Context, d *schema.ResourceDa d.Set(names.AttrDescription, dbClusterParameterGroup.Description) d.Set(names.AttrFamily, dbClusterParameterGroup.DBParameterGroupFamily) d.Set(names.AttrName, dbClusterParameterGroup.DBClusterParameterGroupName) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(dbClusterParameterGroup.DBClusterParameterGroupName))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(dbClusterParameterGroup.DBClusterParameterGroupName))) input := &docdb.DescribeDBClusterParametersInput{ DBClusterParameterGroupName: aws.String(d.Id()), @@ -173,7 +175,7 @@ func resourceClusterParameterGroupRead(ctx context.Context, d *schema.ResourceDa func resourceClusterParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChange(names.AttrParameter) { o, n := d.GetChange(names.AttrParameter) @@ -193,14 +195,14 @@ func resourceClusterParameterGroupUpdate(ctx context.Context, d *schema.Resource func resourceClusterParameterGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) log.Printf("[DEBUG] Deleting DocumentDB Cluster Parameter Group: %s", d.Id()) - _, err := conn.DeleteDBClusterParameterGroupWithContext(ctx, &docdb.DeleteDBClusterParameterGroupInput{ + _, err := conn.DeleteDBClusterParameterGroup(ctx, &docdb.DeleteDBClusterParameterGroupInput{ DBClusterParameterGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBParameterGroupNotFoundFault) { + if errs.IsA[*awstypes.DBParameterGroupNotFoundFault](err) { return diags } @@ -209,7 +211,7 @@ func resourceClusterParameterGroupDelete(ctx context.Context, d *schema.Resource } _, err = tfresource.RetryUntilNotFound(ctx, 10*time.Minute, func() (interface{}, error) { - return FindDBClusterParameterGroupByName(ctx, conn, d.Id()) + return findDBClusterParameterGroupByName(ctx, conn, d.Id()) }) if err != nil { @@ -219,7 +221,7 @@ func resourceClusterParameterGroupDelete(ctx context.Context, d *schema.Resource return diags } -func modifyClusterParameterGroupParameters(ctx context.Context, conn *docdb.DocDB, name string, parameters []*docdb.Parameter) error { +func modifyClusterParameterGroupParameters(ctx context.Context, conn *docdb.Client, name string, parameters []awstypes.Parameter) error { const ( clusterParameterGroupMaxParamsBulkEdit = 20 ) @@ -230,7 +232,7 @@ func modifyClusterParameterGroupParameters(ctx context.Context, conn *docdb.DocD Parameters: chunk, } - _, err := conn.ModifyDBClusterParameterGroupWithContext(ctx, input) + _, err := conn.ModifyDBClusterParameterGroup(ctx, input) if err != nil { return fmt.Errorf("modifying DocumentDB Cluster Parameter Group (%s): %w", name, err) @@ -240,7 +242,7 @@ func modifyClusterParameterGroupParameters(ctx context.Context, conn *docdb.DocD return nil } -func FindDBClusterParameterGroupByName(ctx context.Context, conn *docdb.DocDB, name string) (*docdb.DBClusterParameterGroup, error) { +func findDBClusterParameterGroupByName(ctx context.Context, conn *docdb.Client, name string) (*awstypes.DBClusterParameterGroup, error) { input := &docdb.DescribeDBClusterParameterGroupsInput{ DBClusterParameterGroupName: aws.String(name), } @@ -251,7 +253,7 @@ func FindDBClusterParameterGroupByName(ctx context.Context, conn *docdb.DocDB, n } // Eventual consistency check. - if aws.StringValue(output.DBClusterParameterGroupName) != name { + if aws.ToString(output.DBClusterParameterGroupName) != name { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -260,73 +262,67 @@ func FindDBClusterParameterGroupByName(ctx context.Context, conn *docdb.DocDB, n return output, nil } -func findDBClusterParameterGroup(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClusterParameterGroupsInput) (*docdb.DBClusterParameterGroup, error) { +func findDBClusterParameterGroup(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClusterParameterGroupsInput) (*awstypes.DBClusterParameterGroup, error) { output, err := findDBClusterParameterGroups(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findDBClusterParameterGroups(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClusterParameterGroupsInput) ([]*docdb.DBClusterParameterGroup, error) { - var output []*docdb.DBClusterParameterGroup +func findDBClusterParameterGroups(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClusterParameterGroupsInput) ([]awstypes.DBClusterParameterGroup, error) { + var output []awstypes.DBClusterParameterGroup - err := conn.DescribeDBClusterParameterGroupsPagesWithContext(ctx, input, func(page *docdb.DescribeDBClusterParameterGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBClusterParameterGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBClusterParameterGroups { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.DBParameterGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBParameterGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.DBClusterParameterGroups { + if !reflect.ValueOf(v).IsZero() { + output = append(output, v) + } + } } return output, nil } -func findDBClusterParameters(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClusterParametersInput) ([]*docdb.Parameter, error) { - var output []*docdb.Parameter +func findDBClusterParameters(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClusterParametersInput) ([]awstypes.Parameter, error) { + var output []awstypes.Parameter - err := conn.DescribeDBClusterParametersPagesWithContext(ctx, input, func(page *docdb.DescribeDBClusterParametersOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBClusterParametersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.Parameters { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.DBParameterGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBParameterGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.Parameters { + if !reflect.ValueOf(v).IsZero() { + output = append(output, v) + } + } } return output, nil diff --git a/internal/service/docdb/cluster_parameter_group_test.go b/internal/service/docdb/cluster_parameter_group_test.go index c9cb5e72e0a..77568faee8b 100644 --- a/internal/service/docdb/cluster_parameter_group_test.go +++ b/internal/service/docdb/cluster_parameter_group_test.go @@ -9,7 +9,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -23,7 +23,7 @@ import ( func TestAccDocDBClusterParameterGroup_basic(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -56,7 +56,7 @@ func TestAccDocDBClusterParameterGroup_basic(t *testing.T) { func TestAccDocDBClusterParameterGroup_disappears(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -80,7 +80,7 @@ func TestAccDocDBClusterParameterGroup_disappears(t *testing.T) { func TestAccDocDBClusterParameterGroup_nameGenerated(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" resource.ParallelTest(t, resource.TestCase{ @@ -108,7 +108,7 @@ func TestAccDocDBClusterParameterGroup_nameGenerated(t *testing.T) { func TestAccDocDBClusterParameterGroup_namePrefix(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" resource.ParallelTest(t, resource.TestCase{ @@ -136,7 +136,7 @@ func TestAccDocDBClusterParameterGroup_namePrefix(t *testing.T) { func TestAccDocDBClusterParameterGroup_description(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -164,7 +164,7 @@ func TestAccDocDBClusterParameterGroup_description(t *testing.T) { func TestAccDocDBClusterParameterGroup_systemParameter(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -193,7 +193,7 @@ func TestAccDocDBClusterParameterGroup_systemParameter(t *testing.T) { func TestAccDocDBClusterParameterGroup_parameter(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -238,7 +238,7 @@ func TestAccDocDBClusterParameterGroup_parameter(t *testing.T) { func TestAccDocDBClusterParameterGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBClusterParameterGroup + var v awstypes.DBClusterParameterGroup resourceName := "aws_docdb_cluster_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -284,7 +284,7 @@ func TestAccDocDBClusterParameterGroup_tags(t *testing.T) { func testAccCheckClusterParameterGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_cluster_parameter_group" { @@ -308,7 +308,7 @@ func testAccCheckClusterParameterGroupDestroy(ctx context.Context) resource.Test } } -func testAccCheckClusterParameterGroupExists(ctx context.Context, n string, v *docdb.DBClusterParameterGroup) resource.TestCheckFunc { +func testAccCheckClusterParameterGroupExists(ctx context.Context, n string, v *awstypes.DBClusterParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -319,7 +319,7 @@ func testAccCheckClusterParameterGroupExists(ctx context.Context, n string, v *d return errors.New("No DocumentDB Cluster Parameter Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindDBClusterParameterGroupByName(ctx, conn, rs.Primary.ID) diff --git a/internal/service/docdb/cluster_snapshot.go b/internal/service/docdb/cluster_snapshot.go index c93b850c6f6..62b3e02fc46 100644 --- a/internal/service/docdb/cluster_snapshot.go +++ b/internal/service/docdb/cluster_snapshot.go @@ -6,15 +6,17 @@ package docdb import ( "context" "log" + "reflect" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -99,7 +101,7 @@ func ResourceClusterSnapshot() *schema.Resource { func resourceClusterSnapshotCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) clusterSnapshotID := d.Get("db_cluster_snapshot_identifier").(string) input := &docdb.CreateDBClusterSnapshotInput{ @@ -107,7 +109,7 @@ func resourceClusterSnapshotCreate(ctx context.Context, d *schema.ResourceData, DBClusterSnapshotIdentifier: aws.String(clusterSnapshotID), } - _, err := conn.CreateDBClusterSnapshotWithContext(ctx, input) + _, err := conn.CreateDBClusterSnapshot(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating DocumentDB Cluster Snapshot (%s): %s", clusterSnapshotID, err) @@ -124,9 +126,9 @@ func resourceClusterSnapshotCreate(ctx context.Context, d *schema.ResourceData, func resourceClusterSnapshotRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - snapshot, err := FindClusterSnapshotByID(ctx, conn, d.Id()) + snapshot, err := findClusterSnapshotByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Cluster Snapshot (%s) not found, removing from state", d.Id()) @@ -138,7 +140,7 @@ func resourceClusterSnapshotRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading DocumentDB Cluster Snapshot (%s): %s", d.Id(), err) } - d.Set(names.AttrAvailabilityZones, aws.StringValueSlice(snapshot.AvailabilityZones)) + d.Set(names.AttrAvailabilityZones, snapshot.AvailabilityZones) d.Set("db_cluster_identifier", snapshot.DBClusterIdentifier) d.Set("db_cluster_snapshot_arn", snapshot.DBClusterSnapshotArn) d.Set("db_cluster_snapshot_identifier", snapshot.DBClusterSnapshotIdentifier) @@ -157,14 +159,14 @@ func resourceClusterSnapshotRead(ctx context.Context, d *schema.ResourceData, me func resourceClusterSnapshotDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) log.Printf("[DEBUG] Deleting DocumentDB Cluster Snapshot: %s", d.Id()) - _, err := conn.DeleteDBClusterSnapshotWithContext(ctx, &docdb.DeleteDBClusterSnapshotInput{ + _, err := conn.DeleteDBClusterSnapshot(ctx, &docdb.DeleteDBClusterSnapshotInput{ DBClusterSnapshotIdentifier: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBClusterSnapshotNotFoundFault) { + if errs.IsA[*awstypes.DBClusterSnapshotNotFoundFault](err) { return diags } @@ -175,7 +177,7 @@ func resourceClusterSnapshotDelete(ctx context.Context, d *schema.ResourceData, return diags } -func FindClusterSnapshotByID(ctx context.Context, conn *docdb.DocDB, id string) (*docdb.DBClusterSnapshot, error) { +func findClusterSnapshotByID(ctx context.Context, conn *docdb.Client, id string) (*awstypes.DBClusterSnapshot, error) { input := &docdb.DescribeDBClusterSnapshotsInput{ DBClusterSnapshotIdentifier: aws.String(id), } @@ -186,7 +188,7 @@ func FindClusterSnapshotByID(ctx context.Context, conn *docdb.DocDB, id string) } // Eventual consistency check. - if aws.StringValue(output.DBClusterSnapshotIdentifier) != id { + if aws.ToString(output.DBClusterSnapshotIdentifier) != id { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -195,50 +197,47 @@ func FindClusterSnapshotByID(ctx context.Context, conn *docdb.DocDB, id string) return output, nil } -func findClusterSnapshot(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClusterSnapshotsInput) (*docdb.DBClusterSnapshot, error) { +func findClusterSnapshot(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClusterSnapshotsInput) (*awstypes.DBClusterSnapshot, error) { output, err := findClusterSnapshots(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findClusterSnapshots(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBClusterSnapshotsInput) ([]*docdb.DBClusterSnapshot, error) { - var output []*docdb.DBClusterSnapshot +func findClusterSnapshots(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBClusterSnapshotsInput) ([]awstypes.DBClusterSnapshot, error) { + var output []awstypes.DBClusterSnapshot - err := conn.DescribeDBClusterSnapshotsPagesWithContext(ctx, input, func(page *docdb.DescribeDBClusterSnapshotsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBClusterSnapshotsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBClusterSnapshots { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.DBClusterSnapshotNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBClusterSnapshotNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.DBClusterSnapshots { + if !reflect.ValueOf(v).IsZero() { + output = append(output, v) + } + } } return output, nil } -func statusClusterSnapshot(ctx context.Context, conn *docdb.DocDB, id string) retry.StateRefreshFunc { +func statusClusterSnapshot(ctx context.Context, conn *docdb.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindClusterSnapshotByID(ctx, conn, id) + output, err := findClusterSnapshotByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -248,11 +247,11 @@ func statusClusterSnapshot(ctx context.Context, conn *docdb.DocDB, id string) re return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } -func waitClusterSnapshotCreated(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.DBClusterSnapshot, error) { +func waitClusterSnapshotCreated(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.DBClusterSnapshot, error) { stateConf := &retry.StateChangeConf{ Pending: []string{clusterSnapshotStatusCreating}, Target: []string{clusterSnapshotStatusAvailable}, @@ -264,7 +263,7 @@ func waitClusterSnapshotCreated(ctx context.Context, conn *docdb.DocDB, id strin outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.DBClusterSnapshot); ok { + if output, ok := outputRaw.(*awstypes.DBClusterSnapshot); ok { return output, err } diff --git a/internal/service/docdb/cluster_snapshot_test.go b/internal/service/docdb/cluster_snapshot_test.go index 4c21c913653..c9982d82e88 100644 --- a/internal/service/docdb/cluster_snapshot_test.go +++ b/internal/service/docdb/cluster_snapshot_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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" @@ -22,7 +22,7 @@ import ( func TestAccDocDBClusterSnapshot_basic(t *testing.T) { ctx := acctest.Context(t) - var dbClusterSnapshot docdb.DBClusterSnapshot + var dbClusterSnapshot awstypes.DBClusterSnapshot rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster_snapshot.test" @@ -60,7 +60,7 @@ func TestAccDocDBClusterSnapshot_basic(t *testing.T) { func TestAccDocDBClusterSnapshot_disappears(t *testing.T) { ctx := acctest.Context(t) - var dbClusterSnapshot docdb.DBClusterSnapshot + var dbClusterSnapshot awstypes.DBClusterSnapshot rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster_snapshot.test" @@ -84,7 +84,7 @@ func TestAccDocDBClusterSnapshot_disappears(t *testing.T) { func testAccCheckClusterSnapshotDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_cluster_snapshot" { @@ -108,14 +108,14 @@ func testAccCheckClusterSnapshotDestroy(ctx context.Context) resource.TestCheckF } } -func testAccCheckClusterSnapshotExists(ctx context.Context, n string, v *docdb.DBClusterSnapshot) resource.TestCheckFunc { +func testAccCheckClusterSnapshotExists(ctx context.Context, n string, v *awstypes.DBClusterSnapshot) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindClusterSnapshotByID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/docdb/cluster_test.go b/internal/service/docdb/cluster_test.go index ea3034e1c1c..9f4b2f2b941 100644 --- a/internal/service/docdb/cluster_test.go +++ b/internal/service/docdb/cluster_test.go @@ -10,8 +10,9 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -35,7 +36,7 @@ func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { func TestAccDocDBCluster_basic(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -103,7 +104,7 @@ func TestAccDocDBCluster_basic(t *testing.T) { func TestAccDocDBCluster_disappears(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -127,7 +128,7 @@ func TestAccDocDBCluster_disappears(t *testing.T) { func TestAccDocDBCluster_identifierGenerated(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster resourceName := "aws_docdb_cluster.test" resource.ParallelTest(t, resource.TestCase{ @@ -162,7 +163,7 @@ func TestAccDocDBCluster_identifierGenerated(t *testing.T) { func TestAccDocDBCluster_identifierPrefix(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster resourceName := "aws_docdb_cluster.test" resource.ParallelTest(t, resource.TestCase{ @@ -197,7 +198,7 @@ func TestAccDocDBCluster_identifierPrefix(t *testing.T) { func TestAccDocDBCluster_tags(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -250,7 +251,7 @@ func TestAccDocDBCluster_tags(t *testing.T) { func TestAccDocDBCluster_takeFinalSnapshot(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) snapshotName := fmt.Sprintf("%s-snapshot", rName) resourceName := "aws_docdb_cluster.test" @@ -305,7 +306,7 @@ func TestAccDocDBCluster_missingUserNameCausesError(t *testing.T) { func TestAccDocDBCluster_updateCloudWatchLogsExports(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -349,7 +350,7 @@ func TestAccDocDBCluster_updateCloudWatchLogsExports(t *testing.T) { func TestAccDocDBCluster_kmsKey(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -384,7 +385,7 @@ func TestAccDocDBCluster_kmsKey(t *testing.T) { func TestAccDocDBCluster_encrypted(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -419,7 +420,7 @@ func TestAccDocDBCluster_encrypted(t *testing.T) { func TestAccDocDBCluster_backupsUpdate(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBCluster + var v awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -465,7 +466,7 @@ func TestAccDocDBCluster_backupsUpdate(t *testing.T) { func TestAccDocDBCluster_port(t *testing.T) { ctx := acctest.Context(t) - var dbCluster1, dbCluster2 docdb.DBCluster + var dbCluster1, dbCluster2 awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -508,7 +509,7 @@ func TestAccDocDBCluster_port(t *testing.T) { func TestAccDocDBCluster_deleteProtection(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -564,7 +565,7 @@ func TestAccDocDBCluster_deleteProtection(t *testing.T) { func TestAccDocDBCluster_GlobalClusterIdentifier(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) globalClusterResourceName := "aws_docdb_cluster.test" resourceName := "aws_docdb_cluster.test" @@ -600,7 +601,7 @@ func TestAccDocDBCluster_GlobalClusterIdentifier(t *testing.T) { func TestAccDocDBCluster_GlobalClusterIdentifier_Add(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -643,7 +644,7 @@ func TestAccDocDBCluster_GlobalClusterIdentifier_Add(t *testing.T) { func TestAccDocDBCluster_GlobalClusterIdentifier_Remove(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) globalClusterResourceName := "aws_docdb_global_cluster.test" resourceName := "aws_docdb_cluster.test" @@ -686,7 +687,7 @@ func TestAccDocDBCluster_GlobalClusterIdentifier_Remove(t *testing.T) { func TestAccDocDBCluster_GlobalClusterIdentifier_Update(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) globalClusterResourceName1 := "aws_docdb_global_cluster.test.0" globalClusterResourceName2 := "aws_docdb_global_cluster.test.1" @@ -732,7 +733,7 @@ func TestAccDocDBCluster_GlobalClusterIdentifier_PrimarySecondaryClusters(t *tes ctx := acctest.Context(t) var providers []*schema.Provider - var primaryDbCluster, secondaryDbCluster docdb.DBCluster + var primaryDbCluster, secondaryDbCluster awstypes.DBCluster rNameGlobal := sdkacctest.RandomWithPrefix("tf-acc-test-global") rNamePrimary := sdkacctest.RandomWithPrefix("tf-acc-test-primary") rNameSecondary := sdkacctest.RandomWithPrefix("tf-acc-test-secondary") @@ -765,7 +766,7 @@ func TestAccDocDBCluster_updateEngineMajorVersion(t *testing.T) { acctest.Skip(t, "Amazon DocumentDB has identified an issue and is temporarily disallowing major version upgrades (MVU) in all regions.") ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -840,7 +841,7 @@ func TestAccDocDBCluster_updateEngineMajorVersion(t *testing.T) { func TestAccDocDBCluster_storageType(t *testing.T) { ctx := acctest.Context(t) - var dbCluster docdb.DBCluster + var dbCluster awstypes.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_cluster.test" @@ -889,7 +890,7 @@ func TestAccDocDBCluster_storageType(t *testing.T) { func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_cluster" { @@ -913,18 +914,18 @@ func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckClusterExists(ctx context.Context, n string, v *docdb.DBCluster) resource.TestCheckFunc { +func testAccCheckClusterExists(ctx context.Context, n string, v *awstypes.DBCluster) resource.TestCheckFunc { return testAccCheckClusterExistsProvider(ctx, n, v, func() *schema.Provider { return acctest.Provider }) } -func testAccCheckClusterExistsProvider(ctx context.Context, n string, v *docdb.DBCluster, providerF func() *schema.Provider) resource.TestCheckFunc { +func testAccCheckClusterExistsProvider(ctx context.Context, n string, v *awstypes.DBCluster, providerF func() *schema.Provider) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := providerF().Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := providerF().Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindDBClusterByID(ctx, conn, rs.Primary.ID) @@ -940,7 +941,7 @@ func testAccCheckClusterExistsProvider(ctx context.Context, n string, v *docdb.D func testAccCheckClusterDestroyWithFinalSnapshot(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_cluster" { @@ -948,7 +949,7 @@ func testAccCheckClusterDestroyWithFinalSnapshot(ctx context.Context) resource.T } finalSnapshotID := rs.Primary.Attributes[names.AttrFinalSnapshotIdentifier] - _, err := conn.DeleteDBClusterSnapshotWithContext(ctx, &docdb.DeleteDBClusterSnapshotInput{ + _, err := conn.DeleteDBClusterSnapshot(ctx, &docdb.DeleteDBClusterSnapshotInput{ DBClusterSnapshotIdentifier: aws.String(finalSnapshotID), }) @@ -973,9 +974,9 @@ func testAccCheckClusterDestroyWithFinalSnapshot(ctx context.Context) resource.T } } -func testAccCheckClusterRecreated(i, j *docdb.DBCluster) resource.TestCheckFunc { +func testAccCheckClusterRecreated(i, j *awstypes.DBCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.TimeValue(i.ClusterCreateTime).Equal(aws.TimeValue(j.ClusterCreateTime)) { + if aws.ToTime(i.ClusterCreateTime).Equal(aws.ToTime(j.ClusterCreateTime)) { return errors.New("DocumentDB Cluster was not recreated") } diff --git a/internal/service/docdb/engine_version_data_source.go b/internal/service/docdb/engine_version_data_source.go index 357bb6c2d4b..05398b1b883 100644 --- a/internal/service/docdb/engine_version_data_source.go +++ b/internal/service/docdb/engine_version_data_source.go @@ -6,8 +6,9 @@ package docdb import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "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" @@ -73,7 +74,7 @@ func DataSourceEngineVersion() *schema.Resource { func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) input := &docdb.DescribeDBEngineVersionsInput{} @@ -93,10 +94,10 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me } } - var engineVersion *docdb.DBEngineVersion + var engineVersion *awstypes.DBEngineVersion var err error if preferredVersions := flex.ExpandStringValueList(d.Get("preferred_versions").([]interface{})); len(preferredVersions) > 0 { - var engineVersions []*docdb.DBEngineVersion + var engineVersions []awstypes.DBEngineVersion engineVersions, err = findEngineVersions(ctx, conn, input) @@ -105,8 +106,9 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me // Return the first matching version. for _, preferredVersion := range preferredVersions { for _, v := range engineVersions { - if preferredVersion == aws.StringValue(v.EngineVersion) { - engineVersion = v + if preferredVersion == aws.ToString(v.EngineVersion) { + ev := &v + engineVersion = ev break PreferredVersionLoop } } @@ -124,14 +126,14 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("DocumentDB Engine Version", err)) } - d.SetId(aws.StringValue(engineVersion.EngineVersion)) + d.SetId(aws.ToString(engineVersion.EngineVersion)) d.Set(names.AttrEngine, engineVersion.Engine) d.Set("engine_description", engineVersion.DBEngineDescription) d.Set("exportable_log_types", engineVersion.ExportableLogTypes) d.Set("parameter_group_family", engineVersion.DBParameterGroupFamily) d.Set("supports_log_exports_to_cloudwatch", engineVersion.SupportsLogExportsToCloudwatchLogs) - d.Set("valid_upgrade_targets", tfslices.ApplyToAll(engineVersion.ValidUpgradeTarget, func(v *docdb.UpgradeTarget) string { - return aws.StringValue(v.EngineVersion) + d.Set("valid_upgrade_targets", tfslices.ApplyToAll(engineVersion.ValidUpgradeTarget, func(v awstypes.UpgradeTarget) string { + return aws.ToString(v.EngineVersion) })) d.Set(names.AttrVersion, engineVersion.EngineVersion) @@ -140,35 +142,28 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me return diags } -func findEngineVersion(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBEngineVersionsInput) (*docdb.DBEngineVersion, error) { +func findEngineVersion(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBEngineVersionsInput) (*awstypes.DBEngineVersion, error) { output, err := findEngineVersions(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findEngineVersions(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBEngineVersionsInput) ([]*docdb.DBEngineVersion, error) { - var output []*docdb.DBEngineVersion +func findEngineVersions(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBEngineVersionsInput) ([]awstypes.DBEngineVersion, error) { + var output []awstypes.DBEngineVersion - err := conn.DescribeDBEngineVersionsPagesWithContext(ctx, input, func(page *docdb.DescribeDBEngineVersionsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBEngineVersionsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBEngineVersions { - if v != nil { - output = append(output, v) - } + if err != nil { + return nil, err } - return !lastPage - }) - - if err != nil { - return nil, err + output = append(output, page.DBEngineVersions...) } return output, nil diff --git a/internal/service/docdb/engine_version_data_source_test.go b/internal/service/docdb/engine_version_data_source_test.go index 71bc4b15733..b4a10aaef8b 100644 --- a/internal/service/docdb/engine_version_data_source_test.go +++ b/internal/service/docdb/engine_version_data_source_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -84,14 +84,14 @@ func TestAccDocDBEngineVersionDataSource_defaultOnly(t *testing.T) { } func testAccEngineVersionPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) input := &docdb.DescribeDBEngineVersionsInput{ Engine: aws.String("docdb"), DefaultOnly: aws.Bool(true), } - _, err := conn.DescribeDBEngineVersionsWithContext(ctx, input) + _, err := conn.DescribeDBEngineVersions(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) diff --git a/internal/service/docdb/event_subscription.go b/internal/service/docdb/event_subscription.go index e1883fe2208..e385154793b 100644 --- a/internal/service/docdb/event_subscription.go +++ b/internal/service/docdb/event_subscription.go @@ -6,16 +6,18 @@ package docdb import ( "context" "log" + "reflect" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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/create" + "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" @@ -103,7 +105,7 @@ func ResourceEventSubscription() *schema.Resource { func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &docdb.CreateEventSubscriptionInput{ @@ -114,24 +116,24 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData } if v, ok := d.GetOk("event_categories"); ok && v.(*schema.Set).Len() > 0 { - input.EventCategories = flex.ExpandStringSet(v.(*schema.Set)) + input.EventCategories = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("source_ids"); ok && v.(*schema.Set).Len() > 0 { - input.SourceIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SourceIds = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk(names.AttrSourceType); ok { input.SourceType = aws.String(v.(string)) } - output, err := conn.CreateEventSubscriptionWithContext(ctx, input) + output, err := conn.CreateEventSubscription(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating DocumentDB Event Subscription (%s): %s", name, err) } - d.SetId(aws.StringValue(output.EventSubscription.CustSubscriptionId)) + d.SetId(aws.ToString(output.EventSubscription.CustSubscriptionId)) if _, err := waitEventSubscriptionCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for DocumentDB Event Subscription (%s) create: %s", d.Id(), err) @@ -143,9 +145,9 @@ func resourceEventSubscriptionCreate(ctx context.Context, d *schema.ResourceData func resourceEventSubscriptionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - output, err := FindEventSubscriptionByName(ctx, conn, d.Id()) + output, err := findEventSubscriptionByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Event Subscription (%s) not found, removing from state", d.Id()) @@ -160,11 +162,11 @@ func resourceEventSubscriptionRead(ctx context.Context, d *schema.ResourceData, d.Set(names.AttrARN, output.EventSubscriptionArn) d.Set("customer_aws_id", output.CustomerAwsId) d.Set(names.AttrEnabled, output.Enabled) - d.Set("event_categories", aws.StringValueSlice(output.EventCategoriesList)) + d.Set("event_categories", output.EventCategoriesList) d.Set(names.AttrName, output.CustSubscriptionId) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(output.CustSubscriptionId))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(output.CustSubscriptionId))) d.Set(names.AttrSNSTopicARN, output.SnsTopicArn) - d.Set("source_ids", aws.StringValueSlice(output.SourceIdsList)) + d.Set("source_ids", output.SourceIdsList) d.Set(names.AttrSourceType, output.SourceType) return diags @@ -173,7 +175,7 @@ func resourceEventSubscriptionRead(ctx context.Context, d *schema.ResourceData, func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll, "source_ids") { input := &docdb.ModifyEventSubscriptionInput{ @@ -185,7 +187,7 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData } if d.HasChange("event_categories") { - input.EventCategories = flex.ExpandStringSet(d.Get("event_categories").(*schema.Set)) + input.EventCategories = flex.ExpandStringValueSet(d.Get("event_categories").(*schema.Set)) input.SourceType = aws.String(d.Get(names.AttrSourceType).(string)) } @@ -197,7 +199,7 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData input.SourceType = aws.String(d.Get(names.AttrSourceType).(string)) } - _, err := conn.ModifyEventSubscriptionWithContext(ctx, input) + _, err := conn.ModifyEventSubscription(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating DocumentDB Event Subscription (%s): %s", d.Id(), err) @@ -219,13 +221,13 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData os := o.(*schema.Set) ns := n.(*schema.Set) - remove := flex.ExpandStringSet(os.Difference(ns)) - add := flex.ExpandStringSet(ns.Difference(os)) + remove := flex.ExpandStringValueSet(os.Difference(ns)) + add := flex.ExpandStringValueSet(ns.Difference(os)) if len(remove) > 0 { for _, v := range remove { - _, err := conn.RemoveSourceIdentifierFromSubscriptionWithContext(ctx, &docdb.RemoveSourceIdentifierFromSubscriptionInput{ - SourceIdentifier: v, + _, err := conn.RemoveSourceIdentifierFromSubscription(ctx, &docdb.RemoveSourceIdentifierFromSubscriptionInput{ + SourceIdentifier: aws.String(v), SubscriptionName: aws.String(d.Id()), }) @@ -237,8 +239,8 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData if len(add) > 0 { for _, v := range add { - _, err := conn.AddSourceIdentifierToSubscriptionWithContext(ctx, &docdb.AddSourceIdentifierToSubscriptionInput{ - SourceIdentifier: v, + _, err := conn.AddSourceIdentifierToSubscription(ctx, &docdb.AddSourceIdentifierToSubscriptionInput{ + SourceIdentifier: aws.String(v), SubscriptionName: aws.String(d.Id()), }) @@ -255,14 +257,14 @@ func resourceEventSubscriptionUpdate(ctx context.Context, d *schema.ResourceData func resourceEventSubscriptionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) log.Printf("[DEBUG] Deleting DocumentDB Event Subscription: %s", d.Id()) - _, err := conn.DeleteEventSubscriptionWithContext(ctx, &docdb.DeleteEventSubscriptionInput{ + _, err := conn.DeleteEventSubscription(ctx, &docdb.DeleteEventSubscriptionInput{ SubscriptionName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeSubscriptionNotFoundFault) { + if errs.IsA[*awstypes.SubscriptionNotFoundFault](err) { return diags } @@ -277,7 +279,7 @@ func resourceEventSubscriptionDelete(ctx context.Context, d *schema.ResourceData return diags } -func FindEventSubscriptionByName(ctx context.Context, conn *docdb.DocDB, name string) (*docdb.EventSubscription, error) { +func findEventSubscriptionByName(ctx context.Context, conn *docdb.Client, name string) (*awstypes.EventSubscription, error) { input := &docdb.DescribeEventSubscriptionsInput{ SubscriptionName: aws.String(name), } @@ -288,7 +290,7 @@ func FindEventSubscriptionByName(ctx context.Context, conn *docdb.DocDB, name st } // Eventual consistency check. - if aws.StringValue(output.CustSubscriptionId) != name { + if aws.ToString(output.CustSubscriptionId) != name { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -297,50 +299,47 @@ func FindEventSubscriptionByName(ctx context.Context, conn *docdb.DocDB, name st return output, nil } -func findEventSubscription(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeEventSubscriptionsInput) (*docdb.EventSubscription, error) { +func findEventSubscription(ctx context.Context, conn *docdb.Client, input *docdb.DescribeEventSubscriptionsInput) (*awstypes.EventSubscription, error) { output, err := findEventSubscriptions(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findEventSubscriptions(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeEventSubscriptionsInput) ([]*docdb.EventSubscription, error) { - var output []*docdb.EventSubscription +func findEventSubscriptions(ctx context.Context, conn *docdb.Client, input *docdb.DescribeEventSubscriptionsInput) ([]awstypes.EventSubscription, error) { + var output []awstypes.EventSubscription - err := conn.DescribeEventSubscriptionsPagesWithContext(ctx, input, func(page *docdb.DescribeEventSubscriptionsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeEventSubscriptionsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.EventSubscriptionsList { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.SubscriptionNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastRequest: input, + LastError: err, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeSubscriptionNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.EventSubscriptionsList { + if !reflect.ValueOf(v).IsZero() { + output = append(output, v) + } + } } return output, nil } -func statusEventSubscription(ctx context.Context, conn *docdb.DocDB, name string) retry.StateRefreshFunc { +func statusEventSubscription(ctx context.Context, conn *docdb.Client, name string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindEventSubscriptionByName(ctx, conn, name) + output, err := findEventSubscriptionByName(ctx, conn, name) if tfresource.NotFound(err) { return nil, "", nil @@ -350,11 +349,11 @@ func statusEventSubscription(ctx context.Context, conn *docdb.DocDB, name string return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } -func waitEventSubscriptionCreated(ctx context.Context, conn *docdb.DocDB, name string, timeout time.Duration) (*docdb.EventSubscription, error) { +func waitEventSubscriptionCreated(ctx context.Context, conn *docdb.Client, name string, timeout time.Duration) (*awstypes.EventSubscription, error) { stateConf := &retry.StateChangeConf{ Pending: []string{eventSubscriptionStatusCreating}, Target: []string{eventSubscriptionStatusActive}, @@ -366,14 +365,14 @@ func waitEventSubscriptionCreated(ctx context.Context, conn *docdb.DocDB, name s outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.EventSubscription); ok { + if output, ok := outputRaw.(*awstypes.EventSubscription); ok { return output, err } return nil, err } -func waitEventSubscriptionUpdated(ctx context.Context, conn *docdb.DocDB, name string, timeout time.Duration) (*docdb.EventSubscription, error) { +func waitEventSubscriptionUpdated(ctx context.Context, conn *docdb.Client, name string, timeout time.Duration) (*awstypes.EventSubscription, error) { stateConf := &retry.StateChangeConf{ Pending: []string{eventSubscriptionStatusModifying}, Target: []string{eventSubscriptionStatusActive}, @@ -385,14 +384,14 @@ func waitEventSubscriptionUpdated(ctx context.Context, conn *docdb.DocDB, name s outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.EventSubscription); ok { + if output, ok := outputRaw.(*awstypes.EventSubscription); ok { return output, err } return nil, err } -func waitEventSubscriptionDeleted(ctx context.Context, conn *docdb.DocDB, name string, timeout time.Duration) (*docdb.EventSubscription, error) { +func waitEventSubscriptionDeleted(ctx context.Context, conn *docdb.Client, name string, timeout time.Duration) (*awstypes.EventSubscription, error) { stateConf := &retry.StateChangeConf{ Pending: []string{eventSubscriptionStatusDeleting}, Target: []string{}, @@ -404,7 +403,7 @@ func waitEventSubscriptionDeleted(ctx context.Context, conn *docdb.DocDB, name s outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.EventSubscription); ok { + if output, ok := outputRaw.(*awstypes.EventSubscription); ok { return output, err } diff --git a/internal/service/docdb/event_subscription_test.go b/internal/service/docdb/event_subscription_test.go index ace481774a0..a6531d8df26 100644 --- a/internal/service/docdb/event_subscription_test.go +++ b/internal/service/docdb/event_subscription_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -22,7 +22,7 @@ import ( func TestAccDocDBEventSubscription_basic(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription resourceName := "aws_docdb_event_subscription.test" snsTopicResourceName := "aws_sns_topic.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -59,7 +59,7 @@ func TestAccDocDBEventSubscription_basic(t *testing.T) { func TestAccDocDBEventSubscription_nameGenerated(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription resourceName := "aws_docdb_event_subscription.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -88,7 +88,7 @@ func TestAccDocDBEventSubscription_nameGenerated(t *testing.T) { func TestAccDocDBEventSubscription_disappears(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription resourceName := "aws_docdb_event_subscription.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -112,7 +112,7 @@ func TestAccDocDBEventSubscription_disappears(t *testing.T) { func TestAccDocDBEventSubscription_enabled(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription resourceName := "aws_docdb_event_subscription.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -154,7 +154,7 @@ func TestAccDocDBEventSubscription_enabled(t *testing.T) { func TestAccDocDBEventSubscription_eventCategories(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription resourceName := "aws_docdb_event_subscription.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -193,7 +193,7 @@ func TestAccDocDBEventSubscription_eventCategories(t *testing.T) { func TestAccDocDBEventSubscription_tags(t *testing.T) { ctx := acctest.Context(t) - var eventSubscription docdb.EventSubscription + var eventSubscription awstypes.EventSubscription rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_event_subscription.test" @@ -244,7 +244,7 @@ func testAccCheckEventSubscriptionDestroy(ctx context.Context) resource.TestChec continue } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) _, err := tfdocdb.FindEventSubscriptionByName(ctx, conn, rs.Primary.ID) @@ -263,7 +263,7 @@ func testAccCheckEventSubscriptionDestroy(ctx context.Context) resource.TestChec } } -func testAccCheckEventSubscriptionExists(ctx context.Context, n string, eventSubscription *docdb.EventSubscription) resource.TestCheckFunc { +func testAccCheckEventSubscriptionExists(ctx context.Context, n string, eventSubscription *awstypes.EventSubscription) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -274,7 +274,7 @@ func testAccCheckEventSubscriptionExists(ctx context.Context, n string, eventSub return fmt.Errorf("No DocumentDB Event Subscription ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) res, err := tfdocdb.FindEventSubscriptionByName(ctx, conn, rs.Primary.ID) diff --git a/internal/service/docdb/exports_test.go b/internal/service/docdb/exports_test.go new file mode 100644 index 00000000000..61384712903 --- /dev/null +++ b/internal/service/docdb/exports_test.go @@ -0,0 +1,15 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package docdb + +// Exports for use in tests only. +var ( + FindDBClusterByID = findDBClusterByID + FindDBClusterParameterGroupByName = findDBClusterParameterGroupByName + FindDBSubnetGroupByName = findDBSubnetGroupByName + FindClusterSnapshotByID = findClusterSnapshotByID + FindDBInstanceByID = findDBInstanceByID + FindEventSubscriptionByName = findEventSubscriptionByName + FindGlobalClusterByID = findGlobalClusterByID +) diff --git a/internal/service/docdb/flex.go b/internal/service/docdb/flex.go index 9ecc4c2a155..bcebbddbeed 100644 --- a/internal/service/docdb/flex.go +++ b/internal/service/docdb/flex.go @@ -7,24 +7,24 @@ import ( "fmt" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-provider-aws/names" ) // Takes the result of flatmap.Expand for an array of parameters and // returns Parameter API compatible objects -func expandParameters(configured []interface{}) []*docdb.Parameter { - parameters := make([]*docdb.Parameter, 0, len(configured)) +func expandParameters(configured []interface{}) []awstypes.Parameter { + parameters := make([]awstypes.Parameter, 0, len(configured)) // Loop over our configured parameters and create // an array of aws-sdk-go compatible objects for _, pRaw := range configured { data := pRaw.(map[string]interface{}) - p := &docdb.Parameter{ - ApplyMethod: aws.String(data["apply_method"].(string)), + p := awstypes.Parameter{ + ApplyMethod: awstypes.ApplyMethod(data["apply_method"].(string)), ParameterName: aws.String(data[names.AttrName].(string)), ParameterValue: aws.String(data[names.AttrValue].(string)), } @@ -36,11 +36,11 @@ func expandParameters(configured []interface{}) []*docdb.Parameter { } // Flattens an array of Parameters into a []map[string]interface{} -func flattenParameters(list []*docdb.Parameter, parameterList []interface{}) []map[string]interface{} { +func flattenParameters(list []awstypes.Parameter, parameterList []interface{}) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { if i.ParameterValue != nil { - name := aws.StringValue(i.ParameterName) + name := aws.ToString(i.ParameterName) // Check if any non-user parameters are specified in the configuration. parameterFound := false @@ -51,14 +51,14 @@ func flattenParameters(list []*docdb.Parameter, parameterList []interface{}) []m } // Skip parameters that are not user defined or specified in the configuration. - if aws.StringValue(i.Source) != "user" && !parameterFound { + if aws.ToString(i.Source) != "user" && !parameterFound { continue } result = append(result, map[string]interface{}{ - "apply_method": aws.StringValue(i.ApplyMethod), - names.AttrName: aws.StringValue(i.ParameterName), - names.AttrValue: aws.StringValue(i.ParameterValue), + "apply_method": string(i.ApplyMethod), + names.AttrName: aws.ToString(i.ParameterName), + names.AttrValue: aws.ToString(i.ParameterValue), }) } } diff --git a/internal/service/docdb/generate.go b/internal/service/docdb/generate.go index 6820d934fa4..8ac3a22f0ba 100644 --- a/internal/service/docdb/generate.go +++ b/internal/service/docdb/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsInIDElem=ResourceName -ListTagsOutTagsElem=TagList -ServiceTagsSlice -TagOp=AddTagsToResource -TagInIDElem=ResourceName -UntagOp=RemoveTagsFromResource -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsInIDElem=ResourceName -ListTagsOutTagsElem=TagList -ServiceTagsSlice -TagOp=AddTagsToResource -TagInIDElem=ResourceName -UntagOp=RemoveTagsFromResource -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/docdb/global_cluster.go b/internal/service/docdb/global_cluster.go index 1aa4e47fead..bfcc0bbbed4 100644 --- a/internal/service/docdb/global_cluster.go +++ b/internal/service/docdb/global_cluster.go @@ -6,17 +6,19 @@ package docdb import ( "context" "log" + "reflect" "slices" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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-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" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -121,7 +123,7 @@ func ResourceGlobalCluster() *schema.Resource { func resourceGlobalClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) globalClusterID := d.Get("global_cluster_identifier").(string) input := &docdb.CreateGlobalClusterInput{ @@ -152,13 +154,13 @@ func resourceGlobalClusterCreate(ctx context.Context, d *schema.ResourceData, me input.StorageEncrypted = aws.Bool(v.(bool)) } - output, err := conn.CreateGlobalClusterWithContext(ctx, input) + output, err := conn.CreateGlobalCluster(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating DocumentDB Global Cluster (%s): %s", globalClusterID, err) } - d.SetId(aws.StringValue(output.GlobalCluster.GlobalClusterIdentifier)) + d.SetId(aws.ToString(output.GlobalCluster.GlobalClusterIdentifier)) if _, err := waitGlobalClusterCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for DocumentDB Global Cluster (%s) create: %s", d.Id(), err) @@ -170,9 +172,9 @@ func resourceGlobalClusterCreate(ctx context.Context, d *schema.ResourceData, me func resourceGlobalClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - globalCluster, err := FindGlobalClusterByID(ctx, conn, d.Id()) + globalCluster, err := findGlobalClusterByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Global Cluster (%s) not found, removing from state", d.Id()) @@ -202,7 +204,7 @@ func resourceGlobalClusterRead(ctx context.Context, d *schema.ResourceData, meta func resourceGlobalClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChange(names.AttrDeletionProtection) { input := &docdb.ModifyGlobalClusterInput{ @@ -210,9 +212,9 @@ func resourceGlobalClusterUpdate(ctx context.Context, d *schema.ResourceData, me GlobalClusterIdentifier: aws.String(d.Id()), } - _, err := conn.ModifyGlobalClusterWithContext(ctx, input) + _, err := conn.ModifyGlobalCluster(ctx, input) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeGlobalClusterNotFoundFault) { + if errs.IsA[*awstypes.GlobalClusterNotFoundFault](err) { return diags } @@ -242,7 +244,7 @@ func resourceGlobalClusterUpdate(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading DocumentDB Cluster (%s): %s", clusterARN, err) } - clusterID := aws.StringValue(cluster.DBClusterIdentifier) + clusterID := aws.ToString(cluster.DBClusterIdentifier) input := &docdb.ModifyDBClusterInput{ ApplyImmediately: aws.Bool(true), DBClusterIdentifier: aws.String(clusterID), @@ -250,7 +252,7 @@ func resourceGlobalClusterUpdate(ctx context.Context, d *schema.ResourceData, me } _, err = tfresource.RetryWhenAWSErrMessageContains(ctx, propagationTimeout, func() (interface{}, error) { - return conn.ModifyDBClusterWithContext(ctx, input) + return conn.ModifyDBCluster(ctx, input) }, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") if err != nil { @@ -270,7 +272,7 @@ func resourceGlobalClusterUpdate(ctx context.Context, d *schema.ResourceData, me func resourceGlobalClusterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) // Remove any members from the global cluster. for _, tfMapRaw := range d.Get("global_cluster_members").(*schema.Set).List() { @@ -288,13 +290,14 @@ func resourceGlobalClusterDelete(ctx context.Context, d *schema.ResourceData, me } log.Printf("[DEBUG] Deleting DocumentDB Global Cluster: %s", d.Id()) - _, err := tfresource.RetryWhenAWSErrMessageContains(ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { - return conn.DeleteGlobalClusterWithContext(ctx, &docdb.DeleteGlobalClusterInput{ + + _, err := tfresource.RetryWhenIsAErrorMessageContains[*awstypes.InvalidGlobalClusterStateFault](ctx, d.Timeout(schema.TimeoutDelete), func() (interface{}, error) { + return conn.DeleteGlobalCluster(ctx, &docdb.DeleteGlobalClusterInput{ GlobalClusterIdentifier: aws.String(d.Id()), }) - }, docdb.ErrCodeInvalidGlobalClusterStateFault, "is not empty") + }, "is not empty") - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeGlobalClusterNotFoundFault) { + if errs.IsA[*awstypes.GlobalClusterNotFoundFault](err) { return diags } @@ -309,17 +312,17 @@ func resourceGlobalClusterDelete(ctx context.Context, d *schema.ResourceData, me return diags } -func FindGlobalClusterByID(ctx context.Context, conn *docdb.DocDB, id string) (*docdb.GlobalCluster, error) { +func findGlobalClusterByID(ctx context.Context, conn *docdb.Client, id string) (*awstypes.GlobalCluster, error) { input := &docdb.DescribeGlobalClustersInput{ GlobalClusterIdentifier: aws.String(id), } - output, err := findGlobalCluster(ctx, conn, input, tfslices.PredicateTrue[*docdb.GlobalCluster]()) + output, err := findGlobalCluster(ctx, conn, input, tfslices.PredicateTrue[awstypes.GlobalCluster]()) if err != nil { return nil, err } - if status := aws.StringValue(output.Status); status == globalClusterStatusDeleted { + if status := aws.ToString(output.Status); status == globalClusterStatusDeleted { return nil, &retry.NotFoundError{ Message: status, LastRequest: input, @@ -327,7 +330,7 @@ func FindGlobalClusterByID(ctx context.Context, conn *docdb.DocDB, id string) (* } // Eventual consistency check. - if aws.StringValue(output.GlobalClusterIdentifier) != id { + if aws.ToString(output.GlobalClusterIdentifier) != id { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -336,60 +339,56 @@ func FindGlobalClusterByID(ctx context.Context, conn *docdb.DocDB, id string) (* return output, nil } -func findGlobalClusterByClusterARN(ctx context.Context, conn *docdb.DocDB, arn string) (*docdb.GlobalCluster, error) { +func findGlobalClusterByClusterARN(ctx context.Context, conn *docdb.Client, arn string) (*awstypes.GlobalCluster, error) { input := &docdb.DescribeGlobalClustersInput{} - return findGlobalCluster(ctx, conn, input, func(v *docdb.GlobalCluster) bool { - return slices.ContainsFunc(v.GlobalClusterMembers, func(v *docdb.GlobalClusterMember) bool { - return aws.StringValue(v.DBClusterArn) == arn + return findGlobalCluster(ctx, conn, input, func(v awstypes.GlobalCluster) bool { + return slices.ContainsFunc(v.GlobalClusterMembers, func(v awstypes.GlobalClusterMember) bool { + return aws.ToString(v.DBClusterArn) == arn }) }) } -func findGlobalCluster(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[*docdb.GlobalCluster]) (*docdb.GlobalCluster, error) { +func findGlobalCluster(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[awstypes.GlobalCluster]) (*awstypes.GlobalCluster, error) { output, err := findGlobalClusters(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findGlobalClusters(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[*docdb.GlobalCluster]) ([]*docdb.GlobalCluster, error) { - var output []*docdb.GlobalCluster +func findGlobalClusters(ctx context.Context, conn *docdb.Client, input *docdb.DescribeGlobalClustersInput, filter tfslices.Predicate[awstypes.GlobalCluster]) ([]awstypes.GlobalCluster, error) { + var output []awstypes.GlobalCluster + + pages := docdb.NewDescribeGlobalClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - err := conn.DescribeGlobalClustersPagesWithContext(ctx, input, func(page *docdb.DescribeGlobalClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + if errs.IsA[*awstypes.GlobalClusterNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + if err != nil { + return nil, err } for _, v := range page.GlobalClusters { - if v != nil && filter(v) { + if !reflect.ValueOf(v).IsZero() && filter(v) { output = append(output, v) } } - - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeGlobalClusterNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err } return output, nil } -func statusGlobalCluster(ctx context.Context, conn *docdb.DocDB, id string) retry.StateRefreshFunc { +func statusGlobalCluster(ctx context.Context, conn *docdb.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindGlobalClusterByID(ctx, conn, id) + output, err := findGlobalClusterByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -399,11 +398,11 @@ func statusGlobalCluster(ctx context.Context, conn *docdb.DocDB, id string) retr return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } -func waitGlobalClusterCreated(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.GlobalCluster, error) { +func waitGlobalClusterCreated(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.GlobalCluster, error) { stateConf := &retry.StateChangeConf{ Pending: []string{globalClusterStatusCreating}, Target: []string{globalClusterStatusAvailable}, @@ -413,14 +412,14 @@ func waitGlobalClusterCreated(ctx context.Context, conn *docdb.DocDB, id string, outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.GlobalCluster); ok { + if output, ok := outputRaw.(*awstypes.GlobalCluster); ok { return output, err } return nil, err } -func waitGlobalClusterUpdated(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.GlobalCluster, error) { +func waitGlobalClusterUpdated(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.GlobalCluster, error) { stateConf := &retry.StateChangeConf{ Pending: []string{globalClusterStatusModifying, globalClusterStatusUpgrading}, Target: []string{globalClusterStatusAvailable}, @@ -431,14 +430,14 @@ func waitGlobalClusterUpdated(ctx context.Context, conn *docdb.DocDB, id string, outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.GlobalCluster); ok { + if output, ok := outputRaw.(*awstypes.GlobalCluster); ok { return output, err } return nil, err } -func waitGlobalClusterDeleted(ctx context.Context, conn *docdb.DocDB, id string, timeout time.Duration) (*docdb.GlobalCluster, error) { +func waitGlobalClusterDeleted(ctx context.Context, conn *docdb.Client, id string, timeout time.Duration) (*awstypes.GlobalCluster, error) { stateConf := &retry.StateChangeConf{ Pending: []string{globalClusterStatusAvailable, globalClusterStatusDeleting}, Target: []string{}, @@ -449,14 +448,14 @@ func waitGlobalClusterDeleted(ctx context.Context, conn *docdb.DocDB, id string, outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*docdb.GlobalCluster); ok { + if output, ok := outputRaw.(*awstypes.GlobalCluster); ok { return output, err } return nil, err } -func flattenGlobalClusterMembers(apiObjects []*docdb.GlobalClusterMember) []interface{} { +func flattenGlobalClusterMembers(apiObjects []awstypes.GlobalClusterMember) []interface{} { if len(apiObjects) == 0 { return nil } @@ -465,8 +464,8 @@ func flattenGlobalClusterMembers(apiObjects []*docdb.GlobalClusterMember) []inte for _, apiObject := range apiObjects { tfMap := map[string]interface{}{ - "db_cluster_arn": aws.StringValue(apiObject.DBClusterArn), - "is_writer": aws.BoolValue(apiObject.IsWriter), + "db_cluster_arn": aws.ToString(apiObject.DBClusterArn), + "is_writer": aws.ToBool(apiObject.IsWriter), } tfList = append(tfList, tfMap) diff --git a/internal/service/docdb/global_cluster_test.go b/internal/service/docdb/global_cluster_test.go index 96c31126ef3..2901a389d5f 100644 --- a/internal/service/docdb/global_cluster_test.go +++ b/internal/service/docdb/global_cluster_test.go @@ -10,9 +10,10 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" + "github.com/hashicorp/aws-sdk-go-base/v2/tfawserr" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -25,7 +26,7 @@ import ( func TestAccDocDBGlobalCluster_basic(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -61,7 +62,7 @@ func TestAccDocDBGlobalCluster_basic(t *testing.T) { func TestAccDocDBGlobalCluster_disappears(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -85,7 +86,7 @@ func TestAccDocDBGlobalCluster_disappears(t *testing.T) { func TestAccDocDBGlobalCluster_DatabaseName(t *testing.T) { ctx := acctest.Context(t) - var globalCluster1, globalCluster2 docdb.GlobalCluster + var globalCluster1, globalCluster2 awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -121,7 +122,7 @@ func TestAccDocDBGlobalCluster_DatabaseName(t *testing.T) { func TestAccDocDBGlobalCluster_DeletionProtection(t *testing.T) { ctx := acctest.Context(t) - var globalCluster1, globalCluster2 docdb.GlobalCluster + var globalCluster1, globalCluster2 awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -157,7 +158,7 @@ func TestAccDocDBGlobalCluster_DeletionProtection(t *testing.T) { func TestAccDocDBGlobalCluster_Engine(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -185,7 +186,7 @@ func TestAccDocDBGlobalCluster_Engine(t *testing.T) { func TestAccDocDBGlobalCluster_EngineVersion(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -213,7 +214,7 @@ func TestAccDocDBGlobalCluster_EngineVersion(t *testing.T) { func TestAccDocDBGlobalCluster_SourceDBClusterIdentifier_basic(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName := "aws_docdb_cluster.test" resourceName := "aws_docdb_global_cluster.test" @@ -243,7 +244,7 @@ func TestAccDocDBGlobalCluster_SourceDBClusterIdentifier_basic(t *testing.T) { func TestAccDocDBGlobalCluster_SourceDBClusterIdentifier_storageEncrypted(t *testing.T) { ctx := acctest.Context(t) - var globalCluster docdb.GlobalCluster + var globalCluster awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName := "aws_docdb_cluster.test" resourceName := "aws_docdb_global_cluster.test" @@ -273,7 +274,7 @@ func TestAccDocDBGlobalCluster_SourceDBClusterIdentifier_storageEncrypted(t *tes func TestAccDocDBGlobalCluster_StorageEncrypted(t *testing.T) { ctx := acctest.Context(t) - var globalCluster1, globalCluster2 docdb.GlobalCluster + var globalCluster1, globalCluster2 awstypes.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_docdb_global_cluster.test" @@ -307,14 +308,14 @@ func TestAccDocDBGlobalCluster_StorageEncrypted(t *testing.T) { }) } -func testAccCheckGlobalClusterExists(ctx context.Context, n string, v *docdb.GlobalCluster) resource.TestCheckFunc { +func testAccCheckGlobalClusterExists(ctx context.Context, n string, v *awstypes.GlobalCluster) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindGlobalClusterByID(ctx, conn, rs.Primary.ID) @@ -330,7 +331,7 @@ func testAccCheckGlobalClusterExists(ctx context.Context, n string, v *docdb.Glo func testAccCheckGlobalClusterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_global_cluster" { @@ -354,19 +355,19 @@ func testAccCheckGlobalClusterDestroy(ctx context.Context) resource.TestCheckFun } } -func testAccCheckGlobalClusterNotRecreated(i, j *docdb.GlobalCluster) resource.TestCheckFunc { +func testAccCheckGlobalClusterNotRecreated(i, j *awstypes.GlobalCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.StringValue(i.GlobalClusterArn) != aws.StringValue(j.GlobalClusterArn) { - return fmt.Errorf("DocumentDB Global Cluster was recreated. got: %s, expected: %s", aws.StringValue(i.GlobalClusterArn), aws.StringValue(j.GlobalClusterArn)) + if aws.ToString(i.GlobalClusterArn) != aws.ToString(j.GlobalClusterArn) { + return fmt.Errorf("DocumentDB Global Cluster was recreated. got: %s, expected: %s", aws.ToString(i.GlobalClusterArn), aws.ToString(j.GlobalClusterArn)) } return nil } } -func testAccCheckGlobalClusterRecreated(i, j *docdb.GlobalCluster) resource.TestCheckFunc { +func testAccCheckGlobalClusterRecreated(i, j *awstypes.GlobalCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.StringValue(i.GlobalClusterResourceId) == aws.StringValue(j.GlobalClusterResourceId) { + if aws.ToString(i.GlobalClusterResourceId) == aws.ToString(j.GlobalClusterResourceId) { return errors.New("DocumentDB Global Cluster was not recreated") } @@ -375,11 +376,11 @@ func testAccCheckGlobalClusterRecreated(i, j *docdb.GlobalCluster) resource.Test } func testAccPreCheckGlobalCluster(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) input := &docdb.DescribeGlobalClustersInput{} - _, err := conn.DescribeGlobalClustersWithContext(ctx, input) + _, err := conn.DescribeGlobalClusters(ctx, input) if acctest.PreCheckSkipError(err) || tfawserr.ErrMessageContains(err, "InvalidParameterValue", "Access Denied to API Version: APIGlobalDatabases") { // Current Region/Partition does not support DocumentDB Global Clusters diff --git a/internal/service/docdb/orderable_db_instance_data_source.go b/internal/service/docdb/orderable_db_instance_data_source.go index 1f46839cabb..422ddc62918 100644 --- a/internal/service/docdb/orderable_db_instance_data_source.go +++ b/internal/service/docdb/orderable_db_instance_data_source.go @@ -5,9 +5,11 @@ package docdb import ( "context" + "reflect" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "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" @@ -66,7 +68,7 @@ func DataSourceOrderableDBInstance() *schema.Resource { func dataSourceOrderableDBInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) input := &docdb.DescribeOrderableDBInstanceOptionsInput{} @@ -90,18 +92,19 @@ func dataSourceOrderableDBInstanceRead(ctx context.Context, d *schema.ResourceDa input.Vpc = aws.Bool(v.(bool)) } - var orderableDBInstance *docdb.OrderableDBInstanceOption + var orderableDBInstance *awstypes.OrderableDBInstanceOption var err error if preferredInstanceClasses := flex.ExpandStringValueList(d.Get("preferred_instance_classes").([]interface{})); len(preferredInstanceClasses) > 0 { - var orderableDBInstances []*docdb.OrderableDBInstanceOption + var orderableDBInstances []awstypes.OrderableDBInstanceOption orderableDBInstances, err = findOrderableDBInstances(ctx, conn, input) if err == nil { PreferredInstanceClassLoop: for _, preferredInstanceClass := range preferredInstanceClasses { for _, v := range orderableDBInstances { - if preferredInstanceClass == aws.StringValue(v.DBInstanceClass) { - orderableDBInstance = v + if preferredInstanceClass == aws.ToString(v.DBInstanceClass) { + oi := &v + orderableDBInstance = oi break PreferredInstanceClassLoop } } @@ -119,9 +122,9 @@ func dataSourceOrderableDBInstanceRead(ctx context.Context, d *schema.ResourceDa return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("DocumentDB Orderable DB Instance", err)) } - d.SetId(aws.StringValue(orderableDBInstance.DBInstanceClass)) - d.Set(names.AttrAvailabilityZones, tfslices.ApplyToAll(orderableDBInstance.AvailabilityZones, func(v *docdb.AvailabilityZone) string { - return aws.StringValue(v.Name) + d.SetId(aws.ToString(orderableDBInstance.DBInstanceClass)) + d.Set(names.AttrAvailabilityZones, tfslices.ApplyToAll(orderableDBInstance.AvailabilityZones, func(v awstypes.AvailabilityZone) string { + return aws.ToString(v.Name) })) d.Set(names.AttrEngine, orderableDBInstance.Engine) d.Set(names.AttrEngineVersion, orderableDBInstance.EngineVersion) @@ -132,35 +135,31 @@ func dataSourceOrderableDBInstanceRead(ctx context.Context, d *schema.ResourceDa return diags } -func findOrderableDBInstance(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeOrderableDBInstanceOptionsInput) (*docdb.OrderableDBInstanceOption, error) { +func findOrderableDBInstance(ctx context.Context, conn *docdb.Client, input *docdb.DescribeOrderableDBInstanceOptionsInput) (*awstypes.OrderableDBInstanceOption, error) { output, err := findOrderableDBInstances(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findOrderableDBInstances(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeOrderableDBInstanceOptionsInput) ([]*docdb.OrderableDBInstanceOption, error) { - var output []*docdb.OrderableDBInstanceOption +func findOrderableDBInstances(ctx context.Context, conn *docdb.Client, input *docdb.DescribeOrderableDBInstanceOptionsInput) ([]awstypes.OrderableDBInstanceOption, error) { + var output []awstypes.OrderableDBInstanceOption - err := conn.DescribeOrderableDBInstanceOptionsPagesWithContext(ctx, input, func(page *docdb.DescribeOrderableDBInstanceOptionsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeOrderableDBInstanceOptionsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + return nil, err } for _, v := range page.OrderableDBInstanceOptions { - if v != nil { + if !reflect.ValueOf(v).IsZero() { output = append(output, v) } } - - return !lastPage - }) - - if err != nil { - return nil, err } return output, nil diff --git a/internal/service/docdb/orderable_db_instance_data_source_test.go b/internal/service/docdb/orderable_db_instance_data_source_test.go index c3902cce980..db364ccadea 100644 --- a/internal/service/docdb/orderable_db_instance_data_source_test.go +++ b/internal/service/docdb/orderable_db_instance_data_source_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -69,13 +69,13 @@ func TestAccDocDBOrderableDBInstanceDataSource_preferred(t *testing.T) { } func testAccPreCheckOrderableDBInstance(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) input := &docdb.DescribeOrderableDBInstanceOptionsInput{ Engine: aws.String("docdb"), } - _, err := conn.DescribeOrderableDBInstanceOptionsWithContext(ctx, input) + _, err := conn.DescribeOrderableDBInstanceOptions(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) diff --git a/internal/service/docdb/service_endpoints_gen_test.go b/internal/service/docdb/service_endpoints_gen_test.go index c4d304a0349..5c1b1b68949 100644 --- a/internal/service/docdb/service_endpoints_gen_test.go +++ b/internal/service/docdb/service_endpoints_gen_test.go @@ -4,17 +4,20 @@ package docdb_test import ( "context" + "errors" "fmt" "maps" - "net/url" "os" "path/filepath" + "reflect" "strings" "testing" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - docdb_sdkv1 "github.com/aws/aws-sdk-go/service/docdb" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + docdb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdb" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -239,54 +242,63 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := docdb_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(docdb_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), docdb_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func defaultFIPSEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := docdb_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(docdb_sdkv1.EndpointsID, region, func(opt *endpoints.Options) { - opt.UseFIPSEndpoint = endpoints.FIPSEndpointStateEnabled + ep, err := r.ResolveEndpoint(context.Background(), docdb_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + UseFIPS: aws_sdkv2.Bool(true), }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() - client := meta.DocDBConn(ctx) + client := meta.DocDBClient(ctx) - req, _ := client.DescribeDBClustersRequest(&docdb_sdkv1.DescribeDBClustersInput{}) + var result apiCallParams - req.HTTPRequest.URL.Path = "/" - - return apiCallParams{ - endpoint: req.HTTPRequest.URL.String(), - region: aws_sdkv1.StringValue(client.Config.Region), + _, err := client.DescribeDBClusters(ctx, &docdb_sdkv2.DescribeDBClustersInput{}, + func(opts *docdb_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &result.endpoint), + addRetrieveRegionMiddleware(&result.region), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) } + + return result } func withNoConfig(_ *caseSetup) { @@ -443,6 +455,89 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } } +func addRetrieveEndpointURLMiddleware(t *testing.T, endpoint *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + retrieveEndpointURLMiddleware(t, endpoint), + middleware.After, + ) + } +} + +func retrieveEndpointURLMiddleware(t *testing.T, endpoint *string) middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Retrieve Endpoint", + func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + t.Helper() + + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + t.Fatalf("Expected *github.com/aws/smithy-go/transport/http.Request, got %s", fullTypeName(in.Request)) + } + + url := request.URL + url.RawQuery = "" + url.Path = "/" + + *endpoint = url.String() + + return next.HandleFinalize(ctx, in) + }) +} + +func addRetrieveRegionMiddleware(region *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Serialize.Add( + retrieveRegionMiddleware(region), + middleware.After, + ) + } +} + +func retrieveRegionMiddleware(region *string) middleware.SerializeMiddleware { + return middleware.SerializeMiddlewareFunc( + "Test: Retrieve Region", + func(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (middleware.SerializeOutput, middleware.Metadata, error) { + *region = awsmiddleware.GetRegion(ctx) + + return next.HandleSerialize(ctx, in) + }, + ) +} + +var errCancelOperation = fmt.Errorf("Test: Canceling request") + +func addCancelRequestMiddleware() func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + cancelRequestMiddleware(), + middleware.After, + ) + } +} + +// cancelRequestMiddleware creates a Smithy middleware that intercepts the request before sending and cancels it +func cancelRequestMiddleware() middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Cancel Requests", + func(_ context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + return middleware.FinalizeOutput{}, middleware.Metadata{}, errCancelOperation + }) +} + +func fullTypeName(i interface{}) string { + return fullValueTypeName(reflect.ValueOf(i)) +} + +func fullValueTypeName(v reflect.Value) string { + if v.Kind() == reflect.Ptr { + return "*" + fullValueTypeName(reflect.Indirect(v)) + } + + requestType := v.Type() + return fmt.Sprintf("%s.%s", requestType.PkgPath(), requestType.Name()) +} + func generateSharedConfigFile(config configFile) string { var buf strings.Builder diff --git a/internal/service/docdb/service_package_gen.go b/internal/service/docdb/service_package_gen.go index 5589e145625..d06fe85387c 100644 --- a/internal/service/docdb/service_package_gen.go +++ b/internal/service/docdb/service_package_gen.go @@ -5,10 +5,8 @@ package docdb import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - docdb_sdkv1 "github.com/aws/aws-sdk-go/service/docdb" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + docdb_sdkv2 "github.com/aws/aws-sdk-go-v2/service/docdb" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" @@ -95,25 +93,23 @@ func (p *servicePackage) ServicePackageName() string { return names.DocDB } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*docdb_sdkv1.DocDB, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*docdb_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - cfg := aws_sdkv1.Config{} + return docdb_sdkv2.NewFromConfig(cfg, func(o *docdb_sdkv2.Options) { + if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { + tflog.Debug(ctx, "setting endpoint", map[string]any{ + "tf_aws.endpoint": endpoint, + }) + o.BaseEndpoint = aws_sdkv2.String(endpoint) - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { - tflog.Debug(ctx, "setting endpoint", map[string]any{ - "tf_aws.endpoint": endpoint, - }) - cfg.Endpoint = aws_sdkv1.String(endpoint) - - if sess.Config.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled { - tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") - cfg.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled + if o.EndpointOptions.UseFIPSEndpoint == aws_sdkv2.FIPSEndpointStateEnabled { + tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") + o.EndpointOptions.UseFIPSEndpoint = aws_sdkv2.FIPSEndpointStateDisabled + } } - } - - return docdb_sdkv1.New(sess.Copy(&cfg)), nil + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/docdb/subnet_group.go b/internal/service/docdb/subnet_group.go index 333fe4befa8..70a69db303f 100644 --- a/internal/service/docdb/subnet_group.go +++ b/internal/service/docdb/subnet_group.go @@ -8,14 +8,15 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "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/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/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/create" + "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" @@ -79,17 +80,17 @@ func ResourceSubnetGroup() *schema.Resource { func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) name := create.Name(d.Get(names.AttrName).(string), d.Get(names.AttrNamePrefix).(string)) input := &docdb.CreateDBSubnetGroupInput{ DBSubnetGroupDescription: aws.String(d.Get(names.AttrDescription).(string)), DBSubnetGroupName: aws.String(name), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), Tags: getTagsIn(ctx), } - _, err := conn.CreateDBSubnetGroupWithContext(ctx, input) + _, err := conn.CreateDBSubnetGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating DocumentDB Subnet Group (%s): %s", name, err) @@ -102,9 +103,9 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) - subnetGroup, err := FindDBSubnetGroupByName(ctx, conn, d.Id()) + subnetGroup, err := findDBSubnetGroupByName(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] DocumentDB Subnet Group (%s) not found, removing from state", d.Id()) @@ -119,10 +120,10 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrARN, subnetGroup.DBSubnetGroupArn) d.Set(names.AttrDescription, subnetGroup.DBSubnetGroupDescription) d.Set(names.AttrName, subnetGroup.DBSubnetGroupName) - d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.StringValue(subnetGroup.DBSubnetGroupName))) + d.Set(names.AttrNamePrefix, create.NamePrefixFromName(aws.ToString(subnetGroup.DBSubnetGroupName))) var subnetIDs []string for _, v := range subnetGroup.Subnets { - subnetIDs = append(subnetIDs, aws.StringValue(v.SubnetIdentifier)) + subnetIDs = append(subnetIDs, aws.ToString(v.SubnetIdentifier)) } d.Set(names.AttrSubnetIDs, subnetIDs) @@ -131,16 +132,16 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) if d.HasChanges(names.AttrDescription, names.AttrSubnetIDs) { input := &docdb.ModifyDBSubnetGroupInput{ DBSubnetGroupName: aws.String(d.Id()), DBSubnetGroupDescription: aws.String(d.Get(names.AttrDescription).(string)), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), } - _, err := conn.ModifyDBSubnetGroupWithContext(ctx, input) + _, err := conn.ModifyDBSubnetGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying DocumentDB Subnet Group (%s): %s", d.Id(), err) @@ -152,14 +153,14 @@ func resourceSubnetGroupUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceSubnetGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).DocDBConn(ctx) + conn := meta.(*conns.AWSClient).DocDBClient(ctx) log.Printf("[DEBUG] Deleting DocumentDB Subnet Group: %s", d.Id()) - _, err := conn.DeleteDBSubnetGroupWithContext(ctx, &docdb.DeleteDBSubnetGroupInput{ + _, err := conn.DeleteDBSubnetGroup(ctx, &docdb.DeleteDBSubnetGroupInput{ DBSubnetGroupName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBSubnetGroupNotFoundFault) { + if errs.IsA[*awstypes.DBSubnetGroupNotFoundFault](err) { return diags } @@ -168,7 +169,7 @@ func resourceSubnetGroupDelete(ctx context.Context, d *schema.ResourceData, meta } _, err = tfresource.RetryUntilNotFound(ctx, 10*time.Minute, func() (interface{}, error) { - return FindDBSubnetGroupByName(ctx, conn, d.Id()) + return findDBSubnetGroupByName(ctx, conn, d.Id()) }) if err != nil { @@ -178,7 +179,7 @@ func resourceSubnetGroupDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func FindDBSubnetGroupByName(ctx context.Context, conn *docdb.DocDB, name string) (*docdb.DBSubnetGroup, error) { +func findDBSubnetGroupByName(ctx context.Context, conn *docdb.Client, name string) (*awstypes.DBSubnetGroup, error) { input := &docdb.DescribeDBSubnetGroupsInput{ DBSubnetGroupName: aws.String(name), } @@ -189,7 +190,7 @@ func FindDBSubnetGroupByName(ctx context.Context, conn *docdb.DocDB, name string } // Eventual consistency check. - if aws.StringValue(output.DBSubnetGroupName) != name { + if aws.ToString(output.DBSubnetGroupName) != name { return nil, &retry.NotFoundError{ LastRequest: input, } @@ -198,42 +199,35 @@ func FindDBSubnetGroupByName(ctx context.Context, conn *docdb.DocDB, name string return output, nil } -func findDBSubnetGroup(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBSubnetGroupsInput) (*docdb.DBSubnetGroup, error) { +func findDBSubnetGroup(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBSubnetGroupsInput) (*awstypes.DBSubnetGroup, error) { output, err := findDBSubnetGroups(ctx, conn, input) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findDBSubnetGroups(ctx context.Context, conn *docdb.DocDB, input *docdb.DescribeDBSubnetGroupsInput) ([]*docdb.DBSubnetGroup, error) { - var output []*docdb.DBSubnetGroup +func findDBSubnetGroups(ctx context.Context, conn *docdb.Client, input *docdb.DescribeDBSubnetGroupsInput) ([]awstypes.DBSubnetGroup, error) { + var output []awstypes.DBSubnetGroup - err := conn.DescribeDBSubnetGroupsPagesWithContext(ctx, input, func(page *docdb.DescribeDBSubnetGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := docdb.NewDescribeDBSubnetGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) - for _, v := range page.DBSubnetGroups { - if v != nil { - output = append(output, v) + if errs.IsA[*awstypes.DBSubnetGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, docdb.ErrCodeDBSubnetGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + output = append(output, page.DBSubnetGroups...) } return output, nil diff --git a/internal/service/docdb/subnet_group_test.go b/internal/service/docdb/subnet_group_test.go index e0cc6436d70..fde51c2b35d 100644 --- a/internal/service/docdb/subnet_group_test.go +++ b/internal/service/docdb/subnet_group_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -22,7 +22,7 @@ import ( func TestAccDocDBSubnetGroup_basic(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -54,7 +54,7 @@ func TestAccDocDBSubnetGroup_basic(t *testing.T) { func TestAccDocDBSubnetGroup_disappears(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -78,7 +78,7 @@ func TestAccDocDBSubnetGroup_disappears(t *testing.T) { func TestAccDocDBSubnetGroup_nameGenerated(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -107,7 +107,7 @@ func TestAccDocDBSubnetGroup_nameGenerated(t *testing.T) { func TestAccDocDBSubnetGroup_namePrefix(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -136,7 +136,7 @@ func TestAccDocDBSubnetGroup_namePrefix(t *testing.T) { func TestAccDocDBSubnetGroup_updateDescription(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -171,7 +171,7 @@ func TestAccDocDBSubnetGroup_updateDescription(t *testing.T) { func TestAccDocDBSubnetGroup_updateSubnets(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -206,7 +206,7 @@ func TestAccDocDBSubnetGroup_updateSubnets(t *testing.T) { func TestAccDocDBSubnetGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var v docdb.DBSubnetGroup + var v awstypes.DBSubnetGroup resourceName := "aws_docdb_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -252,7 +252,7 @@ func TestAccDocDBSubnetGroup_tags(t *testing.T) { func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_docdb_subnet_group" { @@ -276,14 +276,14 @@ func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc } } -func testAccCheckSubnetGroupExists(ctx context.Context, n string, v *docdb.DBSubnetGroup) resource.TestCheckFunc { +func testAccCheckSubnetGroupExists(ctx context.Context, n string, v *awstypes.DBSubnetGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBClient(ctx) output, err := tfdocdb.FindDBSubnetGroupByName(ctx, conn, rs.Primary.ID) diff --git a/internal/service/docdb/sweep.go b/internal/service/docdb/sweep.go index 3d7c5baf3bb..e3988c2058b 100644 --- a/internal/service/docdb/sweep.go +++ b/internal/service/docdb/sweep.go @@ -8,11 +8,11 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" - "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) @@ -74,18 +74,26 @@ func sweepClusters(region string) error { if err != nil { return fmt.Errorf("error getting client: %d", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeDBClustersInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeDBClustersPagesWithContext(ctx, input, func(page *docdb.DescribeDBClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeDBClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Cluster sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing DocumentDB Clusters for %s: %s", region, err) } for _, v := range page.DBClusters { - arn := aws.StringValue(v.DBClusterArn) - id := aws.StringValue(v.DBClusterIdentifier) + arn := aws.ToString(v.DBClusterArn) + id := aws.ToString(v.DBClusterIdentifier) r := ResourceCluster() d := r.Data(nil) @@ -105,17 +113,6 @@ func sweepClusters(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Cluster sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing DocumentDB Clusters (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -133,33 +130,30 @@ func sweepClusterSnapshots(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeDBClusterSnapshotsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeDBClusterSnapshotsPagesWithContext(ctx, input, func(page *docdb.DescribeDBClusterSnapshotsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeDBClusterSnapshotsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Cluster Snapshot sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing DocumentDB Cluster Snapshots (%s): %w", region, err) } for _, v := range page.DBClusterSnapshots { r := ResourceClusterSnapshot() d := r.Data(nil) - d.SetId(aws.StringValue(v.DBClusterSnapshotIdentifier)) + d.SetId(aws.ToString(v.DBClusterSnapshotIdentifier)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Cluster Snapshot sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing DocumentDB Cluster Snapshots (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -177,17 +171,25 @@ func sweepClusterParameterGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeDBClusterParameterGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeDBClusterParameterGroupsPagesWithContext(ctx, input, func(page *docdb.DescribeDBClusterParameterGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeDBClusterParameterGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Cluster Parameter Group sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing DocumentDB Cluster Parameter Groups (%s): %s", region, err) } for _, v := range page.DBClusterParameterGroups { - name := aws.StringValue(v.DBClusterParameterGroupName) + name := aws.ToString(v.DBClusterParameterGroupName) if strings.HasPrefix(name, "default.") { log.Printf("[INFO] Skipping DocumentDB Cluster Parameter Group: %s", name) @@ -200,17 +202,6 @@ func sweepClusterParameterGroups(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Cluster Parameter Group sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing DocumentDB Cluster Parameter Groups (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -228,33 +219,30 @@ func sweepClusterInstances(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeDBInstancesInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeDBInstancesPagesWithContext(ctx, input, func(page *docdb.DescribeDBInstancesOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeDBInstancesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Cluster Instance sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing DocumentDB Cluster Instances (%s): %w", region, err) } for _, v := range page.DBInstances { r := ResourceClusterInstance() d := r.Data(nil) - d.SetId(aws.StringValue(v.DBInstanceIdentifier)) + d.SetId(aws.ToString(v.DBInstanceIdentifier)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Cluster Instance sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing DocumentDB Cluster Instances (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -272,33 +260,30 @@ func sweepGlobalClusters(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeGlobalClustersInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeGlobalClustersPagesWithContext(ctx, input, func(page *docdb.DescribeGlobalClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeGlobalClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Global Cluster sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing DocumentDB Global Clusters (%s): %w", region, err) } for _, v := range page.GlobalClusters { r := ResourceGlobalCluster() d := r.Data(nil) - d.SetId(aws.StringValue(v.GlobalClusterIdentifier)) + d.SetId(aws.ToString(v.GlobalClusterIdentifier)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Global Cluster sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing DocumentDB Global Clusters (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -316,33 +301,30 @@ func sweepSubnetGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeDBSubnetGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeDBSubnetGroupsPagesWithContext(ctx, input, func(page *docdb.DescribeDBSubnetGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeDBSubnetGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Subnet Group sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing DocumentDB Subnet Groups (%s): %w", region, err) } for _, v := range page.DBSubnetGroups { r := ResourceSubnetGroup() d := r.Data(nil) - d.SetId(aws.StringValue(v.DBSubnetGroupName)) + d.SetId(aws.ToString(v.DBSubnetGroupName)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Subnet Group sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing DocumentDB Subnet Groups (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -360,33 +342,30 @@ func sweepEventSubscriptions(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.DocDBConn(ctx) + conn := client.DocDBClient(ctx) input := &docdb.DescribeEventSubscriptionsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeEventSubscriptionsPagesWithContext(ctx, input, func(page *docdb.DescribeEventSubscriptionsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := docdb.NewDescribeEventSubscriptionsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping DocumentDB Event Subscription sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing DocumentDB Event Subscriptions (%s): %w", region, err) } for _, v := range page.EventSubscriptionsList { r := ResourceEventSubscription() d := r.Data(nil) - d.SetId(aws.StringValue(v.CustSubscriptionId)) + d.SetId(aws.ToString(v.CustSubscriptionId)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping DocumentDB Event Subscription sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing DocumentDB Event Subscriptions (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) diff --git a/internal/service/docdb/tags_gen.go b/internal/service/docdb/tags_gen.go index 3e538b3f872..abba3d23090 100644 --- a/internal/service/docdb/tags_gen.go +++ b/internal/service/docdb/tags_gen.go @@ -5,9 +5,9 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/docdb" - "github.com/aws/aws-sdk-go/service/docdb/docdbiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/docdb" + awstypes "github.com/aws/aws-sdk-go-v2/service/docdb/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +19,12 @@ import ( // listTags lists docdb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *docdb.Client, identifier string, optFns ...func(*docdb.Options)) (tftags.KeyValueTags, error) { input := &docdb.ListTagsForResourceInput{ ResourceName: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +36,7 @@ func listTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string) // ListTags lists docdb service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).DocDBConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).DocDBClient(ctx), identifier) if err != nil { return err @@ -52,11 +52,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // Tags returns docdb service tags. -func Tags(tags tftags.KeyValueTags) []*docdb.Tag { - result := make([]*docdb.Tag, 0, len(tags)) +func Tags(tags tftags.KeyValueTags) []awstypes.Tag { + result := make([]awstypes.Tag, 0, len(tags)) for k, v := range tags.Map() { - tag := &docdb.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -68,11 +68,11 @@ func Tags(tags tftags.KeyValueTags) []*docdb.Tag { } // KeyValueTags creates tftags.KeyValueTags from docdb service tags. -func KeyValueTags(ctx context.Context, tags []*docdb.Tag) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { m := make(map[string]*string, len(tags)) for _, tag := range tags { - m[aws.StringValue(tag.Key)] = tag.Value + m[aws.ToString(tag.Key)] = tag.Value } return tftags.New(ctx, m) @@ -80,7 +80,7 @@ func KeyValueTags(ctx context.Context, tags []*docdb.Tag) tftags.KeyValueTags { // getTagsIn returns docdb service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*docdb.Tag { +func getTagsIn(ctx context.Context) []awstypes.Tag { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -91,7 +91,7 @@ func getTagsIn(ctx context.Context) []*docdb.Tag { } // setTagsOut sets docdb service tags in Context. -func setTagsOut(ctx context.Context, tags []*docdb.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -100,7 +100,7 @@ func setTagsOut(ctx context.Context, tags []*docdb.Tag) { // updateTags updates docdb service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *docdb.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*docdb.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -111,10 +111,10 @@ func updateTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string if len(removedTags) > 0 { input := &docdb.RemoveTagsFromResourceInput{ ResourceName: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.RemoveTagsFromResourceWithContext(ctx, input) + _, err := conn.RemoveTagsFromResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -129,7 +129,7 @@ func updateTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string Tags: Tags(updatedTags), } - _, err := conn.AddTagsToResourceWithContext(ctx, input) + _, err := conn.AddTagsToResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -142,5 +142,5 @@ func updateTags(ctx context.Context, conn docdbiface.DocDBAPI, identifier string // UpdateTags updates docdb service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).DocDBConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).DocDBClient(ctx), identifier, oldTags, newTags) } diff --git a/names/data/names_data.csv b/names/data/names_data.csv index 0d829250c8c..7d040897135 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -122,7 +122,7 @@ devops-guru,devopsguru,devopsguru,devopsguru,,devopsguru,,,DevOpsGuru,DevOpsGuru directconnect,directconnect,directconnect,directconnect,,directconnect,,,DirectConnect,DirectConnect,,1,,aws_dx_,aws_directconnect_,,dx_,Direct Connect,AWS,,,,,,,Direct Connect,DescribeConnections,,, dlm,dlm,dlm,dlm,,dlm,,,DLM,DLM,,,2,,aws_dlm_,,dlm_,DLM (Data Lifecycle Manager),Amazon,,,,,,,DLM,GetLifecyclePolicies,,, dms,dms,databasemigrationservice,databasemigrationservice,,dms,,databasemigration;databasemigrationservice,DMS,DatabaseMigrationService,,1,,,aws_dms_,,dms_,DMS (Database Migration),AWS,,,,,,,Database Migration Service,DescribeCertificates,,, -docdb,docdb,docdb,docdb,,docdb,,,DocDB,DocDB,,1,,,aws_docdb_,,docdb_,DocumentDB,Amazon,,,,,,,DocDB,DescribeDBClusters,,, +docdb,docdb,docdb,docdb,,docdb,,,DocDB,DocDB,,,2,,aws_docdb_,,docdb_,DocumentDB,Amazon,,,,,,,DocDB,DescribeDBClusters,,, docdb-elastic,docdbelastic,docdbelastic,docdbelastic,,docdbelastic,,,DocDBElastic,DocDBElastic,,,2,,aws_docdbelastic_,,docdbelastic_,DocumentDB Elastic,Amazon,,,,,,,DocDB Elastic,ListClusters,,, drs,drs,drs,drs,,drs,,,DRS,Drs,,,2,,aws_drs_,,drs_,DRS (Elastic Disaster Recovery),AWS,,,,,,,DRS,DescribeJobs,,, ds,ds,directoryservice,directoryservice,,ds,,directoryservice,DS,DirectoryService,,1,2,aws_directory_service_,aws_ds_,,directory_service_,Directory Service,AWS,,,,,,,Directory Service,DescribeDirectories,,,