diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 0f9837eb7eb..8d392e0f0ba 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -211,7 +211,6 @@ import ( directconnect_sdkv1 "github.com/aws/aws-sdk-go/service/directconnect" ec2_sdkv1 "github.com/aws/aws-sdk-go/service/ec2" ecs_sdkv1 "github.com/aws/aws-sdk-go/service/ecs" - elasticache_sdkv1 "github.com/aws/aws-sdk-go/service/elasticache" elasticsearchservice_sdkv1 "github.com/aws/aws-sdk-go/service/elasticsearchservice" elastictranscoder_sdkv1 "github.com/aws/aws-sdk-go/service/elastictranscoder" emr_sdkv1 "github.com/aws/aws-sdk-go/service/emr" @@ -644,10 +643,6 @@ func (c *AWSClient) EMRServerlessClient(ctx context.Context) *emrserverless_sdkv return errs.Must(client[*emrserverless_sdkv2.Client](ctx, c, names.EMRServerless, make(map[string]any))) } -func (c *AWSClient) ElastiCacheConn(ctx context.Context) *elasticache_sdkv1.ElastiCache { - return errs.Must(conn[*elasticache_sdkv1.ElastiCache](ctx, c, names.ElastiCache, make(map[string]any))) -} - func (c *AWSClient) ElastiCacheClient(ctx context.Context) *elasticache_sdkv2.Client { return errs.Must(client[*elasticache_sdkv2.Client](ctx, c, names.ElastiCache, make(map[string]any))) } diff --git a/internal/service/elasticache/cluster.go b/internal/service/elasticache/cluster.go index 36abbeab6e0..b373ff903a2 100644 --- a/internal/service/elasticache/cluster.go +++ b/internal/service/elasticache/cluster.go @@ -14,15 +14,16 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "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" "github.com/hashicorp/terraform-provider-aws/internal/flex" @@ -75,10 +76,10 @@ func resourceCluster() *schema.Resource { ForceNew: true, }, "az_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(elasticache.AZMode_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.AZMode](), }, "cache_nodes": { Type: schema.TypeList, @@ -156,10 +157,10 @@ func resourceCluster() *schema.Resource { Optional: true, }, "ip_discovery": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(elasticache.IpDiscovery_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.IpDiscovery](), }, "log_delivery_configuration": { Type: schema.TypeSet, @@ -172,19 +173,19 @@ func resourceCluster() *schema.Resource { Required: true, }, "destination_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.DestinationType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.DestinationType](), }, "log_format": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogFormat_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogFormat](), }, "log_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogType](), }, }, }, @@ -201,11 +202,11 @@ func resourceCluster() *schema.Resource { ValidateFunc: verify.ValidOnceAWeekWindowFormat, }, "network_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(elasticache.NetworkType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.NetworkType](), }, "node_type": { Type: schema.TypeString, @@ -222,11 +223,11 @@ func resourceCluster() *schema.Resource { Computed: true, }, "outpost_mode": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - RequiredWith: []string{"preferred_outpost_arn"}, - ValidateFunc: validation.StringInSlice(elasticache.OutpostMode_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + RequiredWith: []string{"preferred_outpost_arn"}, + ValidateDiagFunc: enum.Validate[awstypes.OutpostMode](), }, names.AttrParameterGroupName: { Type: schema.TypeString, @@ -347,7 +348,8 @@ func resourceCluster() *schema.Resource { func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition clusterID := d.Get("cluster_id").(string) input := &elasticache.CreateCacheClusterInput{ @@ -358,7 +360,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int if v, ok := d.GetOk("replication_group_id"); ok { input.ReplicationGroupId = aws.String(v.(string)) } else { - input.SecurityGroupIds = flex.ExpandStringSet(d.Get(names.AttrSecurityGroupIDs).(*schema.Set)) + input.SecurityGroupIds = flex.ExpandStringValueSet(d.Get(names.AttrSecurityGroupIDs).(*schema.Set)) } if v, ok := d.GetOk("node_type"); ok { @@ -366,11 +368,11 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("num_cache_nodes"); ok { - input.NumCacheNodes = aws.Int64(int64(v.(int))) + input.NumCacheNodes = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("outpost_mode"); ok { - input.OutpostMode = aws.String(v.(string)) + input.OutpostMode = awstypes.OutpostMode(v.(string)) } if v, ok := d.GetOk("preferred_outpost_arn"); ok { @@ -393,7 +395,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("subnet_group_name"); ok { @@ -406,7 +408,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("snapshot_retention_limit"); ok { - input.SnapshotRetentionLimit = aws.Int64(int64(v.(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("snapshot_window"); ok { @@ -414,11 +416,9 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("log_delivery_configuration"); ok { - input.LogDeliveryConfigurations = []*elasticache.LogDeliveryConfigurationRequest{} - v := v.(*schema.Set).List() - for _, v := range v { - logDeliveryConfigurationRequest := expandLogDeliveryConfigurations(v.(map[string]interface{})) - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &logDeliveryConfigurationRequest) + input.LogDeliveryConfigurations = []awstypes.LogDeliveryConfigurationRequest{} + for _, v := range v.(*schema.Set).List() { + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, expandLogDeliveryConfigurationRequests(v.(map[string]interface{}))) } } @@ -430,10 +430,9 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int input.NotificationTopicArn = aws.String(v.(string)) } - snaps := d.Get("snapshot_arns").([]interface{}) - if len(snaps) > 0 { - input.SnapshotArns = flex.ExpandStringList(snaps) - log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", snaps) + if v := d.Get("snapshot_arns").([]interface{}); len(v) > 0 { + input.SnapshotArns = flex.ExpandStringValueList(v) + log.Printf("[DEBUG] Restoring Redis cluster from S3 snapshot: %#v", v) } if v, ok := d.GetOk("snapshot_name"); ok { @@ -445,7 +444,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("az_mode"); ok { - input.AZMode = aws.String(v.(string)) + input.AZMode = awstypes.AZMode(v.(string)) } if v, ok := d.GetOk(names.AttrAvailabilityZone); ok { @@ -453,18 +452,18 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("preferred_availability_zones"); ok && len(v.([]interface{})) > 0 { - input.PreferredAvailabilityZones = flex.ExpandStringList(v.([]interface{})) + input.PreferredAvailabilityZones = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := d.GetOk("ip_discovery"); ok { - input.IpDiscovery = aws.String(v.(string)) + input.IpDiscovery = awstypes.IpDiscovery(v.(string)) } if v, ok := d.GetOk("network_type"); ok { - input.NetworkType = aws.String(v.(string)) + input.NetworkType = awstypes.NetworkType(v.(string)) } - id, arn, err := createCacheCluster(ctx, conn, input) + id, arn, err := createCacheCluster(ctx, conn, partition, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache Cache Cluster (%s): %s", clusterID, err) @@ -484,7 +483,7 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int err := createTags(ctx, conn, arn, tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceClusterRead(ctx, d, meta)...) } @@ -498,7 +497,7 @@ 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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) c, err := findCacheClusterWithNodeInfoByID(ctx, conn, d.Id()) @@ -515,7 +514,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("cluster_id", c.CacheClusterId) if err := setFromCacheCluster(d, c); err != nil { - return sdkdiag.AppendErrorf(diags, "reading ElastiCache Cache Cluster (%s): %s", d.Id(), err) + return sdkdiag.AppendFromErr(diags, err) } d.Set("log_delivery_configuration", flattenLogDeliveryConfigurations(c.LogDeliveryConfigurations)) @@ -526,7 +525,7 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter if c.ConfigurationEndpoint != nil { d.Set(names.AttrPort, c.ConfigurationEndpoint.Port) - d.Set("configuration_endpoint", aws.String(fmt.Sprintf("%s:%d", aws.StringValue(c.ConfigurationEndpoint.Address), aws.Int64Value(c.ConfigurationEndpoint.Port)))) + d.Set("configuration_endpoint", aws.String(fmt.Sprintf("%s:%d", aws.ToString(c.ConfigurationEndpoint.Address), aws.ToInt32(c.ConfigurationEndpoint.Port)))) d.Set("cluster_address", c.ConfigurationEndpoint.Address) } else if len(c.CacheNodes) > 0 { d.Set(names.AttrPort, c.CacheNodes[0].Endpoint.Port) @@ -535,19 +534,19 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("replication_group_id", c.ReplicationGroupId) if c.NotificationConfiguration != nil { - if aws.StringValue(c.NotificationConfiguration.TopicStatus) == "active" { + if aws.ToString(c.NotificationConfiguration.TopicStatus) == "active" { d.Set("notification_topic_arn", c.NotificationConfiguration.TopicArn) } } d.Set(names.AttrAvailabilityZone, c.PreferredAvailabilityZone) - if aws.StringValue(c.PreferredAvailabilityZone) == "Multiple" { + if aws.ToString(c.PreferredAvailabilityZone) == "Multiple" { d.Set("az_mode", "cross-az") } else { d.Set("az_mode", "single-az") } if err := setCacheNodeData(d, c); err != nil { - return sdkdiag.AppendErrorf(diags, "reading ElastiCache Cache Cluster (%s): %s", d.Id(), err) + return sdkdiag.AppendFromErr(diags, err) } d.Set(names.AttrARN, c.ARN) @@ -562,7 +561,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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &elasticache.ModifyCacheClusterInput{ @@ -573,7 +572,7 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int requestUpdate := false if d.HasChange(names.AttrSecurityGroupIDs) { if attr := d.Get(names.AttrSecurityGroupIDs).(*schema.Set); attr.Len() > 0 { - input.SecurityGroupIds = flex.ExpandStringSet(attr) + input.SecurityGroupIds = flex.ExpandStringValueSet(attr) requestUpdate = true } } @@ -584,29 +583,29 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChange("ip_discovery") { - input.IpDiscovery = aws.String(d.Get("ip_discovery").(string)) + input.IpDiscovery = awstypes.IpDiscovery(d.Get("ip_discovery").(string)) requestUpdate = true } if d.HasChange("log_delivery_configuration") { oldLogDeliveryConfig, newLogDeliveryConfig := d.GetChange("log_delivery_configuration") - input.LogDeliveryConfigurations = []*elasticache.LogDeliveryConfigurationRequest{} + input.LogDeliveryConfigurations = []awstypes.LogDeliveryConfigurationRequest{} logTypesToSubmit := make(map[string]bool) currentLogDeliveryConfig := newLogDeliveryConfig.(*schema.Set).List() for _, current := range currentLogDeliveryConfig { - logDeliveryConfigurationRequest := expandLogDeliveryConfigurations(current.(map[string]interface{})) - logTypesToSubmit[*logDeliveryConfigurationRequest.LogType] = true - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &logDeliveryConfigurationRequest) + logDeliveryConfigurationRequest := expandLogDeliveryConfigurationRequests(current.(map[string]interface{})) + logTypesToSubmit[string(logDeliveryConfigurationRequest.LogType)] = true + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, logDeliveryConfigurationRequest) } previousLogDeliveryConfig := oldLogDeliveryConfig.(*schema.Set).List() for _, previous := range previousLogDeliveryConfig { - logDeliveryConfigurationRequest := expandEmptyLogDeliveryConfigurations(previous.(map[string]interface{})) + logDeliveryConfigurationRequest := expandEmptyLogDeliveryConfigurationRequest(previous.(map[string]interface{})) // if something was removed, send an empty request - if !logTypesToSubmit[*logDeliveryConfigurationRequest.LogType] { - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &logDeliveryConfigurationRequest) + if !logTypesToSubmit[string(logDeliveryConfigurationRequest.LogType)] { + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, logDeliveryConfigurationRequest) } } @@ -652,12 +651,12 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChange("snapshot_retention_limit") { - input.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(d.Get("snapshot_retention_limit").(int))) requestUpdate = true } if d.HasChange("az_mode") { - input.AZMode = aws.String(d.Get("az_mode").(string)) + input.AZMode = awstypes.AZMode(d.Get("az_mode").(string)) requestUpdate = true } @@ -683,27 +682,26 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, meta int if len(v.([]interface{})) != n { return sdkdiag.AppendErrorf(diags, "length of preferred_availability_zones (%d) must match num_cache_nodes (%d)", len(v.([]interface{})), n) } - input.NewAvailabilityZones = flex.ExpandStringList(v.([]interface{})[o:]) + input.NewAvailabilityZones = flex.ExpandStringValueList(v.([]interface{})[o:]) } } - input.NumCacheNodes = aws.Int64(int64(d.Get("num_cache_nodes").(int))) + input.NumCacheNodes = aws.Int32(int32(d.Get("num_cache_nodes").(int))) requestUpdate = true } if requestUpdate { - log.Printf("[DEBUG] Modifying ElastiCache Cluster (%s), opts:\n%s", d.Id(), input) - _, err := conn.ModifyCacheClusterWithContext(ctx, input) + _, err := conn.ModifyCacheCluster(ctx, input) + if err != nil { - return sdkdiag.AppendErrorf(diags, "updating ElastiCache cluster (%s), error: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "updating ElastiCache Cache Cluster (%s): %s", d.Id(), err) } const ( timeout = 80 * time.Minute ) - _, err = waitCacheClusterAvailable(ctx, conn, d.Id(), timeout) - if err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Cache Cluster (%s) to update: %s", d.Id(), err) + if _, err := waitCacheClusterAvailable(ctx, conn, d.Id(), timeout); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Cache Cluster (%s) update: %s", d.Id(), err) } } } @@ -713,35 +711,39 @@ 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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) var finalSnapshotID = d.Get(names.AttrFinalSnapshotIdentifier).(string) - err := DeleteCacheCluster(ctx, conn, d.Id(), finalSnapshotID) + err := deleteCacheCluster(ctx, conn, d.Id(), finalSnapshotID) + + if errs.IsA[*awstypes.CacheClusterNotFoundFault](err) { + return diags + } + if err != nil { - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheClusterNotFoundFault) { - return diags - } return sdkdiag.AppendErrorf(diags, "deleting ElastiCache Cache Cluster (%s): %s", d.Id(), err) } + const ( timeout = 40 * time.Minute ) _, err = waitCacheClusterDeleted(ctx, conn, d.Id(), timeout) + if err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Cache Cluster (%s) to be deleted: %s", d.Id(), err) + return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Cache Cluster (%s) delete: %s", d.Id(), err) } return diags } -func createCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.CreateCacheClusterInput) (string, string, error) { - output, err := conn.CreateCacheClusterWithContext(ctx, input) +func createCacheCluster(ctx context.Context, conn *elasticache.Client, partition string, input *elasticache.CreateCacheClusterInput) (string, string, error) { + output, err := conn.CreateCacheCluster(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.Tags = nil - output, err = conn.CreateCacheClusterWithContext(ctx, input) + output, err = conn.CreateCacheCluster(ctx, input) } if err != nil { @@ -751,13 +753,14 @@ func createCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, inpu if output == nil || output.CacheCluster == nil { return "", "", errors.New("missing cluster ID after creation") } + // ElastiCache always retains the id in lower case, so we have to // mimic that or else we won't be able to refresh a resource whose // name contained uppercase characters. - return strings.ToLower(aws.StringValue(output.CacheCluster.CacheClusterId)), aws.StringValue(output.CacheCluster.ARN), nil + return strings.ToLower(aws.ToString(output.CacheCluster.CacheClusterId)), aws.ToString(output.CacheCluster.ARN), nil } -func DeleteCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, cacheClusterID string, finalSnapshotID string) error { +func deleteCacheCluster(ctx context.Context, conn *elasticache.Client, cacheClusterID string, finalSnapshotID string) error { input := &elasticache.DeleteCacheClusterInput{ CacheClusterId: aws.String(cacheClusterID), } @@ -765,18 +768,18 @@ func DeleteCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, cach input.FinalSnapshotIdentifier = aws.String(finalSnapshotID) } - log.Printf("[DEBUG] Deleting ElastiCache Cache Cluster: %s", input) + log.Printf("[DEBUG] Deleting ElastiCache Cache Cluster: %s", cacheClusterID) err := retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError { - _, err := conn.DeleteCacheClusterWithContext(ctx, input) + _, err := conn.DeleteCacheCluster(ctx, input) if err != nil { - if tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidCacheClusterStateFault, "serving as primary") { + if errs.IsAErrorMessageContains[*awstypes.InvalidCacheClusterStateFault](err, "serving as primary") { return retry.NonRetryableError(err) } - if tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidCacheClusterStateFault, "only member of a replication group") { + if errs.IsAErrorMessageContains[*awstypes.InvalidCacheClusterStateFault](err, "only member of a replication group") { return retry.NonRetryableError(err) } // The cluster may be just snapshotting, so we retry until it's ready for deletion - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeInvalidCacheClusterStateFault) { + if errs.IsA[*awstypes.InvalidCacheClusterStateFault](err) { return retry.RetryableError(err) } return retry.NonRetryableError(err) @@ -784,70 +787,69 @@ func DeleteCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, cach return nil }) if tfresource.TimedOut(err) { - _, err = conn.DeleteCacheClusterWithContext(ctx, input) + _, err = conn.DeleteCacheCluster(ctx, input) } return err } -func findCacheClusterByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.CacheCluster, error) { +func findCacheClusterByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.CacheCluster, error) { input := &elasticache.DescribeCacheClustersInput{ CacheClusterId: aws.String(id), } - return findCacheCluster(ctx, conn, input, tfslices.PredicateTrue[*elasticache.CacheCluster]()) + return findCacheCluster(ctx, conn, input, tfslices.PredicateTrue[*awstypes.CacheCluster]()) } -func findCacheClusterWithNodeInfoByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.CacheCluster, error) { + +func findCacheClusterWithNodeInfoByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.CacheCluster, error) { input := &elasticache.DescribeCacheClustersInput{ CacheClusterId: aws.String(id), ShowCacheNodeInfo: aws.Bool(true), } - return findCacheCluster(ctx, conn, input, tfslices.PredicateTrue[*elasticache.CacheCluster]()) + return findCacheCluster(ctx, conn, input, tfslices.PredicateTrue[*awstypes.CacheCluster]()) } -func findCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheClustersInput, filter tfslices.Predicate[*elasticache.CacheCluster]) (*elasticache.CacheCluster, error) { +func findCacheCluster(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheClustersInput, filter tfslices.Predicate[*awstypes.CacheCluster]) (*awstypes.CacheCluster, error) { output, err := findCacheClusters(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findCacheClusters(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheClustersInput, filter tfslices.Predicate[*elasticache.CacheCluster]) ([]*elasticache.CacheCluster, error) { - var output []*elasticache.CacheCluster +func findCacheClusters(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheClustersInput, filter tfslices.Predicate[*awstypes.CacheCluster]) ([]awstypes.CacheCluster, error) { + var output []awstypes.CacheCluster - err := conn.DescribeCacheClustersPagesWithContext(ctx, input, func(page *elasticache.DescribeCacheClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeCacheClustersPaginator(conn, input) - for _, v := range page.CacheClusters { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.CacheClusterNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheClusterNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.CacheClusters { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func statusCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, cacheClusterID string) retry.StateRefreshFunc { +func statusCacheCluster(ctx context.Context, conn *elasticache.Client, cacheClusterID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findCacheClusterByID(ctx, conn, cacheClusterID) @@ -859,7 +861,7 @@ func statusCacheCluster(ctx context.Context, conn *elasticache.ElastiCache, cach return nil, "", err } - return output, aws.StringValue(output.CacheClusterStatus), nil + return output, aws.ToString(output.CacheClusterStatus), nil } } @@ -875,7 +877,7 @@ const ( cacheClusterStatusSnapshotting = "snapshotting" ) -func waitCacheClusterAvailable(ctx context.Context, conn *elasticache.ElastiCache, cacheClusterID string, timeout time.Duration) (*elasticache.CacheCluster, error) { //nolint:unparam +func waitCacheClusterAvailable(ctx context.Context, conn *elasticache.Client, cacheClusterID string, timeout time.Duration) (*awstypes.CacheCluster, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{ cacheClusterStatusCreating, @@ -892,14 +894,14 @@ func waitCacheClusterAvailable(ctx context.Context, conn *elasticache.ElastiCach outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.CacheCluster); ok { + if output, ok := outputRaw.(*awstypes.CacheCluster); ok { return output, err } return nil, err } -func waitCacheClusterDeleted(ctx context.Context, conn *elasticache.ElastiCache, cacheClusterID string, timeout time.Duration) (*elasticache.CacheCluster, error) { +func waitCacheClusterDeleted(ctx context.Context, conn *elasticache.Client, cacheClusterID string, timeout time.Duration) (*awstypes.CacheCluster, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ cacheClusterStatusCreating, @@ -919,25 +921,25 @@ func waitCacheClusterDeleted(ctx context.Context, conn *elasticache.ElastiCache, outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.CacheCluster); ok { + if output, ok := outputRaw.(*awstypes.CacheCluster); ok { return output, err } return nil, err } -func getCacheNodesToRemove(oldNumberOfNodes int, cacheNodesToRemove int) []*string { - nodesIdsToRemove := []*string{} +func getCacheNodesToRemove(oldNumberOfNodes int, cacheNodesToRemove int) []string { + nodesIdsToRemove := []string{} for i := oldNumberOfNodes; i > oldNumberOfNodes-cacheNodesToRemove && i > 0; i-- { s := fmt.Sprintf("%04d", i) - nodesIdsToRemove = append(nodesIdsToRemove, &s) + nodesIdsToRemove = append(nodesIdsToRemove, s) } return nodesIdsToRemove } -func setCacheNodeData(d *schema.ResourceData, c *elasticache.CacheCluster) error { - sortedCacheNodes := make([]*elasticache.CacheNode, len(c.CacheNodes)) +func setCacheNodeData(d *schema.ResourceData, c *awstypes.CacheCluster) error { + sortedCacheNodes := make([]awstypes.CacheNode, len(c.CacheNodes)) copy(sortedCacheNodes, c.CacheNodes) sort.Sort(byCacheNodeId(sortedCacheNodes)) @@ -945,41 +947,41 @@ func setCacheNodeData(d *schema.ResourceData, c *elasticache.CacheCluster) error for _, node := range sortedCacheNodes { if node.CacheNodeId == nil || node.Endpoint == nil || node.Endpoint.Address == nil || node.Endpoint.Port == nil || node.CustomerAvailabilityZone == nil { - return fmt.Errorf("Unexpected nil pointer in: %s", node) + return fmt.Errorf("Unexpected nil pointer in: %+v", node) } cacheNodeData = append(cacheNodeData, map[string]interface{}{ - names.AttrID: aws.StringValue(node.CacheNodeId), - names.AttrAddress: aws.StringValue(node.Endpoint.Address), - names.AttrPort: aws.Int64Value(node.Endpoint.Port), - names.AttrAvailabilityZone: aws.StringValue(node.CustomerAvailabilityZone), - "outpost_arn": aws.StringValue(node.CustomerOutpostArn), + names.AttrID: aws.ToString(node.CacheNodeId), + names.AttrAddress: aws.ToString(node.Endpoint.Address), + names.AttrPort: aws.ToInt32(node.Endpoint.Port), + names.AttrAvailabilityZone: aws.ToString(node.CustomerAvailabilityZone), + "outpost_arn": aws.ToString(node.CustomerOutpostArn), }) } return d.Set("cache_nodes", cacheNodeData) } -type byCacheNodeId []*elasticache.CacheNode +type byCacheNodeId []awstypes.CacheNode func (b byCacheNodeId) Len() int { return len(b) } func (b byCacheNodeId) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b byCacheNodeId) Less(i, j int) bool { return b[i].CacheNodeId != nil && b[j].CacheNodeId != nil && - aws.StringValue(b[i].CacheNodeId) < aws.StringValue(b[j].CacheNodeId) + aws.ToString(b[i].CacheNodeId) < aws.ToString(b[j].CacheNodeId) } -func setFromCacheCluster(d *schema.ResourceData, c *elasticache.CacheCluster) error { +func setFromCacheCluster(d *schema.ResourceData, c *awstypes.CacheCluster) error { d.Set("node_type", c.CacheNodeType) d.Set(names.AttrEngine, c.Engine) - if aws.StringValue(c.Engine) == engineRedis { + if aws.ToString(c.Engine) == engineRedis { if err := setEngineVersionRedis(d, c.EngineVersion); err != nil { return err // nosemgrep:ci.bare-error-returns } } else { setEngineVersionMemcached(d, c.EngineVersion) } - d.Set(names.AttrAutoMinorVersionUpgrade, strconv.FormatBool(aws.BoolValue(c.AutoMinorVersionUpgrade))) + d.Set(names.AttrAutoMinorVersionUpgrade, strconv.FormatBool(aws.ToBool(c.AutoMinorVersionUpgrade))) d.Set("subnet_group_name", c.CacheSubnetGroupName) if err := d.Set(names.AttrSecurityGroupIDs, flattenSecurityGroupIDs(c.SecurityGroups)); err != nil { diff --git a/internal/service/elasticache/cluster_data_source.go b/internal/service/elasticache/cluster_data_source.go index b95f8540ce6..ba306d66535 100644 --- a/internal/service/elasticache/cluster_data_source.go +++ b/internal/service/elasticache/cluster_data_source.go @@ -9,7 +9,7 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "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" @@ -174,8 +174,9 @@ func dataSourceCluster() *schema.Resource { func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + partition := meta.(*conns.AWSClient).Partition clusterID := d.Get("cluster_id").(string) cluster, err := findCacheClusterWithNodeInfoByID(ctx, conn, clusterID) @@ -184,11 +185,11 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("ElastiCache Cluster", err)) } - d.SetId(aws.StringValue(cluster.CacheClusterId)) + d.SetId(aws.ToString(cluster.CacheClusterId)) d.Set(names.AttrARN, cluster.ARN) d.Set(names.AttrAvailabilityZone, cluster.PreferredAvailabilityZone) if cluster.ConfigurationEndpoint != nil { - clusterAddress, port := aws.StringValue(cluster.ConfigurationEndpoint.Address), aws.Int64Value(cluster.ConfigurationEndpoint.Port) + clusterAddress, port := aws.ToString(cluster.ConfigurationEndpoint.Address), aws.ToInt32(cluster.ConfigurationEndpoint.Port) d.Set("cluster_address", clusterAddress) d.Set("configuration_endpoint", fmt.Sprintf("%s:%d", clusterAddress, port)) d.Set(names.AttrPort, port) @@ -202,7 +203,7 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("network_type", cluster.NetworkType) d.Set("node_type", cluster.CacheNodeType) if cluster.NotificationConfiguration != nil { - if aws.StringValue(cluster.NotificationConfiguration.TopicStatus) == "active" { + if aws.ToString(cluster.NotificationConfiguration.TopicStatus) == "active" { d.Set("notification_topic_arn", cluster.NotificationConfiguration.TopicArn) } } @@ -218,12 +219,12 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int d.Set("subnet_group_name", cluster.CacheSubnetGroupName) if err := setCacheNodeData(d, cluster); err != nil { - return sdkdiag.AppendErrorf(diags, "setting cache_nodes: %s", err) + return sdkdiag.AppendFromErr(diags, err) } - tags, err := listTags(ctx, conn, aws.StringValue(cluster.ARN)) + tags, err := listTags(ctx, conn, aws.ToString(cluster.ARN)) - if err != nil && !errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if err != nil && !errs.IsUnsupportedOperationInPartitionError(partition, err) { return sdkdiag.AppendErrorf(diags, "listing tags for ElastiCache Cluster (%s): %s", d.Id(), err) } diff --git a/internal/service/elasticache/cluster_data_source_test.go b/internal/service/elasticache/cluster_data_source_test.go index eaaf6552172..5fd2e13eae9 100644 --- a/internal/service/elasticache/cluster_data_source_test.go +++ b/internal/service/elasticache/cluster_data_source_test.go @@ -7,7 +7,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -63,7 +63,7 @@ func TestAccElastiCacheClusterDataSource_Engine_Redis_LogDeliveryConfigurations( ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson, true, awstypes.DestinationTypeCloudWatchLogs, awstypes.LogFormatText), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, names.AttrEngine, "redis"), resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configuration.#", acctest.Ct2), diff --git a/internal/service/elasticache/cluster_test.go b/internal/service/elasticache/cluster_test.go index 330750ca516..adc687e6881 100644 --- a/internal/service/elasticache/cluster_test.go +++ b/internal/service/elasticache/cluster_test.go @@ -12,8 +12,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -40,7 +40,7 @@ func TestAccElastiCacheCluster_Engine_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -79,7 +79,7 @@ func TestAccElastiCacheCluster_Engine_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -123,7 +123,7 @@ func TestAccElastiCacheCluster_disappears(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -151,7 +151,7 @@ func TestAccElastiCacheCluster_Engine_redis_v5(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -209,7 +209,7 @@ func TestAccElastiCacheCluster_PortRedis_default(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -236,7 +236,7 @@ func TestAccElastiCacheCluster_ParameterGroupName_default(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -274,7 +274,7 @@ func TestAccElastiCacheCluster_ipDiscovery(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -310,7 +310,7 @@ func TestAccElastiCacheCluster_port(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster port := 11212 rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -350,7 +350,7 @@ func TestAccElastiCacheCluster_snapshotsWithUpdates(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -385,7 +385,7 @@ func TestAccElastiCacheCluster_NumCacheNodes_decrease(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -419,7 +419,7 @@ func TestAccElastiCacheCluster_NumCacheNodes_increase(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -453,7 +453,7 @@ func TestAccElastiCacheCluster_NumCacheNodes_increaseWithPreferredAvailabilityZo t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -489,8 +489,8 @@ func TestAccElastiCacheCluster_vpc(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var csg elasticache.CacheSubnetGroup - var ec elasticache.CacheCluster + var csg awstypes.CacheSubnetGroup + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -517,8 +517,8 @@ func TestAccElastiCacheCluster_multiAZInVPC(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var csg elasticache.CacheSubnetGroup - var ec elasticache.CacheCluster + var csg awstypes.CacheSubnetGroup + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -545,7 +545,7 @@ func TestAccElastiCacheCluster_AZMode_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -584,7 +584,7 @@ func TestAccElastiCacheCluster_AZMode_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -619,7 +619,7 @@ func TestAccElastiCacheCluster_EngineVersion_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var pre, mid, post elasticache.CacheCluster + var pre, mid, post awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -665,7 +665,7 @@ func TestAccElastiCacheCluster_EngineVersion_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var v1, v2, v3, v4, v5, v6 elasticache.CacheCluster + var v1, v2, v3, v4, v5, v6 awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -738,7 +738,7 @@ func TestAccElastiCacheCluster_NodeTypeResize_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var pre, post elasticache.CacheCluster + var pre, post awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -773,7 +773,7 @@ func TestAccElastiCacheCluster_NodeTypeResize_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var pre, post elasticache.CacheCluster + var pre, post awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -826,8 +826,8 @@ func TestAccElastiCacheCluster_ReplicationGroupID_availabilityZone(t *testing.T) t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster - var replicationGroup elasticache.ReplicationGroup + var cluster awstypes.CacheCluster + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName := "aws_elasticache_cluster.test" replicationGroupResourceName := "aws_elasticache_replication_group.test" @@ -856,8 +856,8 @@ func TestAccElastiCacheCluster_ReplicationGroupID_transitEncryption(t *testing.T t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster - var replicationGroup elasticache.ReplicationGroup + var cluster awstypes.CacheCluster + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName := "aws_elasticache_cluster.test" replicationGroupResourceName := "aws_elasticache_replication_group.test" @@ -887,8 +887,8 @@ func TestAccElastiCacheCluster_ReplicationGroupID_singleReplica(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster - var replicationGroup elasticache.ReplicationGroup + var cluster awstypes.CacheCluster + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName := "aws_elasticache_cluster.test.0" replicationGroupResourceName := "aws_elasticache_replication_group.test" @@ -920,8 +920,8 @@ func TestAccElastiCacheCluster_ReplicationGroupID_multipleReplica(t *testing.T) t.Skip("skipping long-running test in short mode") } - var cluster1, cluster2 elasticache.CacheCluster - var replicationGroup elasticache.ReplicationGroup + var cluster1, cluster2 awstypes.CacheCluster + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) clusterResourceName1 := "aws_elasticache_cluster.test.0" clusterResourceName2 := "aws_elasticache_cluster.test.1" @@ -979,7 +979,7 @@ func TestAccElastiCacheCluster_Redis_finalSnapshot(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1006,7 +1006,7 @@ func TestAccElastiCacheCluster_Redis_autoMinorVersionUpgrade(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1048,7 +1048,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1059,7 +1059,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeCloudWatchLogs, awstypes.LogFormatText, true, awstypes.DestinationTypeCloudWatchLogs, awstypes.LogFormatText), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &ec), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -1080,7 +1080,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing ImportStateVerifyIgnore: []string{names.AttrApplyImmediately}, }, { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &ec), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -1101,7 +1101,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing ImportStateVerifyIgnore: []string{names.AttrApplyImmediately}, }, { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeCloudWatchLogs, awstypes.LogFormatText, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &ec), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -1116,7 +1116,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing ), }, { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson, true, awstypes.DestinationTypeCloudWatchLogs, awstypes.LogFormatText), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &ec), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -1146,7 +1146,7 @@ func TestAccElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations(t *testing ), }, { - Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, false, "", ""), + Config: testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, awstypes.DestinationTypeKinesisFirehose, awstypes.LogFormatJson, false, "", ""), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &ec), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -1176,7 +1176,7 @@ func TestAccElastiCacheCluster_tags(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1234,7 +1234,7 @@ func TestAccElastiCacheCluster_tagWithOtherModification(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1275,7 +1275,7 @@ func TestAccElastiCacheCluster_TransitEncryption(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") } - var cluster elasticache.CacheCluster + var cluster awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1312,7 +1312,7 @@ func TestAccElastiCacheCluster_outpost_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1352,7 +1352,7 @@ func TestAccElastiCacheCluster_outpost_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var ec elasticache.CacheCluster + var ec awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1392,7 +1392,7 @@ func TestAccElastiCacheCluster_outpostID_memcached(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var pre, post elasticache.CacheCluster + var pre, post awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1425,7 +1425,7 @@ func TestAccElastiCacheCluster_outpostID_redis(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var pre, post elasticache.CacheCluster + var pre, post awstypes.CacheCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_cluster.test" @@ -1452,7 +1452,7 @@ func TestAccElastiCacheCluster_outpostID_redis(t *testing.T) { }) } -func testAccCheckClusterAttributes(v *elasticache.CacheCluster) resource.TestCheckFunc { +func testAccCheckClusterAttributes(v *awstypes.CacheCluster) resource.TestCheckFunc { return func(s *terraform.State) error { if v.NotificationConfiguration == nil { return fmt.Errorf("Expected NotificationConfiguration for ElastiCache Cluster (%s)", *v.CacheClusterId) @@ -1466,13 +1466,13 @@ func testAccCheckClusterAttributes(v *elasticache.CacheCluster) resource.TestChe } } -func testAccCheckClusterReplicationGroupIDAttribute(cluster *elasticache.CacheCluster, replicationGroup *elasticache.ReplicationGroup) resource.TestCheckFunc { +func testAccCheckClusterReplicationGroupIDAttribute(cluster *awstypes.CacheCluster, replicationGroup *awstypes.ReplicationGroup) resource.TestCheckFunc { return func(s *terraform.State) error { if cluster.ReplicationGroupId == nil { return errors.New("expected cluster ReplicationGroupId to be set") } - if aws.StringValue(cluster.ReplicationGroupId) != aws.StringValue(replicationGroup.ReplicationGroupId) { + if aws.ToString(cluster.ReplicationGroupId) != aws.ToString(replicationGroup.ReplicationGroupId) { return errors.New("expected cluster ReplicationGroupId to equal replication group ID") } @@ -1480,9 +1480,9 @@ func testAccCheckClusterReplicationGroupIDAttribute(cluster *elasticache.CacheCl } } -func testAccCheckClusterNotRecreated(i, j *elasticache.CacheCluster) resource.TestCheckFunc { +func testAccCheckClusterNotRecreated(i, j *awstypes.CacheCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - if !aws.TimeValue(i.CacheClusterCreateTime).Equal(aws.TimeValue(j.CacheClusterCreateTime)) { + if !aws.ToTime(i.CacheClusterCreateTime).Equal(aws.ToTime(j.CacheClusterCreateTime)) { return errors.New("ElastiCache Cluster was recreated") } @@ -1490,9 +1490,9 @@ func testAccCheckClusterNotRecreated(i, j *elasticache.CacheCluster) resource.Te } } -func testAccCheckClusterRecreated(i, j *elasticache.CacheCluster) resource.TestCheckFunc { +func testAccCheckClusterRecreated(i, j *awstypes.CacheCluster) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.TimeValue(i.CacheClusterCreateTime).Equal(aws.TimeValue(j.CacheClusterCreateTime)) { + if aws.ToTime(i.CacheClusterCreateTime).Equal(aws.ToTime(j.CacheClusterCreateTime)) { return errors.New("ElastiCache Cluster was not recreated") } @@ -1502,7 +1502,7 @@ func testAccCheckClusterRecreated(i, j *elasticache.CacheCluster) resource.TestC func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_cluster" { @@ -1525,7 +1525,7 @@ func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckClusterExists(ctx context.Context, n string, v *elasticache.CacheCluster) resource.TestCheckFunc { +func testAccCheckClusterExists(ctx context.Context, n string, v *awstypes.CacheCluster) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -1536,7 +1536,7 @@ func testAccCheckClusterExists(ctx context.Context, n string, v *elasticache.Cac return fmt.Errorf("No ElastiCache Cluster ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindCacheClusterByID(ctx, conn, rs.Primary.ID) @@ -2088,7 +2088,7 @@ resource "aws_elasticache_cluster" "test" { `, rName, enable) } -func testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName string, slowLogDeliveryEnabled bool, slowDeliveryDestination string, slowDeliveryFormat string, engineLogDeliveryEnabled bool, engineDeliveryDestination string, engineLogDeliveryFormat string) string { +func testAccClusterConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName string, slowLogDeliveryEnabled bool, slowDeliveryDestination awstypes.DestinationType, slowDeliveryFormat awstypes.LogFormat, engineLogDeliveryEnabled bool, engineDeliveryDestination awstypes.DestinationType, engineLogDeliveryFormat awstypes.LogFormat) string { return fmt.Sprintf(` data "aws_iam_policy_document" "p" { statement { diff --git a/internal/service/elasticache/service.go b/internal/service/elasticache/consts.go similarity index 100% rename from internal/service/elasticache/service.go rename to internal/service/elasticache/consts.go diff --git a/internal/service/elasticache/diff.go b/internal/service/elasticache/diff.go index 3a629dc6a25..5cc20eaa812 100644 --- a/internal/service/elasticache/diff.go +++ b/internal/service/elasticache/diff.go @@ -7,20 +7,19 @@ import ( "context" "errors" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/names" ) // customizeDiffValidateClusterAZMode validates that `num_cache_nodes` is greater than 1 when `az_mode` is "cross-az" func customizeDiffValidateClusterAZMode(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - if v, ok := diff.GetOk("az_mode"); !ok || v.(string) != elasticache.AZModeCrossAz { + if v, ok := diff.GetOk("az_mode"); !ok || awstypes.AZMode(v.(string)) != awstypes.AZModeCrossAz { return nil } if v, ok := diff.GetOk("num_cache_nodes"); !ok || v.(int) != 1 { return nil } - return errors.New(`az_mode "cross-az" is not supported with num_cache_nodes = 1`) } @@ -29,7 +28,6 @@ func customizeDiffValidateClusterNumCacheNodes(_ context.Context, diff *schema.R if v, ok := diff.GetOk(names.AttrEngine); !ok || v.(string) == engineMemcached { return nil } - if v, ok := diff.GetOk("num_cache_nodes"); !ok || v.(int) == 1 { return nil } diff --git a/internal/service/elasticache/engine_version.go b/internal/service/elasticache/engine_version.go index 71b0bd817b0..448069ed2f4 100644 --- a/internal/service/elasticache/engine_version.go +++ b/internal/service/elasticache/engine_version.go @@ -11,7 +11,7 @@ import ( "regexp" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" gversion "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/names" @@ -167,7 +167,7 @@ func setEngineVersionMemcached(d *schema.ResourceData, version *string) { } func setEngineVersionRedis(d *schema.ResourceData, version *string) error { - engineVersion, err := gversion.NewVersion(aws.StringValue(version)) + engineVersion, err := gversion.NewVersion(aws.ToString(version)) if err != nil { return fmt.Errorf("reading engine version: %w", err) } @@ -187,11 +187,11 @@ func setEngineVersionRedis(d *schema.ResourceData, version *string) error { return nil } -type VersionDiff [3]int +type versionDiff [3]int // diffVersion returns a diff of the versions, component by component. // Only reports the first diff, since subsequent segments are unimportant for us. -func diffVersion(n, o *gversion.Version) (result VersionDiff) { +func diffVersion(n, o *gversion.Version) (result versionDiff) { if n.String() == o.String() { return } diff --git a/internal/service/elasticache/exports_test.go b/internal/service/elasticache/exports_test.go index f9fd80061e5..c4d719c6f15 100644 --- a/internal/service/elasticache/exports_test.go +++ b/internal/service/elasticache/exports_test.go @@ -30,14 +30,21 @@ var ( WaitCacheClusterDeleted = waitCacheClusterDeleted WaitReplicationGroupAvailable = waitReplicationGroupAvailable + DeleteCacheCluster = deleteCacheCluster DiffVersion = diffVersion + EmptyDescription = emptyDescription EngineMemcached = engineMemcached EngineRedis = engineRedis EngineVersionForceNewOnDowngrade = engineVersionForceNewOnDowngrade EngineVersionIsDowngrade = engineVersionIsDowngrade + GlobalReplicationGroupRegionPrefixFormat = globalReplicationGroupRegionPrefixFormat NormalizeEngineVersion = normalizeEngineVersion ParamGroupNameRequiresMajorVersionUpgrade = paramGroupNameRequiresMajorVersionUpgrade ValidateClusterEngineVersion = validateClusterEngineVersion ValidMemcachedVersionString = validMemcachedVersionString ValidRedisVersionString = validRedisVersionString ) + +type ( + VersionDiff = versionDiff +) diff --git a/internal/service/elasticache/flex.go b/internal/service/elasticache/flex.go index 2fb70a3936d..d7d241ff5a2 100644 --- a/internal/service/elasticache/flex.go +++ b/internal/service/elasticache/flex.go @@ -4,74 +4,72 @@ package elasticache import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" "github.com/hashicorp/terraform-provider-aws/names" ) -func flattenSecurityGroupIDs(securityGroups []*elasticache.SecurityGroupMembership) []string { - result := make([]string, 0, len(securityGroups)) - for _, sg := range securityGroups { - if sg.SecurityGroupId != nil { - result = append(result, *sg.SecurityGroupId) - } - } - return result +func flattenSecurityGroupIDs(apiObjects []awstypes.SecurityGroupMembership) []string { + return tfslices.ApplyToAll(apiObjects, func(v awstypes.SecurityGroupMembership) string { + return aws.ToString(v.SecurityGroupId) + }) } -func flattenLogDeliveryConfigurations(logDeliveryConfiguration []*elasticache.LogDeliveryConfiguration) []map[string]interface{} { - if len(logDeliveryConfiguration) == 0 { +func flattenLogDeliveryConfigurations(apiObjects []awstypes.LogDeliveryConfiguration) []interface{} { + if len(apiObjects) == 0 { return nil } - var logDeliveryConfigurations []map[string]interface{} - for _, v := range logDeliveryConfiguration { - logDeliveryConfig := make(map[string]interface{}) + var tfList []interface{} + + for _, apiObject := range apiObjects { + tfMap := make(map[string]interface{}) - switch aws.StringValue(v.DestinationType) { - case elasticache.DestinationTypeKinesisFirehose: - logDeliveryConfig[names.AttrDestination] = aws.StringValue(v.DestinationDetails.KinesisFirehoseDetails.DeliveryStream) - case elasticache.DestinationTypeCloudwatchLogs: - logDeliveryConfig[names.AttrDestination] = aws.StringValue(v.DestinationDetails.CloudWatchLogsDetails.LogGroup) + switch apiObject.DestinationType { + case awstypes.DestinationTypeKinesisFirehose: + tfMap[names.AttrDestination] = aws.ToString(apiObject.DestinationDetails.KinesisFirehoseDetails.DeliveryStream) + case awstypes.DestinationTypeCloudWatchLogs: + tfMap[names.AttrDestination] = aws.ToString(apiObject.DestinationDetails.CloudWatchLogsDetails.LogGroup) } + tfMap["destination_type"] = apiObject.DestinationType + tfMap["log_format"] = apiObject.LogFormat + tfMap["log_type"] = apiObject.LogType - logDeliveryConfig["destination_type"] = aws.StringValue(v.DestinationType) - logDeliveryConfig["log_format"] = aws.StringValue(v.LogFormat) - logDeliveryConfig["log_type"] = aws.StringValue(v.LogType) - logDeliveryConfigurations = append(logDeliveryConfigurations, logDeliveryConfig) + tfList = append(tfList, tfMap) } - return logDeliveryConfigurations + return tfList } -func expandEmptyLogDeliveryConfigurations(v map[string]interface{}) elasticache.LogDeliveryConfigurationRequest { - logDeliveryConfigurationRequest := elasticache.LogDeliveryConfigurationRequest{} - logDeliveryConfigurationRequest.SetEnabled(false) - logDeliveryConfigurationRequest.SetLogType(v["log_type"].(string)) +func expandEmptyLogDeliveryConfigurationRequest(tfMap map[string]interface{}) awstypes.LogDeliveryConfigurationRequest { + apiObject := awstypes.LogDeliveryConfigurationRequest{} - return logDeliveryConfigurationRequest -} + apiObject.Enabled = aws.Bool(false) + apiObject.LogType = awstypes.LogType(tfMap["log_type"].(string)) -func expandLogDeliveryConfigurations(v map[string]interface{}) elasticache.LogDeliveryConfigurationRequest { - logDeliveryConfigurationRequest := elasticache.LogDeliveryConfigurationRequest{} + return apiObject +} - logDeliveryConfigurationRequest.LogType = aws.String(v["log_type"].(string)) - logDeliveryConfigurationRequest.DestinationType = aws.String(v["destination_type"].(string)) - logDeliveryConfigurationRequest.LogFormat = aws.String(v["log_format"].(string)) - destinationDetails := elasticache.DestinationDetails{} +func expandLogDeliveryConfigurationRequests(v map[string]interface{}) awstypes.LogDeliveryConfigurationRequest { + apiObject := awstypes.LogDeliveryConfigurationRequest{} - switch v["destination_type"].(string) { - case elasticache.DestinationTypeCloudwatchLogs: - destinationDetails.CloudWatchLogsDetails = &elasticache.CloudWatchLogsDestinationDetails{ + destinationType := awstypes.DestinationType(v["destination_type"].(string)) + apiObject.DestinationType = destinationType + destinationDetails := &awstypes.DestinationDetails{} + switch destinationType { + case awstypes.DestinationTypeCloudWatchLogs: + destinationDetails.CloudWatchLogsDetails = &awstypes.CloudWatchLogsDestinationDetails{ LogGroup: aws.String(v[names.AttrDestination].(string)), } - case elasticache.DestinationTypeKinesisFirehose: - destinationDetails.KinesisFirehoseDetails = &elasticache.KinesisFirehoseDestinationDetails{ + case awstypes.DestinationTypeKinesisFirehose: + destinationDetails.KinesisFirehoseDetails = &awstypes.KinesisFirehoseDestinationDetails{ DeliveryStream: aws.String(v[names.AttrDestination].(string)), } } + apiObject.DestinationDetails = destinationDetails + apiObject.LogType = awstypes.LogType(v["log_type"].(string)) + apiObject.LogFormat = awstypes.LogFormat(v["log_format"].(string)) - logDeliveryConfigurationRequest.DestinationDetails = &destinationDetails - - return logDeliveryConfigurationRequest + return apiObject } diff --git a/internal/service/elasticache/generate.go b/internal/service/elasticache/generate.go index 0436db54324..9ac233d5186 100644 --- a/internal/service/elasticache/generate.go +++ b/internal/service/elasticache/generate.go @@ -1,8 +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 -CreateTags -RetryTagsListTagsType=TagListMessage -RetryTagsErrorCodes=elasticache.ErrCodeInvalidReplicationGroupStateFault "-RetryTagsErrorMessages=not in available state" -RetryTagsTimeout=15m -//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -TagsFunc=TagsV2 -KeyValueTagsFunc=keyValueTagsV2 -GetTagsInFunc=getTagsInV2 -SetTagsOutFunc=setTagsOutV2 -SkipAWSServiceImp -KVTValues -ServiceTagsSlice -- tagsv2_gen.go +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -CreateTags -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/elasticache/global_replication_group.go b/internal/service/elasticache/global_replication_group.go index fe284d944d5..7043cc75a64 100644 --- a/internal/service/elasticache/global_replication_group.go +++ b/internal/service/elasticache/global_replication_group.go @@ -14,9 +14,9 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" gversion "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -32,11 +33,11 @@ import ( ) const ( - EmptyDescription = " " + emptyDescription = " " ) const ( - GlobalReplicationGroupRegionPrefixFormat = "[[:alpha:]]{5}-" + globalReplicationGroupRegionPrefixFormat = "[[:alpha:]]{5}-" ) const ( @@ -54,7 +55,7 @@ func resourceGlobalReplicationGroup() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: func(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - re := regexache.MustCompile("^" + GlobalReplicationGroupRegionPrefixFormat) + re := regexache.MustCompile("^" + globalReplicationGroupRegionPrefixFormat) d.Set("global_replication_group_id_suffix", re.ReplaceAllLiteralString(d.Id(), "")) return []*schema.ResourceData{d}, nil @@ -141,7 +142,7 @@ func resourceGlobalReplicationGroup() *schema.Resource { Type: schema.TypeString, Optional: true, DiffSuppressFunc: func(_, old, new string, _ *schema.ResourceData) bool { - if (old == EmptyDescription && new == "") || (old == "" && new == EmptyDescription) { + if (old == emptyDescription && new == "") || (old == "" && new == emptyDescription) { return true } return false @@ -149,7 +150,7 @@ func resourceGlobalReplicationGroup() *schema.Resource { StateFunc: func(v any) string { s := v.(string) if s == "" { - return EmptyDescription + return emptyDescription } return s }, @@ -268,7 +269,7 @@ func paramGroupNameRequiresMajorVersionUpgrade(diff sdkv2.ResourceDiffer) error func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) id := d.Get("global_replication_group_id_suffix").(string) input := &elasticache.CreateGlobalReplicationGroupInput{ @@ -280,13 +281,13 @@ func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.Resourc input.GlobalReplicationGroupDescription = aws.String(v.(string)) } - output, err := conn.CreateGlobalReplicationGroupWithContext(ctx, input) + output, err := conn.CreateGlobalReplicationGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache Global Replication Group (%s): %s", id, err) } - d.SetId(aws.StringValue(output.GlobalReplicationGroup.GlobalReplicationGroupId)) + d.SetId(aws.ToString(output.GlobalReplicationGroup.GlobalReplicationGroupId)) globalReplicationGroup, err := waitGlobalReplicationGroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)) @@ -305,7 +306,7 @@ func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.Resourc } if v, ok := d.GetOk("cache_node_type"); ok { - if v.(string) == aws.StringValue(globalReplicationGroup.CacheNodeType) { + if v.(string) == aws.ToString(globalReplicationGroup.CacheNodeType) { log.Printf("[DEBUG] Not updating ElastiCache Global Replication Group (%s) node type: no change from %q", d.Id(), v) } else { if err := updateGlobalReplicationGroup(ctx, conn, d.Id(), globalReplicationGroupNodeTypeUpdater(v.(string)), "node type", d.Timeout(schema.TimeoutCreate)); err != nil { @@ -317,7 +318,7 @@ func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.Resourc if v, ok := d.GetOk(names.AttrEngineVersion); ok { requestedVersion, _ := normalizeEngineVersion(v.(string)) - engineVersion, err := gversion.NewVersion(aws.StringValue(globalReplicationGroup.EngineVersion)) + engineVersion, err := gversion.NewVersion(aws.ToString(globalReplicationGroup.EngineVersion)) if err != nil { return sdkdiag.AppendErrorf(diags, "updating ElastiCache Global Replication Group (%s) engine version on creation: error reading engine version: %s", d.Id(), err) } @@ -353,8 +354,8 @@ func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.Resourc return sdkdiag.AppendFromErr(diags, err) } } else if newNodeGroupCount < oldNodeGroupCount { - ids := tfslices.ApplyToAll(globalReplicationGroup.GlobalNodeGroups, func(v *elasticache.GlobalNodeGroup) string { - return aws.StringValue(v.GlobalNodeGroupId) + ids := tfslices.ApplyToAll(globalReplicationGroup.GlobalNodeGroups, func(v awstypes.GlobalNodeGroup) string { + return aws.ToString(v.GlobalNodeGroupId) }) if err := decreaseGlobalReplicationGroupNodeGroupCount(ctx, conn, d.Id(), newNodeGroupCount, ids, d.Timeout(schema.TimeoutUpdate)); err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -368,7 +369,7 @@ func resourceGlobalReplicationGroupCreate(ctx context.Context, d *schema.Resourc func resourceGlobalReplicationGroupRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) globalReplicationGroup, err := findGlobalReplicationGroupByID(ctx, conn, d.Id()) @@ -382,7 +383,7 @@ func resourceGlobalReplicationGroupRead(ctx context.Context, d *schema.ResourceD return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): %s", d.Id(), err) } - if status := aws.StringValue(globalReplicationGroup.Status); !d.IsNewResource() && (status == globalReplicationGroupStatusDeleting || status == globalReplicationGroupStatusDeleted) { + if status := aws.ToString(globalReplicationGroup.Status); !d.IsNewResource() && (status == globalReplicationGroupStatusDeleting || status == globalReplicationGroupStatusDeleted) { log.Printf("[WARN] ElastiCache Global Replication Group (%s) in deleted state (%s), removing from state", d.Id(), status) d.SetId("") return diags @@ -415,7 +416,7 @@ func resourceGlobalReplicationGroupRead(ctx context.Context, d *schema.ResourceD func resourceGlobalReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) // Only one field can be changed per request if d.HasChange("cache_node_type") { @@ -481,7 +482,7 @@ func resourceGlobalReplicationGroupUpdate(ctx context.Context, d *schema.Resourc func resourceGlobalReplicationGroupDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) // Using Update timeout because the Global Replication Group could be in the middle of an update operation. if err := deleteGlobalReplicationGroup(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate), d.Timeout(schema.TimeoutDelete)); err != nil { @@ -524,14 +525,14 @@ func globalReplicationGroupNodeTypeUpdater(nodeType string) globalReplicationGro } } -func updateGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, id string, f globalReplicationGroupUpdater, propertyName string, timeout time.Duration) error { +func updateGlobalReplicationGroup(ctx context.Context, conn *elasticache.Client, id string, f globalReplicationGroupUpdater, propertyName string, timeout time.Duration) error { input := &elasticache.ModifyGlobalReplicationGroupInput{ ApplyImmediately: aws.Bool(true), GlobalReplicationGroupId: aws.String(id), } f(input) - if _, err := conn.ModifyGlobalReplicationGroupWithContext(ctx, input); err != nil { + if _, err := conn.ModifyGlobalReplicationGroup(ctx, input); err != nil { return fmt.Errorf("updating ElastiCache Global Replication Group (%s) %s: %w", id, propertyName, err) } @@ -542,14 +543,14 @@ func updateGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiC return nil } -func increaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *elasticache.ElastiCache, id string, newNodeGroupCount int, timeout time.Duration) error { +func increaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *elasticache.Client, id string, newNodeGroupCount int, timeout time.Duration) error { input := &elasticache.IncreaseNodeGroupsInGlobalReplicationGroupInput{ ApplyImmediately: aws.Bool(true), GlobalReplicationGroupId: aws.String(id), - NodeGroupCount: aws.Int64(int64(newNodeGroupCount)), + NodeGroupCount: aws.Int32(int32(newNodeGroupCount)), } - _, err := conn.IncreaseNodeGroupsInGlobalReplicationGroupWithContext(ctx, input) + _, err := conn.IncreaseNodeGroupsInGlobalReplicationGroup(ctx, input) if err != nil { return fmt.Errorf("increasing ElastiCache Global Replication Group (%s) node group count (%d): %w", id, newNodeGroupCount, err) @@ -562,7 +563,7 @@ func increaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *ela return nil } -func decreaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *elasticache.ElastiCache, id string, newNodeGroupCount int, nodeGroupIDs []string, timeout time.Duration) error { +func decreaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *elasticache.Client, id string, newNodeGroupCount int, nodeGroupIDs []string, timeout time.Duration) error { slices.SortFunc(nodeGroupIDs, func(a, b string) int { if globalReplicationGroupNodeNumber(a) < globalReplicationGroupNodeNumber(b) { return -1 @@ -576,12 +577,12 @@ func decreaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *ela input := &elasticache.DecreaseNodeGroupsInGlobalReplicationGroupInput{ ApplyImmediately: aws.Bool(true), - GlobalNodeGroupsToRetain: aws.StringSlice(nodeGroupIDs), + GlobalNodeGroupsToRetain: nodeGroupIDs, GlobalReplicationGroupId: aws.String(id), - NodeGroupCount: aws.Int64(int64(newNodeGroupCount)), + NodeGroupCount: aws.Int32(int32(newNodeGroupCount)), } - _, err := conn.DecreaseNodeGroupsInGlobalReplicationGroupWithContext(ctx, input) + _, err := conn.DecreaseNodeGroupsInGlobalReplicationGroup(ctx, input) if err != nil { return fmt.Errorf("decreasing ElastiCache Global Replication Group (%s) node group count (%d): %w", id, newNodeGroupCount, err) @@ -594,17 +595,17 @@ func decreaseGlobalReplicationGroupNodeGroupCount(ctx context.Context, conn *ela return nil } -func deleteGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, id string, readyTimeout, deleteTimeout time.Duration) error { +func deleteGlobalReplicationGroup(ctx context.Context, conn *elasticache.Client, id string, readyTimeout, deleteTimeout time.Duration) error { input := &elasticache.DeleteGlobalReplicationGroupInput{ GlobalReplicationGroupId: aws.String(id), RetainPrimaryReplicationGroup: aws.Bool(true), } - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, readyTimeout, func() (interface{}, error) { - return conn.DeleteGlobalReplicationGroupWithContext(ctx, input) - }, elasticache.ErrCodeInvalidGlobalReplicationGroupStateFault) + _, err := tfresource.RetryWhenIsA[*awstypes.InvalidGlobalReplicationGroupStateFault](ctx, readyTimeout, func() (interface{}, error) { + return conn.DeleteGlobalReplicationGroup(ctx, input) + }) - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeGlobalReplicationGroupNotFoundFault) { + if errs.IsA[*awstypes.GlobalReplicationGroupNotFoundFault](err) { return nil } @@ -619,57 +620,55 @@ func deleteGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiC return nil } -func findGlobalReplicationGroupByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.GlobalReplicationGroup, error) { +func findGlobalReplicationGroupByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.GlobalReplicationGroup, error) { input := &elasticache.DescribeGlobalReplicationGroupsInput{ GlobalReplicationGroupId: aws.String(id), ShowMemberInfo: aws.Bool(true), } - return findGlobalReplicationGroup(ctx, conn, input, tfslices.PredicateTrue[*elasticache.GlobalReplicationGroup]()) + return findGlobalReplicationGroup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.GlobalReplicationGroup]()) } -func findGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeGlobalReplicationGroupsInput, filter tfslices.Predicate[*elasticache.GlobalReplicationGroup]) (*elasticache.GlobalReplicationGroup, error) { +func findGlobalReplicationGroup(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeGlobalReplicationGroupsInput, filter tfslices.Predicate[*awstypes.GlobalReplicationGroup]) (*awstypes.GlobalReplicationGroup, error) { output, err := findGlobalReplicationGroups(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findGlobalReplicationGroups(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeGlobalReplicationGroupsInput, filter tfslices.Predicate[*elasticache.GlobalReplicationGroup]) ([]*elasticache.GlobalReplicationGroup, error) { - var output []*elasticache.GlobalReplicationGroup +func findGlobalReplicationGroups(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeGlobalReplicationGroupsInput, filter tfslices.Predicate[*awstypes.GlobalReplicationGroup]) ([]awstypes.GlobalReplicationGroup, error) { + var output []awstypes.GlobalReplicationGroup - err := conn.DescribeGlobalReplicationGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeGlobalReplicationGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeGlobalReplicationGroupsPaginator(conn, input) - for _, v := range page.GlobalReplicationGroups { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.GlobalReplicationGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeGlobalReplicationGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.GlobalReplicationGroups { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func statusGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID string) retry.StateRefreshFunc { +func statusGlobalReplicationGroup(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findGlobalReplicationGroupByID(ctx, conn, globalReplicationGroupID) @@ -681,7 +680,7 @@ func statusGlobalReplicationGroup(ctx context.Context, conn *elasticache.ElastiC return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } @@ -700,7 +699,7 @@ const ( globalReplicationGroupStatusPrimaryOnly = "primary-only" ) -func waitGlobalReplicationGroupAvailable(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID string, timeout time.Duration) (*elasticache.GlobalReplicationGroup, error) { +func waitGlobalReplicationGroupAvailable(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID string, timeout time.Duration) (*awstypes.GlobalReplicationGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{globalReplicationGroupStatusCreating, globalReplicationGroupStatusModifying}, Target: []string{globalReplicationGroupStatusAvailable, globalReplicationGroupStatusPrimaryOnly}, @@ -712,14 +711,14 @@ func waitGlobalReplicationGroupAvailable(ctx context.Context, conn *elasticache. outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.GlobalReplicationGroup); ok { + if output, ok := outputRaw.(*awstypes.GlobalReplicationGroup); ok { return output, err } return nil, err } -func waitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID string, timeout time.Duration) (*elasticache.GlobalReplicationGroup, error) { +func waitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID string, timeout time.Duration) (*awstypes.GlobalReplicationGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ globalReplicationGroupStatusAvailable, @@ -736,14 +735,14 @@ func waitGlobalReplicationGroupDeleted(ctx context.Context, conn *elasticache.El outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.GlobalReplicationGroup); ok { + if output, ok := outputRaw.(*awstypes.GlobalReplicationGroup); ok { return output, err } return nil, err } -func findGlobalReplicationGroupMemberByID(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID, replicationGroupID string) (*elasticache.GlobalReplicationGroupMember, error) { +func findGlobalReplicationGroupMemberByID(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID, replicationGroupID string) (*awstypes.GlobalReplicationGroupMember, error) { globalReplicationGroup, err := findGlobalReplicationGroupByID(ctx, conn, globalReplicationGroupID) if err != nil { @@ -755,8 +754,8 @@ func findGlobalReplicationGroupMemberByID(ctx context.Context, conn *elasticache } for _, v := range globalReplicationGroup.Members { - if aws.StringValue(v.ReplicationGroupId) == replicationGroupID { - return v, nil + if aws.ToString(v.ReplicationGroupId) == replicationGroupID { + return &v, nil } } @@ -765,7 +764,7 @@ func findGlobalReplicationGroupMemberByID(ctx context.Context, conn *elasticache } } -func statusGlobalReplicationGroupMember(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID, replicationGroupID string) retry.StateRefreshFunc { +func statusGlobalReplicationGroupMember(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID, replicationGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findGlobalReplicationGroupMemberByID(ctx, conn, globalReplicationGroupID, replicationGroupID) @@ -777,7 +776,7 @@ func statusGlobalReplicationGroupMember(ctx context.Context, conn *elasticache.E return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } @@ -785,7 +784,7 @@ const ( globalReplicationGroupMemberStatusAssociated = "associated" ) -func waitGlobalReplicationGroupMemberDetached(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID, replicationGroupID string, timeout time.Duration) (*elasticache.GlobalReplicationGroupMember, error) { +func waitGlobalReplicationGroupMemberDetached(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID, replicationGroupID string, timeout time.Duration) (*awstypes.GlobalReplicationGroupMember, error) { stateConf := &retry.StateChangeConf{ Pending: []string{globalReplicationGroupMemberStatusAssociated}, Target: []string{}, @@ -797,23 +796,23 @@ func waitGlobalReplicationGroupMemberDetached(ctx context.Context, conn *elastic outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.GlobalReplicationGroupMember); ok { + if output, ok := outputRaw.(*awstypes.GlobalReplicationGroupMember); ok { return output, err } return nil, err } -func flattenGlobalReplicationGroupAutomaticFailoverEnabled(members []*elasticache.GlobalReplicationGroupMember) bool { +func flattenGlobalReplicationGroupAutomaticFailoverEnabled(members []awstypes.GlobalReplicationGroupMember) bool { if len(members) == 0 { return false } member := members[0] - return aws.StringValue(member.AutomaticFailover) == elasticache.AutomaticFailoverStatusEnabled + return member.AutomaticFailover == awstypes.AutomaticFailoverStatusEnabled } -func flattenGlobalNodeGroups(nodeGroups []*elasticache.GlobalNodeGroup) []any { +func flattenGlobalNodeGroups(nodeGroups []awstypes.GlobalNodeGroup) []any { if len(nodeGroups) == 0 { return nil } @@ -821,38 +820,30 @@ func flattenGlobalNodeGroups(nodeGroups []*elasticache.GlobalNodeGroup) []any { var l []any for _, nodeGroup := range nodeGroups { - if nodeGroup == nil { - continue - } - l = append(l, flattenGlobalNodeGroup(nodeGroup)) } return l } -func flattenGlobalNodeGroup(nodeGroup *elasticache.GlobalNodeGroup) map[string]any { - if nodeGroup == nil { - return nil - } - +func flattenGlobalNodeGroup(nodeGroup awstypes.GlobalNodeGroup) map[string]any { m := map[string]interface{}{} if v := nodeGroup.GlobalNodeGroupId; v != nil { - m["global_node_group_id"] = aws.StringValue(v) + m["global_node_group_id"] = aws.ToString(v) } if v := nodeGroup.Slots; v != nil { - m["slots"] = aws.StringValue(v) + m["slots"] = aws.ToString(v) } return m } -func flattenGlobalReplicationGroupPrimaryGroupID(members []*elasticache.GlobalReplicationGroupMember) string { +func flattenGlobalReplicationGroupPrimaryGroupID(members []awstypes.GlobalReplicationGroupMember) string { for _, member := range members { - if aws.StringValue(member.Role) == globalReplicationGroupMemberRolePrimary { - return aws.StringValue(member.ReplicationGroupId) + if aws.ToString(member.Role) == globalReplicationGroupMemberRolePrimary { + return aws.ToString(member.ReplicationGroupId) } } return "" diff --git a/internal/service/elasticache/global_replication_group_test.go b/internal/service/elasticache/global_replication_group_test.go index e5cdce7df59..399bd8b19f9 100644 --- a/internal/service/elasticache/global_replication_group_test.go +++ b/internal/service/elasticache/global_replication_group_test.go @@ -10,14 +10,15 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs" tfelasticache "github.com/hashicorp/terraform-provider-aws/internal/service/elasticache" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -29,8 +30,8 @@ func TestAccElastiCacheGlobalReplicationGroup_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -83,7 +84,7 @@ func TestAccElastiCacheGlobalReplicationGroup_disappears(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -112,7 +113,7 @@ func TestAccElastiCacheGlobalReplicationGroup_description(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description1 := sdkacctest.RandString(10) @@ -154,7 +155,7 @@ func TestAccElastiCacheGlobalReplicationGroup_nodeType_createNoChange(t *testing t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) nodeType := "cache.m5.large" @@ -188,7 +189,7 @@ func TestAccElastiCacheGlobalReplicationGroup_nodeType_createWithChange(t *testi t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) nodeType := "cache.m5.large" @@ -223,7 +224,7 @@ func TestAccElastiCacheGlobalReplicationGroup_nodeType_setNoChange(t *testing.T) t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) nodeType := "cache.m5.large" @@ -265,7 +266,7 @@ func TestAccElastiCacheGlobalReplicationGroup_nodeType_update(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) nodeType := "cache.m5.large" @@ -307,7 +308,7 @@ func TestAccElastiCacheGlobalReplicationGroup_automaticFailover_createNoChange(t t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -340,7 +341,7 @@ func TestAccElastiCacheGlobalReplicationGroup_automaticFailover_createWithChange t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -373,7 +374,7 @@ func TestAccElastiCacheGlobalReplicationGroup_automaticFailover_setNoChange(t *t t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -414,7 +415,7 @@ func TestAccElastiCacheGlobalReplicationGroup_automaticFailover_update(t *testin t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -454,7 +455,7 @@ func TestAccElastiCacheGlobalReplicationGroup_multipleSecondaries(t *testing.T) t.Skip("skipping long-running test in short mode") } - var globalReplcationGroup elasticache.GlobalReplicationGroup + var globalReplcationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -483,7 +484,7 @@ func TestAccElastiCacheGlobalReplicationGroup_ReplaceSecondary_differentRegion(t t.Skip("skipping long-running test in short mode") } - var globalReplcationGroup elasticache.GlobalReplicationGroup + var globalReplcationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -518,8 +519,8 @@ func TestAccElastiCacheGlobalReplicationGroup_clusterMode_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -558,8 +559,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetNumNodeGroupsOnCreate_NoChange( t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -598,8 +599,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetNumNodeGroupsOnCreate_Increase( t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -647,8 +648,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetNumNodeGroupsOnCreate_Decrease( t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -691,8 +692,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetNumNodeGroupsOnUpdate_Increase( t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -757,8 +758,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetNumNodeGroupsOnUpdate_Decrease( t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var primaryReplicationGroup elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var primaryReplicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -818,7 +819,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_NoChange_ t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -851,7 +852,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_NoChange_ t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -885,7 +886,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_NoChange_ t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -918,8 +919,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_MinorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var rg elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -956,8 +957,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_MinorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var rg elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -989,8 +990,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_MajorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var rg elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1028,8 +1029,8 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnCreate_MajorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup - var rg elasticache.ReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1129,7 +1130,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnUpdate_MinorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -1166,7 +1167,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnUpdate_MinorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -1200,7 +1201,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnUpdate_MinorDown t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -1247,7 +1248,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnUpdate_MajorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -1289,7 +1290,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetEngineVersionOnUpdate_MajorUpgr t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_global_replication_group.test" @@ -1331,7 +1332,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetParameterGroupOnUpdate_NoVersio t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1366,7 +1367,7 @@ func TestAccElastiCacheGlobalReplicationGroup_SetParameterGroupOnUpdate_MinorUpg t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1401,7 +1402,7 @@ func TestAccElastiCacheGlobalReplicationGroup_UpdateParameterGroupName(t *testin t.Skip("skipping long-running test in short mode") } - var globalReplicationGroup elasticache.GlobalReplicationGroup + var globalReplicationGroup awstypes.GlobalReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) primaryReplicationGroupId := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1431,7 +1432,7 @@ func TestAccElastiCacheGlobalReplicationGroup_UpdateParameterGroupName(t *testin }) } -func testAccCheckGlobalReplicationGroupExists(ctx context.Context, resourceName string, v *elasticache.GlobalReplicationGroup) resource.TestCheckFunc { +func testAccCheckGlobalReplicationGroupExists(ctx context.Context, resourceName string, v *awstypes.GlobalReplicationGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -1442,14 +1443,14 @@ func testAccCheckGlobalReplicationGroupExists(ctx context.Context, resourceName return fmt.Errorf("No ElastiCache Global Replication Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) grg, err := tfelasticache.FindGlobalReplicationGroupByID(ctx, conn, rs.Primary.ID) if err != nil { return fmt.Errorf("retrieving ElastiCache Global Replication Group (%s): %w", rs.Primary.ID, err) } - if aws.StringValue(grg.Status) == "deleting" || aws.StringValue(grg.Status) == "deleted" { - return fmt.Errorf("ElastiCache Global Replication Group (%s) exists, but is in a non-available state: %s", rs.Primary.ID, aws.StringValue(grg.Status)) + if aws.ToString(grg.Status) == "deleting" || aws.ToString(grg.Status) == "deleted" { + return fmt.Errorf("ElastiCache Global Replication Group (%s) exists, but is in a non-available state: %s", rs.Primary.ID, aws.ToString(grg.Status)) } *v = *grg @@ -1460,7 +1461,7 @@ func testAccCheckGlobalReplicationGroupExists(ctx context.Context, resourceName func testAccCheckGlobalReplicationGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_global_replication_group" { @@ -1482,13 +1483,13 @@ func testAccCheckGlobalReplicationGroupDestroy(ctx context.Context) resource.Tes } func testAccPreCheckGlobalReplicationGroup(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) input := &elasticache.DescribeGlobalReplicationGroupsInput{} - _, err := conn.DescribeGlobalReplicationGroupsWithContext(ctx, input) + _, err := conn.DescribeGlobalReplicationGroups(ctx, input) if acctest.PreCheckSkipError(err) || - tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidParameterValueException, "Access Denied to API Version: APIGlobalDatastore") { + errs.IsAErrorMessageContains[*awstypes.InvalidParameterValueException](err, "Access Denied to API Version: APIGlobalDatastore") { t.Skipf("skipping acceptance testing: %s", err) } @@ -1497,18 +1498,18 @@ func testAccPreCheckGlobalReplicationGroup(ctx context.Context, t *testing.T) { } } -func testAccMatchReplicationGroupActualVersion(ctx context.Context, j *elasticache.ReplicationGroup, r *regexp.Regexp) resource.TestCheckFunc { +func testAccMatchReplicationGroupActualVersion(ctx context.Context, j *awstypes.ReplicationGroup, r *regexp.Regexp) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) cacheCluster := j.NodeGroups[0].NodeGroupMembers[0] - cluster, err := tfelasticache.FindCacheClusterByID(ctx, conn, aws.StringValue(cacheCluster.CacheClusterId)) + cluster, err := tfelasticache.FindCacheClusterByID(ctx, conn, aws.ToString(cacheCluster.CacheClusterId)) if err != nil { return err } - if !r.MatchString(aws.StringValue(cluster.EngineVersion)) { - return fmt.Errorf("Actual engine version didn't match %q, got %q", r.String(), aws.StringValue(cluster.EngineVersion)) + if !r.MatchString(aws.ToString(cluster.EngineVersion)) { + return fmt.Errorf("Actual engine version didn't match %q, got %q", r.String(), aws.ToString(cluster.EngineVersion)) } return nil } diff --git a/internal/service/elasticache/parameter_group.go b/internal/service/elasticache/parameter_group.go index 28dbb026be6..c4ae8478271 100644 --- a/internal/service/elasticache/parameter_group.go +++ b/internal/service/elasticache/parameter_group.go @@ -10,9 +10,9 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -91,7 +91,8 @@ func resourceParameterGroup() *schema.Resource { func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition name := d.Get(names.AttrName).(string) input := &elasticache.CreateCacheParameterGroupInput{ @@ -101,20 +102,20 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m Tags: getTagsIn(ctx), } - output, err := conn.CreateCacheParameterGroupWithContext(ctx, input) + output, err := conn.CreateCacheParameterGroup(ctx, input) - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { log.Printf("[WARN] failed creating ElastiCache Parameter Group with tags: %s. Trying create without tags.", err) input.Tags = nil - output, err = conn.CreateCacheParameterGroupWithContext(ctx, input) + output, err = conn.CreateCacheParameterGroup(ctx, input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache Parameter Group (%s): %s", name, err) } - d.SetId(aws.StringValue(output.CacheParameterGroup.CacheParameterGroupName)) + d.SetId(aws.ToString(output.CacheParameterGroup.CacheParameterGroupName)) d.Set(names.AttrARN, output.CacheParameterGroup.ARN) return append(diags, resourceParameterGroupUpdate(ctx, d, meta)...) @@ -122,7 +123,7 @@ func resourceParameterGroupCreate(ctx context.Context, d *schema.ResourceData, m func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) parameterGroup, err := findCacheParameterGroupByName(ctx, conn, d.Id()) @@ -147,7 +148,7 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met Source: aws.String("user"), } - output, err := conn.DescribeCacheParametersWithContext(ctx, input) + output, err := conn.DescribeCacheParameters(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading ElastiCache Parameter Group (%s) parameters: %s", d.Id(), err) @@ -160,7 +161,7 @@ func resourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, met func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChange(names.AttrParameter) { o, n := d.GetChange(names.AttrParameter) @@ -171,7 +172,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m const maxParams = 20 for len(toRemove) > 0 { - var paramsToModify []*elasticache.ParameterNameValue + var paramsToModify []*awstypes.ParameterNameValue if len(toRemove) <= maxParams { paramsToModify, toRemove = toRemove[:], nil } else { @@ -194,9 +195,9 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m // above, which may become out of date, here we add logic to // workaround this API behavior - if tfresource.TimedOut(err) || tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidParameterValueException, "Parameter reserved-memory doesn't exist") { + if tfresource.TimedOut(err) || errs.IsAErrorMessageContains[*awstypes.InvalidParameterValueException](err, "Parameter reserved-memory doesn't exist") { for i, paramToModify := range paramsToModify { - if aws.StringValue(paramToModify.ParameterName) != "reserved-memory" { + if aws.ToString(paramToModify.ParameterName) != "reserved-memory" { continue } @@ -211,7 +212,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m tryReservedMemoryPercentageWorkaround := true for _, configuredParameter := range toAdd { - if aws.StringValue(configuredParameter.ParameterName) == "reserved-memory-percent" { + if aws.ToString(configuredParameter.ParameterName) == "reserved-memory-percent" { tryReservedMemoryPercentageWorkaround = false break } @@ -228,7 +229,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m break } - workaroundParams := []*elasticache.ParameterNameValue{ + workaroundParams := []*awstypes.ParameterNameValue{ { ParameterName: aws.String("reserved-memory-percent"), ParameterValue: aws.String("0"), @@ -260,7 +261,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m } for len(toAdd) > 0 { - var paramsToModify []*elasticache.ParameterNameValue + var paramsToModify []*awstypes.ParameterNameValue if len(toAdd) <= maxParams { paramsToModify, toAdd = toAdd[:], nil } else { @@ -279,7 +280,7 @@ func resourceParameterGroupUpdate(ctx context.Context, d *schema.ResourceData, m func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) log.Printf("[INFO] Deleting ElastiCache Parameter Group: %s", d.Id()) if err := deleteParameterGroup(ctx, conn, d.Id()); err != nil { @@ -289,17 +290,17 @@ func resourceParameterGroupDelete(ctx context.Context, d *schema.ResourceData, m return diags } -func deleteParameterGroup(ctx context.Context, conn *elasticache.ElastiCache, name string) error { +func deleteParameterGroup(ctx context.Context, conn *elasticache.Client, name string) error { const ( timeout = 3 * time.Minute ) - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.DeleteCacheParameterGroupWithContext(ctx, &elasticache.DeleteCacheParameterGroupInput{ + _, err := tfresource.RetryWhenIsA[*awstypes.InvalidCacheParameterGroupStateFault](ctx, timeout, func() (interface{}, error) { + return conn.DeleteCacheParameterGroup(ctx, &elasticache.DeleteCacheParameterGroupInput{ CacheParameterGroupName: aws.String(name), }) - }, elasticache.ErrCodeInvalidCacheParameterGroupStateFault) + }) - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheParameterGroupNotFoundFault) { + if errs.IsA[*awstypes.CacheParameterGroupNotFoundFault](err) { return nil } @@ -314,7 +315,7 @@ var ( parameterHash = sdkv2.SimpleSchemaSetFunc(names.AttrName, names.AttrValue) ) -func parameterChanges(o, n interface{}) (remove, addOrUpdate []*elasticache.ParameterNameValue) { +func parameterChanges(o, n interface{}) (remove, addOrUpdate []*awstypes.ParameterNameValue) { if o == nil { o = new(schema.Set) } @@ -324,19 +325,19 @@ func parameterChanges(o, n interface{}) (remove, addOrUpdate []*elasticache.Para os := o.(*schema.Set) ns := n.(*schema.Set) - om := make(map[string]*elasticache.ParameterNameValue, os.Len()) + om := make(map[string]*awstypes.ParameterNameValue, os.Len()) for _, raw := range os.List() { param := raw.(map[string]interface{}) om[param[names.AttrName].(string)] = expandParameter(param) } - nm := make(map[string]*elasticache.ParameterNameValue, len(addOrUpdate)) + nm := make(map[string]*awstypes.ParameterNameValue, len(addOrUpdate)) for _, raw := range ns.List() { param := raw.(map[string]interface{}) nm[param[names.AttrName].(string)] = expandParameter(param) } // Remove: key is in old, but not in new - remove = make([]*elasticache.ParameterNameValue, 0, os.Len()) + remove = make([]*awstypes.ParameterNameValue, 0, os.Len()) for k := range om { if _, ok := nm[k]; !ok { remove = append(remove, om[k]) @@ -344,10 +345,10 @@ func parameterChanges(o, n interface{}) (remove, addOrUpdate []*elasticache.Para } // Add or Update: key is in new, but not in old or has changed value - addOrUpdate = make([]*elasticache.ParameterNameValue, 0, ns.Len()) + addOrUpdate = make([]*awstypes.ParameterNameValue, 0, ns.Len()) for k, nv := range nm { ov, ok := om[k] - if !ok || ok && (aws.StringValue(nv.ParameterValue) != aws.StringValue(ov.ParameterValue)) { + if !ok || ok && (aws.ToString(nv.ParameterValue) != aws.ToString(ov.ParameterValue)) { addOrUpdate = append(addOrUpdate, nm[k]) } } @@ -355,15 +356,15 @@ func parameterChanges(o, n interface{}) (remove, addOrUpdate []*elasticache.Para return remove, addOrUpdate } -func resourceResetParameterGroup(ctx context.Context, conn *elasticache.ElastiCache, name string, parameters []*elasticache.ParameterNameValue) error { +func resourceResetParameterGroup(ctx context.Context, conn *elasticache.Client, name string, parameters []*awstypes.ParameterNameValue) error { input := elasticache.ResetCacheParameterGroupInput{ CacheParameterGroupName: aws.String(name), - ParameterNameValues: parameters, + ParameterNameValues: tfslices.Values(parameters), } return retry.RetryContext(ctx, 30*time.Second, func() *retry.RetryError { - _, err := conn.ResetCacheParameterGroupWithContext(ctx, &input) + _, err := conn.ResetCacheParameterGroup(ctx, &input) if err != nil { - if tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidCacheParameterGroupStateFault, " has pending changes") { + if errs.IsAErrorMessageContains[*awstypes.InvalidCacheParameterGroupStateFault](err, " has pending changes") { return retry.RetryableError(err) } return retry.NonRetryableError(err) @@ -372,79 +373,77 @@ func resourceResetParameterGroup(ctx context.Context, conn *elasticache.ElastiCa }) } -func resourceModifyParameterGroup(ctx context.Context, conn *elasticache.ElastiCache, name string, parameters []*elasticache.ParameterNameValue) error { +func resourceModifyParameterGroup(ctx context.Context, conn *elasticache.Client, name string, parameters []*awstypes.ParameterNameValue) error { input := elasticache.ModifyCacheParameterGroupInput{ CacheParameterGroupName: aws.String(name), - ParameterNameValues: parameters, + ParameterNameValues: tfslices.Values(parameters), } - _, err := conn.ModifyCacheParameterGroupWithContext(ctx, &input) + _, err := conn.ModifyCacheParameterGroup(ctx, &input) return err } -func findCacheParameterGroupByName(ctx context.Context, conn *elasticache.ElastiCache, name string) (*elasticache.CacheParameterGroup, error) { +func findCacheParameterGroupByName(ctx context.Context, conn *elasticache.Client, name string) (*awstypes.CacheParameterGroup, error) { input := &elasticache.DescribeCacheParameterGroupsInput{ CacheParameterGroupName: aws.String(name), } - return findCacheParameterGroup(ctx, conn, input, tfslices.PredicateTrue[*elasticache.CacheParameterGroup]()) + return findCacheParameterGroup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.CacheParameterGroup]()) } -func findCacheParameterGroup(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheParameterGroupsInput, filter tfslices.Predicate[*elasticache.CacheParameterGroup]) (*elasticache.CacheParameterGroup, error) { +func findCacheParameterGroup(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheParameterGroupsInput, filter tfslices.Predicate[*awstypes.CacheParameterGroup]) (*awstypes.CacheParameterGroup, error) { output, err := findCacheParameterGroups(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findCacheParameterGroups(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheParameterGroupsInput, filter tfslices.Predicate[*elasticache.CacheParameterGroup]) ([]*elasticache.CacheParameterGroup, error) { - var output []*elasticache.CacheParameterGroup +func findCacheParameterGroups(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheParameterGroupsInput, filter tfslices.Predicate[*awstypes.CacheParameterGroup]) ([]awstypes.CacheParameterGroup, error) { + var output []awstypes.CacheParameterGroup - err := conn.DescribeCacheParameterGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeCacheParameterGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeCacheParameterGroupsPaginator(conn, input) - for _, v := range page.CacheParameterGroups { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.CacheParameterGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheParameterGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.CacheParameterGroups { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func expandParameter(tfMap map[string]interface{}) *elasticache.ParameterNameValue { - return &elasticache.ParameterNameValue{ +func expandParameter(tfMap map[string]interface{}) *awstypes.ParameterNameValue { + return &awstypes.ParameterNameValue{ ParameterName: aws.String(tfMap[names.AttrName].(string)), ParameterValue: aws.String(tfMap[names.AttrValue].(string)), } } -func flattenParameters(apiObjects []*elasticache.Parameter) []interface{} { +func flattenParameters(apiObjects []awstypes.Parameter) []interface{} { tfList := make([]interface{}, 0, len(apiObjects)) for _, apiObject := range apiObjects { if apiObject.ParameterValue != nil { tfList = append(tfList, map[string]interface{}{ - names.AttrName: strings.ToLower(aws.StringValue(apiObject.ParameterName)), - names.AttrValue: aws.StringValue(apiObject.ParameterValue), + names.AttrName: strings.ToLower(aws.ToString(apiObject.ParameterName)), + names.AttrValue: aws.ToString(apiObject.ParameterValue), }) } } diff --git a/internal/service/elasticache/parameter_group_test.go b/internal/service/elasticache/parameter_group_test.go index d67114f9498..3ca46ae3cb9 100644 --- a/internal/service/elasticache/parameter_group_test.go +++ b/internal/service/elasticache/parameter_group_test.go @@ -9,8 +9,8 @@ import ( "reflect" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -24,7 +24,7 @@ import ( func TestAccElastiCacheParameterGroup_basic(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -56,7 +56,7 @@ func TestAccElastiCacheParameterGroup_basic(t *testing.T) { func TestAccElastiCacheParameterGroup_disappears(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -80,7 +80,7 @@ func TestAccElastiCacheParameterGroup_disappears(t *testing.T) { func TestAccElastiCacheParameterGroup_addParameter(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -128,7 +128,7 @@ func TestAccElastiCacheParameterGroup_addParameter(t *testing.T) { // Regression for https://github.com/hashicorp/terraform-provider-aws/issues/116 func TestAccElastiCacheParameterGroup_removeAllParameters(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -168,7 +168,7 @@ func TestAccElastiCacheParameterGroup_removeAllParameters(t *testing.T) { // This covers our custom logic handling for this situation. func TestAccElastiCacheParameterGroup_RemoveReservedMemoryParameter_allParameters(t *testing.T) { ctx := acctest.Context(t) - var cacheParameterGroup1 elasticache.CacheParameterGroup + var cacheParameterGroup1 awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -209,7 +209,7 @@ func TestAccElastiCacheParameterGroup_RemoveReservedMemoryParameter_allParameter // This covers our custom logic handling for this situation. func TestAccElastiCacheParameterGroup_RemoveReservedMemoryParameter_remainingParameters(t *testing.T) { ctx := acctest.Context(t) - var cacheParameterGroup1 elasticache.CacheParameterGroup + var cacheParameterGroup1 awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -258,7 +258,7 @@ func TestAccElastiCacheParameterGroup_RemoveReservedMemoryParameter_remainingPar // This covers our custom logic handling for this situation. func TestAccElastiCacheParameterGroup_switchReservedMemoryParameter(t *testing.T) { ctx := acctest.Context(t) - var cacheParameterGroup1 elasticache.CacheParameterGroup + var cacheParameterGroup1 awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -303,7 +303,7 @@ func TestAccElastiCacheParameterGroup_switchReservedMemoryParameter(t *testing.T // This covers our custom logic handling for this situation. func TestAccElastiCacheParameterGroup_updateReservedMemoryParameter(t *testing.T) { ctx := acctest.Context(t) - var cacheParameterGroup1 elasticache.CacheParameterGroup + var cacheParameterGroup1 awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -346,7 +346,7 @@ func TestAccElastiCacheParameterGroup_updateReservedMemoryParameter(t *testing.T func TestAccElastiCacheParameterGroup_uppercaseName(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rInt := sdkacctest.RandInt() rName := fmt.Sprintf("TF-ELASTIPG-%d", rInt) @@ -375,7 +375,7 @@ func TestAccElastiCacheParameterGroup_uppercaseName(t *testing.T) { func TestAccElastiCacheParameterGroup_description(t *testing.T) { ctx := acctest.Context(t) - var v elasticache.CacheParameterGroup + var v awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -403,7 +403,7 @@ func TestAccElastiCacheParameterGroup_description(t *testing.T) { func TestAccElastiCacheParameterGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var cacheParameterGroup1 elasticache.CacheParameterGroup + var cacheParameterGroup1 awstypes.CacheParameterGroup resourceName := "aws_elasticache_parameter_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -448,7 +448,7 @@ func TestAccElastiCacheParameterGroup_tags(t *testing.T) { func testAccCheckParameterGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_parameter_group" { @@ -472,7 +472,7 @@ func testAccCheckParameterGroupDestroy(ctx context.Context) resource.TestCheckFu } } -func testAccCheckParameterGroupExists(ctx context.Context, n string, v *elasticache.CacheParameterGroup) resource.TestCheckFunc { +func testAccCheckParameterGroupExists(ctx context.Context, n string, v *awstypes.CacheParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -483,7 +483,7 @@ func testAccCheckParameterGroupExists(ctx context.Context, n string, v *elastica return fmt.Errorf("No ElastiCache Parameter Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindCacheParameterGroupByName(ctx, conn, rs.Primary.ID) @@ -497,7 +497,7 @@ func testAccCheckParameterGroupExists(ctx context.Context, n string, v *elastica } } -func testAccCheckParameterGroupAttributes(v *elasticache.CacheParameterGroup, rName string) resource.TestCheckFunc { +func testAccCheckParameterGroupAttributes(v *awstypes.CacheParameterGroup, rName string) resource.TestCheckFunc { return func(s *terraform.State) error { if *v.CacheParameterGroupName != rName { return fmt.Errorf("bad name: %#v", v.CacheParameterGroupName) @@ -597,15 +597,15 @@ func TestParameterChanges(t *testing.T) { Name string Old *schema.Set New *schema.Set - ExpectedRemove []*elasticache.ParameterNameValue - ExpectedAddOrUpdate []*elasticache.ParameterNameValue + ExpectedRemove []*awstypes.ParameterNameValue + ExpectedAddOrUpdate []*awstypes.ParameterNameValue }{ { Name: "Empty", Old: new(schema.Set), New: new(schema.Set), - ExpectedRemove: []*elasticache.ParameterNameValue{}, - ExpectedAddOrUpdate: []*elasticache.ParameterNameValue{}, + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Remove all", @@ -616,13 +616,13 @@ func TestParameterChanges(t *testing.T) { }, }), New: new(schema.Set), - ExpectedRemove: []*elasticache.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("reserved-memory"), ParameterValue: aws.String(acctest.Ct0), }, }, - ExpectedAddOrUpdate: []*elasticache.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "No change", @@ -638,8 +638,8 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: acctest.Ct0, }, }), - ExpectedRemove: []*elasticache.ParameterNameValue{}, - ExpectedAddOrUpdate: []*elasticache.ParameterNameValue{}, + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Remove partial", @@ -659,13 +659,13 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: "yes", }, }), - ExpectedRemove: []*elasticache.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("reserved-memory"), ParameterValue: aws.String(acctest.Ct0), }, }, - ExpectedAddOrUpdate: []*elasticache.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{}, }, { Name: "Add to existing", @@ -685,8 +685,8 @@ func TestParameterChanges(t *testing.T) { names.AttrValue: "always", }, }), - ExpectedRemove: []*elasticache.ParameterNameValue{}, - ExpectedAddOrUpdate: []*elasticache.ParameterNameValue{ + ExpectedRemove: []*awstypes.ParameterNameValue{}, + ExpectedAddOrUpdate: []*awstypes.ParameterNameValue{ { ParameterName: aws.String("appendfsync"), ParameterValue: aws.String("always"), diff --git a/internal/service/elasticache/replication_group.go b/internal/service/elasticache/replication_group.go index 9920ba80e82..2480dea7fb4 100644 --- a/internal/service/elasticache/replication_group.go +++ b/internal/service/elasticache/replication_group.go @@ -12,9 +12,9 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "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" "github.com/hashicorp/terraform-provider-aws/internal/flex" @@ -72,10 +73,10 @@ func resourceReplicationGroup() *schema.Resource { ConflictsWith: []string{"user_group_ids"}, }, "auth_token_update_strategy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(elasticache.AuthTokenUpdateStrategyType_Values(), true), - Default: elasticache.AuthTokenUpdateStrategyTypeRotate, + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[awstypes.AuthTokenUpdateStrategyType](), + Default: awstypes.AuthTokenUpdateStrategyTypeRotate, }, names.AttrAutoMinorVersionUpgrade: { Type: nullable.TypeNullableBool, @@ -149,10 +150,10 @@ func resourceReplicationGroup() *schema.Resource { }, }, "ip_discovery": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(elasticache.IpDiscovery_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.IpDiscovery](), }, names.AttrKMSKeyID: { Type: schema.TypeString, @@ -166,23 +167,23 @@ func resourceReplicationGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "destination_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.DestinationType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.DestinationType](), }, names.AttrDestination: { Type: schema.TypeString, Required: true, }, "log_format": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogFormat_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogFormat](), }, "log_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogType](), }, }, }, @@ -208,11 +209,11 @@ func resourceReplicationGroup() *schema.Resource { Default: false, }, "network_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(elasticache.NetworkType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.NetworkType](), }, "node_type": { Type: schema.TypeString, @@ -339,10 +340,10 @@ func resourceReplicationGroup() *schema.Resource { Computed: true, }, "transit_encryption_mode": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(elasticache.TransitEncryptionMode_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.TransitEncryptionMode](), }, "user_group_ids": { Type: schema.TypeSet, @@ -398,7 +399,8 @@ func resourceReplicationGroup() *schema.Resource { func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition replicationGroupID := d.Get("replication_group_id").(string) input := &elasticache.CreateReplicationGroupInput{ @@ -446,7 +448,7 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("ip_discovery"); ok { - input.IpDiscovery = aws.String(v.(string)) + input.IpDiscovery = awstypes.IpDiscovery(v.(string)) } if v, ok := d.GetOk(names.AttrKMSKeyID); ok { @@ -460,8 +462,8 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, continue } - apiObject := expandLogDeliveryConfigurations(tfMap) - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &apiObject) + apiObject := expandLogDeliveryConfigurationRequests(tfMap) + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, apiObject) } } @@ -474,7 +476,7 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("network_type"); ok { - input.NetworkType = aws.String(v.(string)) + input.NetworkType = awstypes.NetworkType(v.(string)) } if v, ok := d.GetOk("notification_topic_arn"); ok { @@ -482,11 +484,11 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("num_cache_clusters"); ok { - input.NumCacheClusters = aws.Int64(int64(v.(int))) + input.NumCacheClusters = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("num_node_groups"); ok && v != 0 { - input.NumNodeGroups = aws.Int64(int64(v.(int))) + input.NumNodeGroups = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk(names.AttrParameterGroupName); ok { @@ -494,15 +496,15 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } 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_cache_cluster_azs"); ok && len(v.([]interface{})) > 0 { - input.PreferredCacheClusterAZs = flex.ExpandStringList(v.([]interface{})) + input.PreferredCacheClusterAZs = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := d.GetOk("replicas_per_node_group"); ok { - input.ReplicasPerNodeGroup = aws.Int64(int64(v.(int))) + input.ReplicasPerNodeGroup = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("subnet_group_name"); ok { @@ -510,15 +512,15 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk(names.AttrSecurityGroupIDs); ok && v.(*schema.Set).Len() > 0 { - input.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroupIds = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("security_group_names"); ok && v.(*schema.Set).Len() > 0 { - input.CacheSecurityGroupNames = flex.ExpandStringSet(v.(*schema.Set)) + input.CacheSecurityGroupNames = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("snapshot_arns"); ok && v.(*schema.Set).Len() > 0 { - input.SnapshotArns = flex.ExpandStringSet(v.(*schema.Set)) + input.SnapshotArns = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("snapshot_name"); ok { @@ -526,7 +528,7 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("snapshot_retention_limit"); ok { - input.SnapshotRetentionLimit = aws.Int64(int64(v.(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("snapshot_window"); ok { @@ -538,27 +540,27 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("transit_encryption_mode"); ok { - input.TransitEncryptionMode = aws.String(v.(string)) + input.TransitEncryptionMode = awstypes.TransitEncryptionMode(v.(string)) } if v, ok := d.GetOk("user_group_ids"); ok && v.(*schema.Set).Len() > 0 { - input.UserGroupIds = flex.ExpandStringSet(v.(*schema.Set)) + input.UserGroupIds = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateReplicationGroupWithContext(ctx, input) + output, err := conn.CreateReplicationGroup(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.Tags = nil - output, err = conn.CreateReplicationGroupWithContext(ctx, input) + output, err = conn.CreateReplicationGroup(ctx, input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache Replication Group (%s): %s", replicationGroupID, err) } - d.SetId(aws.StringValue(output.ReplicationGroup.ReplicationGroupId)) + d.SetId(aws.ToString(output.ReplicationGroup.ReplicationGroupId)) const ( delay = 30 * time.Second @@ -579,10 +581,10 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, // For partitions not supporting tag-on-create, attempt tag after create. if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 { - err := createTags(ctx, conn, aws.StringValue(output.ReplicationGroup.ARN), tags) + err := createTags(ctx, conn, aws.ToString(output.ReplicationGroup.ARN), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceReplicationGroupRead(ctx, d, meta)...) } @@ -596,7 +598,7 @@ func resourceReplicationGroupCreate(ctx context.Context, d *schema.ResourceData, func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) rgp, err := findReplicationGroupByID(ctx, conn, d.Id()) @@ -610,7 +612,7 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): %s", d.Id(), err) } - if aws.StringValue(rgp.Status) == replicationGroupStatusDeleting { + if aws.ToString(rgp.Status) == replicationGroupStatusDeleting { log.Printf("[WARN] ElastiCache Replication Group (%s) is currently in the `deleting` status, removing from state", d.Id()) d.SetId("") return diags @@ -620,32 +622,28 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m d.Set("global_replication_group_id", rgp.GlobalReplicationGroupInfo.GlobalReplicationGroupId) } - if rgp.AutomaticFailover != nil { - switch strings.ToLower(aws.StringValue(rgp.AutomaticFailover)) { - case elasticache.AutomaticFailoverStatusDisabled, elasticache.AutomaticFailoverStatusDisabling: - d.Set("automatic_failover_enabled", false) - case elasticache.AutomaticFailoverStatusEnabled, elasticache.AutomaticFailoverStatusEnabling: - d.Set("automatic_failover_enabled", true) - default: - log.Printf("Unknown AutomaticFailover state %q", aws.StringValue(rgp.AutomaticFailover)) - } + switch rgp.AutomaticFailover { + case awstypes.AutomaticFailoverStatusDisabled, awstypes.AutomaticFailoverStatusDisabling: + d.Set("automatic_failover_enabled", false) + case awstypes.AutomaticFailoverStatusEnabled, awstypes.AutomaticFailoverStatusEnabling: + d.Set("automatic_failover_enabled", true) + default: + log.Printf("Unknown AutomaticFailover state %q", string(rgp.AutomaticFailover)) } - if rgp.MultiAZ != nil { - switch strings.ToLower(aws.StringValue(rgp.MultiAZ)) { - case elasticache.MultiAZStatusEnabled: - d.Set("multi_az_enabled", true) - case elasticache.MultiAZStatusDisabled: - d.Set("multi_az_enabled", false) - default: - log.Printf("Unknown MultiAZ state %q", aws.StringValue(rgp.MultiAZ)) - } + switch rgp.MultiAZ { + case awstypes.MultiAZStatusEnabled: + d.Set("multi_az_enabled", true) + case awstypes.MultiAZStatusDisabled: + d.Set("multi_az_enabled", false) + default: + log.Printf("Unknown MultiAZ state %q", string(rgp.MultiAZ)) } d.Set(names.AttrKMSKeyID, rgp.KmsKeyId) d.Set(names.AttrDescription, rgp.Description) d.Set("num_cache_clusters", len(rgp.MemberClusters)) - if err := d.Set("member_clusters", flex.FlattenStringSet(rgp.MemberClusters)); err != nil { + if err := d.Set("member_clusters", flex.FlattenStringValueSet(rgp.MemberClusters)); err != nil { return sdkdiag.AppendErrorf(diags, "setting member_clusters: %s", err) } @@ -655,7 +653,7 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m d.Set("cluster_enabled", rgp.ClusterEnabled) d.Set("replication_group_id", rgp.ReplicationGroupId) d.Set(names.AttrARN, rgp.ARN) - d.Set("data_tiering_enabled", aws.StringValue(rgp.DataTiering) == elasticache.DataTieringStatusEnabled) + d.Set("data_tiering_enabled", rgp.DataTiering == awstypes.DataTieringStatusEnabled) d.Set("ip_discovery", rgp.IpDiscovery) d.Set("network_type", rgp.NetworkType) @@ -689,40 +687,41 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m const ( delay = 0 * time.Second ) - _, err = waitReplicationGroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate), delay) - if err != nil { - return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group to be available (%s): %s", aws.StringValue(rgp.ARN), err) + if _, err := waitReplicationGroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate), delay); err != nil { + return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group (%s) create: %s", aws.ToString(rgp.ARN), err) } log.Printf("[DEBUG] ElastiCache Replication Group (%s): Checking underlying cache clusters", d.Id()) // This section reads settings that require checking the underlying cache clusters - if rgp.NodeGroups != nil && rgp.NodeGroups[0] != nil && len(rgp.NodeGroups[0].NodeGroupMembers) != 0 { + if rgp.NodeGroups != nil && len(rgp.NodeGroups[0].NodeGroupMembers) != 0 { cacheCluster := rgp.NodeGroups[0].NodeGroupMembers[0] - - res, err := conn.DescribeCacheClustersWithContext(ctx, &elasticache.DescribeCacheClustersInput{ + input := &elasticache.DescribeCacheClustersInput{ CacheClusterId: cacheCluster.CacheClusterId, ShowCacheNodeInfo: aws.Bool(true), - }) + } + + output, err := conn.DescribeCacheClusters(ctx, input) + if err != nil { - return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): reading Cache Cluster (%s): %s", d.Id(), aws.StringValue(cacheCluster.CacheClusterId), err) + return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): reading Cache Cluster (%s): %s", d.Id(), aws.ToString(cacheCluster.CacheClusterId), err) } - if len(res.CacheClusters) == 0 { + if len(output.CacheClusters) == 0 { return diags } - c := res.CacheClusters[0] + c := output.CacheClusters[0] - if err := setFromCacheCluster(d, c); err != nil { - return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): reading Cache Cluster (%s): %s", d.Id(), aws.StringValue(cacheCluster.CacheClusterId), err) + if err := setFromCacheCluster(d, &c); err != nil { + return sdkdiag.AppendErrorf(diags, "reading ElastiCache Replication Group (%s): reading Cache Cluster (%s): %s", d.Id(), aws.ToString(cacheCluster.CacheClusterId), err) } d.Set("at_rest_encryption_enabled", c.AtRestEncryptionEnabled) d.Set("transit_encryption_enabled", c.TransitEncryptionEnabled) d.Set("transit_encryption_mode", c.TransitEncryptionMode) - if c.AuthTokenEnabled != nil && !aws.BoolValue(c.AuthTokenEnabled) { + if c.AuthTokenEnabled != nil && !aws.ToBool(c.AuthTokenEnabled) { d.Set("auth_token", nil) } } @@ -732,7 +731,7 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { o, n := d.GetChange("num_cache_clusters") @@ -781,29 +780,29 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, } if d.HasChange("ip_discovery") { - input.IpDiscovery = aws.String(d.Get("ip_discovery").(string)) + input.IpDiscovery = awstypes.IpDiscovery(d.Get("ip_discovery").(string)) requestUpdate = true } if d.HasChange("log_delivery_configuration") { o, n := d.GetChange("log_delivery_configuration") - input.LogDeliveryConfigurations = []*elasticache.LogDeliveryConfigurationRequest{} - logTypesToSubmit := make(map[string]bool) + input.LogDeliveryConfigurations = []awstypes.LogDeliveryConfigurationRequest{} + logTypesToSubmit := make(map[awstypes.LogType]bool) currentLogDeliveryConfig := n.(*schema.Set).List() for _, current := range currentLogDeliveryConfig { - logDeliveryConfigurationRequest := expandLogDeliveryConfigurations(current.(map[string]interface{})) - logTypesToSubmit[*logDeliveryConfigurationRequest.LogType] = true - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &logDeliveryConfigurationRequest) + logDeliveryConfigurationRequest := expandLogDeliveryConfigurationRequests(current.(map[string]interface{})) + logTypesToSubmit[logDeliveryConfigurationRequest.LogType] = true + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, logDeliveryConfigurationRequest) } previousLogDeliveryConfig := o.(*schema.Set).List() for _, previous := range previousLogDeliveryConfig { - logDeliveryConfigurationRequest := expandEmptyLogDeliveryConfigurations(previous.(map[string]interface{})) + logDeliveryConfigurationRequest := expandEmptyLogDeliveryConfigurationRequest(previous.(map[string]interface{})) //if something was removed, send an empty request - if !logTypesToSubmit[*logDeliveryConfigurationRequest.LogType] { - input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, &logDeliveryConfigurationRequest) + if !logTypesToSubmit[logDeliveryConfigurationRequest.LogType] { + input.LogDeliveryConfigurations = append(input.LogDeliveryConfigurations, logDeliveryConfigurationRequest) } } @@ -821,7 +820,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, } if d.HasChange("network_type") { - input.IpDiscovery = aws.String(d.Get("network_type").(string)) + input.IpDiscovery = awstypes.IpDiscovery(d.Get("network_type").(string)) requestUpdate = true } @@ -842,14 +841,14 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, if d.HasChange(names.AttrSecurityGroupIDs) { if v, ok := d.GetOk(names.AttrSecurityGroupIDs); ok && v.(*schema.Set).Len() > 0 { - input.SecurityGroupIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroupIds = flex.ExpandStringValueSet(v.(*schema.Set)) requestUpdate = true } } if d.HasChange("security_group_names") { if v, ok := d.GetOk("security_group_names"); ok && v.(*schema.Set).Len() > 0 { - input.CacheSecurityGroupNames = flex.ExpandStringSet(v.(*schema.Set)) + input.CacheSecurityGroupNames = flex.ExpandStringValueSet(v.(*schema.Set)) requestUpdate = true } } @@ -861,7 +860,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, input.SnapshottingClusterId = aws.String(fmt.Sprintf("%s-001", d.Id())) } - input.SnapshotRetentionLimit = aws.Int64(int64(d.Get("snapshot_retention_limit").(int))) + input.SnapshotRetentionLimit = aws.Int32(int32(d.Get("snapshot_retention_limit").(int))) requestUpdate = true } @@ -876,7 +875,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, } if d.HasChange("transit_encryption_mode") { - input.TransitEncryptionMode = aws.String(d.Get("transit_encryption_mode").(string)) + input.TransitEncryptionMode = awstypes.TransitEncryptionMode(d.Get("transit_encryption_mode").(string)) requestUpdate = true } @@ -886,12 +885,12 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, add, del := ns.Difference(os), os.Difference(ns) if add.Len() > 0 { - input.UserGroupIdsToAdd = flex.ExpandStringSet(add) + input.UserGroupIdsToAdd = flex.ExpandStringValueSet(add) requestUpdate = true } if del.Len() > 0 { - input.UserGroupIdsToRemove = flex.ExpandStringSet(del) + input.UserGroupIdsToRemove = flex.ExpandStringValueSet(del) requestUpdate = true } } @@ -905,7 +904,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group (%s) update: %s", d.Id(), err) } - _, err := conn.ModifyReplicationGroupWithContext(ctx, input) + _, err := conn.ModifyReplicationGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying ElastiCache Replication Group (%s): %s", d.Id(), err) @@ -920,7 +919,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, input := &elasticache.ModifyReplicationGroupInput{ ApplyImmediately: aws.Bool(true), AuthToken: aws.String(d.Get("auth_token").(string)), - AuthTokenUpdateStrategy: aws.String(d.Get("auth_token_update_strategy").(string)), + AuthTokenUpdateStrategy: awstypes.AuthTokenUpdateStrategyType(d.Get("auth_token_update_strategy").(string)), ReplicationGroupId: aws.String(d.Id()), } @@ -932,7 +931,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache Replication Group (%s) update: %s", d.Id(), err) } - _, err := conn.ModifyReplicationGroupWithContext(ctx, input) + _, err := conn.ModifyReplicationGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "modifying ElastiCache Replication Group (%s) authentication: %s", d.Id(), err) @@ -957,7 +956,7 @@ func resourceReplicationGroupUpdate(ctx context.Context, d *schema.ResourceData, func resourceReplicationGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) v, hasGlobalReplicationGroupID := d.GetOk("global_replication_group_id") if hasGlobalReplicationGroupID { @@ -980,12 +979,12 @@ func resourceReplicationGroupDelete(ctx context.Context, d *schema.ResourceData, timeout = 10 * time.Minute // 10 minutes should give any creating/deleting cache clusters or snapshots time to complete. ) log.Printf("[INFO] Deleting ElastiCache Replication Group: %s", d.Id()) - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.DeleteReplicationGroupWithContext(ctx, input) - }, elasticache.ErrCodeInvalidReplicationGroupStateFault) + _, err := tfresource.RetryWhenIsA[*awstypes.InvalidReplicationGroupStateFault](ctx, timeout, func() (interface{}, error) { + return conn.DeleteReplicationGroup(ctx, input) + }) switch { - case tfawserr.ErrCodeEquals(err, elasticache.ErrCodeReplicationGroupNotFoundFault): + case errs.IsA[*awstypes.ReplicationGroupNotFoundFault](err): case err != nil: return sdkdiag.AppendErrorf(diags, "deleting ElastiCache Replication Group (%s): %s", d.Id(), err) default: @@ -1005,22 +1004,22 @@ func resourceReplicationGroupDelete(ctx context.Context, d *schema.ResourceData, return diags } -func disassociateReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroupID, replicationGroupID, region string, timeout time.Duration) error { +func disassociateReplicationGroup(ctx context.Context, conn *elasticache.Client, globalReplicationGroupID, replicationGroupID, region string, timeout time.Duration) error { input := &elasticache.DisassociateGlobalReplicationGroupInput{ GlobalReplicationGroupId: aws.String(globalReplicationGroupID), ReplicationGroupId: aws.String(replicationGroupID), ReplicationGroupRegion: aws.String(region), } - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, timeout, func() (interface{}, error) { - return conn.DisassociateGlobalReplicationGroupWithContext(ctx, input) - }, elasticache.ErrCodeInvalidGlobalReplicationGroupStateFault) + _, err := tfresource.RetryWhenIsA[*awstypes.InvalidGlobalReplicationGroupStateFault](ctx, timeout, func() (interface{}, error) { + return conn.DisassociateGlobalReplicationGroup(ctx, input) + }) - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeGlobalReplicationGroupNotFoundFault) { + if errs.IsA[*awstypes.GlobalReplicationGroupNotFoundFault](err) { return nil } - if tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidParameterValueException, "is not associated with Global Replication Group") { + if errs.IsAErrorMessageContains[*awstypes.InvalidParameterValueException](err, "is not associated with Global Replication Group") { return nil } @@ -1035,7 +1034,7 @@ func disassociateReplicationGroup(ctx context.Context, conn *elasticache.ElastiC return nil } -func modifyReplicationGroupShardConfiguration(ctx context.Context, conn *elasticache.ElastiCache, d *schema.ResourceData) error { +func modifyReplicationGroupShardConfiguration(ctx context.Context, conn *elasticache.Client, d *schema.ResourceData) error { if d.HasChange("num_node_groups") { if err := modifyReplicationGroupShardConfigurationNumNodeGroups(ctx, conn, d, "num_node_groups"); err != nil { return err @@ -1051,13 +1050,13 @@ func modifyReplicationGroupShardConfiguration(ctx context.Context, conn *elastic return nil } -func modifyReplicationGroupShardConfigurationNumNodeGroups(ctx context.Context, conn *elasticache.ElastiCache, d *schema.ResourceData, argument string) error { +func modifyReplicationGroupShardConfigurationNumNodeGroups(ctx context.Context, conn *elasticache.Client, d *schema.ResourceData, argument string) error { o, n := d.GetChange(argument) oldNodeGroupCount, newNodeGroupCount := o.(int), n.(int) input := &elasticache.ModifyReplicationGroupShardConfigurationInput{ ApplyImmediately: aws.Bool(true), - NodeGroupCount: aws.Int64(int64(newNodeGroupCount)), + NodeGroupCount: aws.Int32(int32(newNodeGroupCount)), ReplicationGroupId: aws.String(d.Id()), } @@ -1069,10 +1068,10 @@ func modifyReplicationGroupShardConfigurationNumNodeGroups(ctx context.Context, nodeGroupID := fmt.Sprintf("%04d", i) nodeGroupsToRemove = append(nodeGroupsToRemove, nodeGroupID) } - input.NodeGroupsToRemove = aws.StringSlice(nodeGroupsToRemove) + input.NodeGroupsToRemove = nodeGroupsToRemove } - _, err := conn.ModifyReplicationGroupShardConfigurationWithContext(ctx, input) + _, err := conn.ModifyReplicationGroupShardConfiguration(ctx, input) if err != nil { return fmt.Errorf("modifying ElastiCache Replication Group (%s) shard configuration: %w", d.Id(), err) @@ -1088,18 +1087,18 @@ func modifyReplicationGroupShardConfigurationNumNodeGroups(ctx context.Context, return nil } -func modifyReplicationGroupShardConfigurationReplicasPerNodeGroup(ctx context.Context, conn *elasticache.ElastiCache, d *schema.ResourceData, argument string) error { +func modifyReplicationGroupShardConfigurationReplicasPerNodeGroup(ctx context.Context, conn *elasticache.Client, d *schema.ResourceData, argument string) error { o, n := d.GetChange(argument) oldReplicaCount, newReplicaCount := o.(int), n.(int) if newReplicaCount > oldReplicaCount { input := &elasticache.IncreaseReplicaCountInput{ ApplyImmediately: aws.Bool(true), - NewReplicaCount: aws.Int64(int64(newReplicaCount)), + NewReplicaCount: aws.Int32(int32(newReplicaCount)), ReplicationGroupId: aws.String(d.Id()), } - _, err := conn.IncreaseReplicaCountWithContext(ctx, input) + _, err := conn.IncreaseReplicaCount(ctx, input) if err != nil { return fmt.Errorf("increasing ElastiCache Replication Group (%s) replica count (%d): %w", d.Id(), newReplicaCount, err) @@ -1114,11 +1113,11 @@ func modifyReplicationGroupShardConfigurationReplicasPerNodeGroup(ctx context.Co } else if newReplicaCount < oldReplicaCount { input := &elasticache.DecreaseReplicaCountInput{ ApplyImmediately: aws.Bool(true), - NewReplicaCount: aws.Int64(int64(newReplicaCount)), + NewReplicaCount: aws.Int32(int32(newReplicaCount)), ReplicationGroupId: aws.String(d.Id()), } - _, err := conn.DecreaseReplicaCountWithContext(ctx, input) + _, err := conn.DecreaseReplicaCount(ctx, input) if err != nil { return fmt.Errorf("decreasing ElastiCache Replication Group (%s) replica count (%d): %w", d.Id(), newReplicaCount, err) @@ -1135,14 +1134,14 @@ func modifyReplicationGroupShardConfigurationReplicasPerNodeGroup(ctx context.Co return nil } -func increaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, newReplicaCount int, timeout time.Duration) error { +func increaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache.Client, replicationGroupID string, newReplicaCount int, timeout time.Duration) error { input := &elasticache.IncreaseReplicaCountInput{ ApplyImmediately: aws.Bool(true), - NewReplicaCount: aws.Int64(int64(newReplicaCount - 1)), + NewReplicaCount: aws.Int32(int32(newReplicaCount - 1)), ReplicationGroupId: aws.String(replicationGroupID), } - _, err := conn.IncreaseReplicaCountWithContext(ctx, input) + _, err := conn.IncreaseReplicaCount(ctx, input) if err != nil { return fmt.Errorf("increasing ElastiCache Replication Group (%s) replica count (%d): %w", replicationGroupID, newReplicaCount-1, err) @@ -1155,14 +1154,14 @@ func increaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache return nil } -func decreaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, newReplicaCount int, timeout time.Duration) error { +func decreaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache.Client, replicationGroupID string, newReplicaCount int, timeout time.Duration) error { input := &elasticache.DecreaseReplicaCountInput{ ApplyImmediately: aws.Bool(true), - NewReplicaCount: aws.Int64(int64(newReplicaCount - 1)), + NewReplicaCount: aws.Int32(int32(newReplicaCount - 1)), ReplicationGroupId: aws.String(replicationGroupID), } - _, err := conn.DecreaseReplicaCountWithContext(ctx, input) + _, err := conn.DecreaseReplicaCount(ctx, input) if err != nil { return fmt.Errorf("decreasing ElastiCache Replication Group (%s) replica count (%d): %w", replicationGroupID, newReplicaCount-1, err) @@ -1175,56 +1174,54 @@ func decreaseReplicationGroupReplicaCount(ctx context.Context, conn *elasticache return nil } -func findReplicationGroupByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.ReplicationGroup, error) { +func findReplicationGroupByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.ReplicationGroup, error) { input := &elasticache.DescribeReplicationGroupsInput{ ReplicationGroupId: aws.String(id), } - return findReplicationGroup(ctx, conn, input, tfslices.PredicateTrue[*elasticache.ReplicationGroup]()) + return findReplicationGroup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.ReplicationGroup]()) } -func findReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeReplicationGroupsInput, filter tfslices.Predicate[*elasticache.ReplicationGroup]) (*elasticache.ReplicationGroup, error) { +func findReplicationGroup(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeReplicationGroupsInput, filter tfslices.Predicate[*awstypes.ReplicationGroup]) (*awstypes.ReplicationGroup, error) { output, err := findReplicationGroups(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findReplicationGroups(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeReplicationGroupsInput, filter tfslices.Predicate[*elasticache.ReplicationGroup]) ([]*elasticache.ReplicationGroup, error) { - var output []*elasticache.ReplicationGroup +func findReplicationGroups(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeReplicationGroupsInput, filter tfslices.Predicate[*awstypes.ReplicationGroup]) ([]awstypes.ReplicationGroup, error) { + var output []awstypes.ReplicationGroup - err := conn.DescribeReplicationGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeReplicationGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeReplicationGroupsPaginator(conn, input) - for _, v := range page.ReplicationGroups { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.ReplicationGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeReplicationGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.ReplicationGroups { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func statusReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string) retry.StateRefreshFunc { +func statusReplicationGroup(ctx context.Context, conn *elasticache.Client, replicationGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findReplicationGroupByID(ctx, conn, replicationGroupID) @@ -1236,7 +1233,7 @@ func statusReplicationGroup(ctx context.Context, conn *elasticache.ElastiCache, return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } @@ -1249,7 +1246,7 @@ const ( replicationGroupStatusSnapshotting = "snapshotting" ) -func waitReplicationGroupAvailable(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, timeout time.Duration, delay time.Duration) (*elasticache.ReplicationGroup, error) { +func waitReplicationGroupAvailable(ctx context.Context, conn *elasticache.Client, replicationGroupID string, timeout time.Duration, delay time.Duration) (*awstypes.ReplicationGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ replicationGroupStatusCreating, @@ -1265,14 +1262,14 @@ func waitReplicationGroupAvailable(ctx context.Context, conn *elasticache.Elasti outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.ReplicationGroup); ok { + if output, ok := outputRaw.(*awstypes.ReplicationGroup); ok { return output, err } return nil, err } -func waitReplicationGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, timeout time.Duration) (*elasticache.ReplicationGroup, error) { +func waitReplicationGroupDeleted(ctx context.Context, conn *elasticache.Client, replicationGroupID string, timeout time.Duration) (*awstypes.ReplicationGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{ replicationGroupStatusCreating, @@ -1288,23 +1285,22 @@ func waitReplicationGroupDeleted(ctx context.Context, conn *elasticache.ElastiCa outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.ReplicationGroup); ok { + if output, ok := outputRaw.(*awstypes.ReplicationGroup); ok { return output, err } return nil, err } -func findReplicationGroupMemberClustersByID(ctx context.Context, conn *elasticache.ElastiCache, id string) ([]*elasticache.CacheCluster, error) { +func findReplicationGroupMemberClustersByID(ctx context.Context, conn *elasticache.Client, id string) ([]awstypes.CacheCluster, error) { rg, err := findReplicationGroupByID(ctx, conn, id) if err != nil { return nil, err } - - ids := aws.StringValueSlice(rg.MemberClusters) - clusters, err := findCacheClusters(ctx, conn, &elasticache.DescribeCacheClustersInput{}, func(v *elasticache.CacheCluster) bool { - return slices.Contains(ids, aws.StringValue(v.CacheClusterId)) + ids := rg.MemberClusters + clusters, err := findCacheClusters(ctx, conn, &elasticache.DescribeCacheClustersInput{}, func(v *awstypes.CacheCluster) bool { + return slices.Contains(ids, aws.ToString(v.CacheClusterId)) }) if err != nil { @@ -1320,7 +1316,7 @@ func findReplicationGroupMemberClustersByID(ctx context.Context, conn *elasticac // statusReplicationGroupMemberClusters fetches the Replication Group's Member Clusters and either "available" or the first non-"available" status. // NOTE: This function assumes that the intended end-state is to have all member clusters in "available" status. -func statusReplicationGroupMemberClusters(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string) retry.StateRefreshFunc { +func statusReplicationGroupMemberClusters(ctx context.Context, conn *elasticache.Client, replicationGroupID string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findReplicationGroupMemberClustersByID(ctx, conn, replicationGroupID) @@ -1334,7 +1330,7 @@ func statusReplicationGroupMemberClusters(ctx context.Context, conn *elasticache status := cacheClusterStatusAvailable for _, v := range output { - if clusterStatus := aws.StringValue(v.CacheClusterStatus); clusterStatus != cacheClusterStatusAvailable { + if clusterStatus := aws.ToString(v.CacheClusterStatus); clusterStatus != cacheClusterStatusAvailable { status = clusterStatus break } @@ -1344,7 +1340,7 @@ func statusReplicationGroupMemberClusters(ctx context.Context, conn *elasticache } } -func waitReplicationGroupMemberClustersAvailable(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, timeout time.Duration) ([]*elasticache.CacheCluster, error) { //nolint:unparam +func waitReplicationGroupMemberClustersAvailable(ctx context.Context, conn *elasticache.Client, replicationGroupID string, timeout time.Duration) ([]*awstypes.CacheCluster, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{ cacheClusterStatusCreating, @@ -1361,7 +1357,7 @@ func waitReplicationGroupMemberClustersAvailable(ctx context.Context, conn *elas outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.([]*elasticache.CacheCluster); ok { + if output, ok := outputRaw.([]*awstypes.CacheCluster); ok { return output, err } diff --git a/internal/service/elasticache/replication_group_data_source.go b/internal/service/elasticache/replication_group_data_source.go index 0c03edb9c24..f582054f0f2 100644 --- a/internal/service/elasticache/replication_group_data_source.go +++ b/internal/service/elasticache/replication_group_data_source.go @@ -6,10 +6,9 @@ package elasticache import ( "context" "log" - "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -124,7 +123,7 @@ func dataSourceReplicationGroup() *schema.Resource { func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) groupID := d.Get("replication_group_id").(string) @@ -134,29 +133,25 @@ func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("ElastiCache Replication Group", err)) } - d.SetId(aws.StringValue(rg.ReplicationGroupId)) + d.SetId(aws.ToString(rg.ReplicationGroupId)) d.Set(names.AttrDescription, rg.Description) d.Set(names.AttrARN, rg.ARN) d.Set("auth_token_enabled", rg.AuthTokenEnabled) - if rg.AutomaticFailover != nil { - switch aws.StringValue(rg.AutomaticFailover) { - case elasticache.AutomaticFailoverStatusDisabled, elasticache.AutomaticFailoverStatusDisabling: - d.Set("automatic_failover_enabled", false) - case elasticache.AutomaticFailoverStatusEnabled, elasticache.AutomaticFailoverStatusEnabling: - d.Set("automatic_failover_enabled", true) - } + switch rg.AutomaticFailover { + case awstypes.AutomaticFailoverStatusDisabled, awstypes.AutomaticFailoverStatusDisabling: + d.Set("automatic_failover_enabled", false) + case awstypes.AutomaticFailoverStatusEnabled, awstypes.AutomaticFailoverStatusEnabling: + d.Set("automatic_failover_enabled", true) } - if rg.MultiAZ != nil { - switch strings.ToLower(aws.StringValue(rg.MultiAZ)) { - case elasticache.MultiAZStatusEnabled: - d.Set("multi_az_enabled", true) - case elasticache.MultiAZStatusDisabled: - d.Set("multi_az_enabled", false) - default: - log.Printf("Unknown MultiAZ state %q", aws.StringValue(rg.MultiAZ)) - } + switch rg.MultiAZ { + case awstypes.MultiAZStatusEnabled: + d.Set("multi_az_enabled", true) + case awstypes.MultiAZStatusDisabled: + d.Set("multi_az_enabled", false) + default: + log.Printf("Unknown MultiAZ state %q", string(rg.MultiAZ)) } if rg.ConfigurationEndpoint != nil { @@ -165,7 +160,7 @@ func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, } else { if rg.NodeGroups == nil { d.SetId("") - return sdkdiag.AppendErrorf(diags, "ElastiCache Replication Group (%s) doesn't have node groups", aws.StringValue(rg.ReplicationGroupId)) + return sdkdiag.AppendErrorf(diags, "ElastiCache Replication Group (%s) doesn't have node groups", aws.ToString(rg.ReplicationGroupId)) } d.Set(names.AttrPort, rg.NodeGroups[0].PrimaryEndpoint.Port) d.Set("primary_endpoint_address", rg.NodeGroups[0].PrimaryEndpoint.Address) @@ -173,7 +168,7 @@ func dataSourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, } d.Set("num_cache_clusters", len(rg.MemberClusters)) - if err := d.Set("member_clusters", flex.FlattenStringList(rg.MemberClusters)); err != nil { + if err := d.Set("member_clusters", flex.FlattenStringValueList(rg.MemberClusters)); err != nil { return sdkdiag.AppendErrorf(diags, "setting member_clusters: %s", err) } d.Set("node_type", rg.CacheNodeType) diff --git a/internal/service/elasticache/replication_group_data_source_test.go b/internal/service/elasticache/replication_group_data_source_test.go index a5f6be280b6..6a4d98e0243 100644 --- a/internal/service/elasticache/replication_group_data_source_test.go +++ b/internal/service/elasticache/replication_group_data_source_test.go @@ -7,8 +7,7 @@ import ( "fmt" "testing" - "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -112,21 +111,6 @@ func TestAccElastiCacheReplicationGroupDataSource_multiAZ(t *testing.T) { }) } -func TestAccElastiCacheReplicationGroupDataSource_nonExistent(t *testing.T) { - ctx := acctest.Context(t) - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, names.ElastiCacheServiceID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Steps: []resource.TestStep{ - { - Config: testAccReplicationGroupDataSourceConfig_nonExistent, - ExpectError: regexache.MustCompile(`couldn't find resource`), - }, - }, - }) -} - func TestAccElastiCacheReplicationGroupDataSource_Engine_Redis_LogDeliveryConfigurations(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { @@ -142,7 +126,7 @@ func TestAccElastiCacheReplicationGroupDataSource_Engine_Redis_LogDeliveryConfig ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText), true, string(awstypes.DestinationTypeKinesisFirehose), string(awstypes.LogFormatJson)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configuration.0.destination", rName), resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configuration.0.destination_type", "cloudwatch-logs"), @@ -212,9 +196,3 @@ data "aws_elasticache_replication_group" "test" { } `, rName) } - -const testAccReplicationGroupDataSourceConfig_nonExistent = ` -data "aws_elasticache_replication_group" "test" { - replication_group_id = "tf-acc-test-nonexistent" -} -` diff --git a/internal/service/elasticache/replication_group_migrate.go b/internal/service/elasticache/replication_group_migrate.go index 4518254d63e..f94db85fcc3 100644 --- a/internal/service/elasticache/replication_group_migrate.go +++ b/internal/service/elasticache/replication_group_migrate.go @@ -7,9 +7,10 @@ import ( "context" "strings" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "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/enum" "github.com/hashicorp/terraform-provider-aws/internal/sdkv2/types/nullable" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/verify" @@ -22,7 +23,7 @@ func replicationGroupStateUpgradeV1(ctx context.Context, rawState map[string]int } // Set auth_token_update_strategy to new default value - rawState["auth_token_update_strategy"] = elasticache.AuthTokenUpdateStrategyTypeRotate + rawState["auth_token_update_strategy"] = awstypes.AuthTokenUpdateStrategyTypeRotate return rawState, nil } @@ -120,10 +121,10 @@ func resourceReplicationGroupConfigV1() *schema.Resource { }, }, "ip_discovery": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(elasticache.IpDiscovery_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.IpDiscovery](), }, "log_delivery_configuration": { Type: schema.TypeSet, @@ -132,23 +133,23 @@ func resourceReplicationGroupConfigV1() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "destination_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.DestinationType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.DestinationType](), }, names.AttrDestination: { Type: schema.TypeString, Required: true, }, "log_format": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogFormat_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogFormat](), }, "log_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.LogType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.LogType](), }, }, }, @@ -175,11 +176,11 @@ func resourceReplicationGroupConfigV1() *schema.Resource { Default: false, }, "network_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(elasticache.NetworkType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.NetworkType](), }, "node_type": { Type: schema.TypeString, diff --git a/internal/service/elasticache/replication_group_test.go b/internal/service/elasticache/replication_group_test.go index 936b93e1662..14c1d199560 100644 --- a/internal/service/elasticache/replication_group_test.go +++ b/internal/service/elasticache/replication_group_test.go @@ -13,8 +13,9 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -32,7 +33,7 @@ func TestAccElastiCacheReplicationGroup_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -76,7 +77,7 @@ func TestAccElastiCacheReplicationGroup_basic_v5(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -113,7 +114,7 @@ func TestAccElastiCacheReplicationGroup_uppercase(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -146,7 +147,7 @@ func TestAccElastiCacheReplicationGroup_EngineVersion_v7(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -181,7 +182,7 @@ func TestAccElastiCacheReplicationGroup_EngineVersion_update(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var v1, v2, v3, v4, v5, v6 elasticache.ReplicationGroup + var v1, v2, v3, v4, v5, v6 awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -260,7 +261,7 @@ func TestAccElastiCacheReplicationGroup_EngineVersion_6xToRealVersion(t *testing t.Skip("skipping long-running test in short mode") } - var v1, v2 elasticache.ReplicationGroup + var v1, v2 awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -299,7 +300,7 @@ func TestAccElastiCacheReplicationGroup_disappears(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -327,7 +328,7 @@ func TestAccElastiCacheReplicationGroup_updateDescription(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -369,7 +370,7 @@ func TestAccElastiCacheReplicationGroup_updateMaintenanceWindow(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -409,7 +410,7 @@ func TestAccElastiCacheReplicationGroup_updateUserGroups(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) userGroup := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -453,7 +454,7 @@ func TestAccElastiCacheReplicationGroup_updateNodeSize(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -496,7 +497,7 @@ func TestAccElastiCacheReplicationGroup_updateParameterGroup(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup parameterGroupResourceName1 := "aws_elasticache_parameter_group.test.0" parameterGroupResourceName2 := "aws_elasticache_parameter_group.test.1" resourceName := "aws_elasticache_replication_group.test" @@ -542,7 +543,7 @@ func TestAccElastiCacheReplicationGroup_authToken(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" token1 := sdkacctest.RandString(16) @@ -569,21 +570,21 @@ func TestAccElastiCacheReplicationGroup_authToken(t *testing.T) { { // When adding an auth_token to a previously passwordless replication // group, the SET strategy can be used. - Config: testAccReplicationGroupConfig_authToken(rName, token1, elasticache.AuthTokenUpdateStrategyTypeSet), + Config: testAccReplicationGroupConfig_authToken(rName, token1, string(awstypes.AuthTokenUpdateStrategyTypeSet)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), resource.TestCheckResourceAttr(resourceName, "auth_token", token1), - resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", elasticache.AuthTokenUpdateStrategyTypeSet), + resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", string(awstypes.AuthTokenUpdateStrategyTypeSet)), ), }, { - Config: testAccReplicationGroupConfig_authToken(rName, token2, elasticache.AuthTokenUpdateStrategyTypeRotate), + Config: testAccReplicationGroupConfig_authToken(rName, token2, string(awstypes.AuthTokenUpdateStrategyTypeRotate)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), resource.TestCheckResourceAttr(resourceName, "auth_token", token2), - resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", elasticache.AuthTokenUpdateStrategyTypeRotate), + resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", string(awstypes.AuthTokenUpdateStrategyTypeRotate)), ), }, { @@ -591,12 +592,12 @@ func TestAccElastiCacheReplicationGroup_authToken(t *testing.T) { // should include the auth_token to be kept and the SET auth_token_update_strategy. // // Ref: https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/auth.html#auth-modifyng-token - Config: testAccReplicationGroupConfig_authToken(rName, token2, elasticache.AuthTokenUpdateStrategyTypeSet), + Config: testAccReplicationGroupConfig_authToken(rName, token2, string(awstypes.AuthTokenUpdateStrategyTypeSet)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), resource.TestCheckResourceAttr(resourceName, "auth_token", token2), - resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", elasticache.AuthTokenUpdateStrategyTypeSet), + resource.TestCheckResourceAttr(resourceName, "auth_token_update_strategy", string(awstypes.AuthTokenUpdateStrategyTypeSet)), ), }, }, @@ -609,7 +610,7 @@ func TestAccElastiCacheReplicationGroup_stateUpgrade5270(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -648,7 +649,7 @@ func TestAccElastiCacheReplicationGroup_vpc(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup resourceName := "aws_elasticache_replication_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -682,7 +683,7 @@ func TestAccElastiCacheReplicationGroup_multiAzNotInVPC(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -720,7 +721,7 @@ func TestAccElastiCacheReplicationGroup_multiAzNotInVPC_repeated(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -760,7 +761,7 @@ func TestAccElastiCacheReplicationGroup_multiAzInVPC(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -781,11 +782,11 @@ func TestAccElastiCacheReplicationGroup_multiAzInVPC(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "snapshot_retention_limit", "7"), resource.TestCheckResourceAttrSet(resourceName, "primary_endpoint_address"), func(s *terraform.State) error { - return resource.TestMatchResourceAttr(resourceName, "primary_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s\\..+\\.%s", aws.StringValue(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) + return resource.TestMatchResourceAttr(resourceName, "primary_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s\\..+\\.%s", aws.ToString(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) }, resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint_address"), func(s *terraform.State) error { - return resource.TestMatchResourceAttr(resourceName, "reader_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s-ro\\..+\\.%s", aws.StringValue(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) + return resource.TestMatchResourceAttr(resourceName, "reader_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s-ro\\..+\\.%s", aws.ToString(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) }, ), }, @@ -805,7 +806,7 @@ func TestAccElastiCacheReplicationGroup_deprecatedAvailabilityZones_multiAzInVPC t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -826,11 +827,11 @@ func TestAccElastiCacheReplicationGroup_deprecatedAvailabilityZones_multiAzInVPC resource.TestCheckResourceAttr(resourceName, "snapshot_retention_limit", "7"), resource.TestCheckResourceAttrSet(resourceName, "primary_endpoint_address"), func(s *terraform.State) error { - return resource.TestMatchResourceAttr(resourceName, "primary_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s\\..+\\.%s", aws.StringValue(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) + return resource.TestMatchResourceAttr(resourceName, "primary_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s\\..+\\.%s", aws.ToString(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) }, resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint_address"), func(s *terraform.State) error { - return resource.TestMatchResourceAttr(resourceName, "reader_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s-ro\\..+\\.%s", aws.StringValue(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) + return resource.TestMatchResourceAttr(resourceName, "reader_endpoint_address", regexache.MustCompile(fmt.Sprintf("%s-ro\\..+\\.%s", aws.ToString(rg.ReplicationGroupId), acctest.PartitionDNSSuffix())))(s) }, ), }, @@ -868,7 +869,7 @@ func TestAccElastiCacheReplicationGroup_ipDiscovery(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup resourceName := "aws_elasticache_replication_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -909,7 +910,7 @@ func TestAccElastiCacheReplicationGroup_networkType(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup resourceName := "aws_elasticache_replication_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -951,7 +952,7 @@ func TestAccElastiCacheReplicationGroup_ClusterMode_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -993,7 +994,7 @@ func TestAccElastiCacheReplicationGroup_ClusterMode_nonClusteredParameterGroup(t t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1037,7 +1038,7 @@ func TestAccElastiCacheReplicationGroup_ClusterModeUpdateNumNodeGroups_scaleUp(t t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" clusterDataSourcePrefix := "data.aws_elasticache_cluster.test" @@ -1087,7 +1088,7 @@ func TestAccElastiCacheReplicationGroup_ClusterModeUpdateNumNodeGroups_scaleDown t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1131,7 +1132,7 @@ func TestAccElastiCacheReplicationGroup_ClusterMode_updateReplicasPerNodeGroup(t t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1187,7 +1188,7 @@ func TestAccElastiCacheReplicationGroup_ClusterModeUpdateNumNodeGroupsAndReplica t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1231,7 +1232,7 @@ func TestAccElastiCacheReplicationGroup_ClusterModeUpdateNumNodeGroupsAndReplica t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1275,7 +1276,7 @@ func TestAccElastiCacheReplicationGroup_ClusterMode_singleNode(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1337,7 +1338,7 @@ func TestAccElastiCacheReplicationGroup_enableSnapshotting(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1377,7 +1378,7 @@ func TestAccElastiCacheReplicationGroup_transitEncryptionWithAuthToken(t *testin t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" authToken := sdkacctest.RandString(16) @@ -1413,7 +1414,7 @@ func TestAccElastiCacheReplicationGroup_transitEncryption5x(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg1, rg2 elasticache.ReplicationGroup + var rg1, rg2 awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1457,7 +1458,7 @@ func TestAccElastiCacheReplicationGroup_transitEncryption7x(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg1, rg2, rg3, rg4 elasticache.ReplicationGroup + var rg1, rg2, rg3, rg4 awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1468,11 +1469,11 @@ func TestAccElastiCacheReplicationGroup_transitEncryption7x(t *testing.T) { CheckDestroy: testAccCheckReplicationGroupDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, elasticache.TransitEncryptionModePreferred), + Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, string(awstypes.TransitEncryptionModePreferred)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg1), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), - resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", elasticache.TransitEncryptionModePreferred), + resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", string(awstypes.TransitEncryptionModePreferred)), ), }, { @@ -1483,22 +1484,22 @@ func TestAccElastiCacheReplicationGroup_transitEncryption7x(t *testing.T) { }, { // With Redis engine versions >= 7.0.5, transit_encryption_mode can be modified in-place. - Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, elasticache.TransitEncryptionModeRequired), + Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, string(awstypes.TransitEncryptionModeRequired)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg2), testAccCheckReplicationGroupNotRecreated(&rg1, &rg2), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), - resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", elasticache.TransitEncryptionModeRequired), + resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", string(awstypes.TransitEncryptionModeRequired)), ), }, { // Before disabling transit encryption, mode must be transitioned back to "preferred" first. - Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, elasticache.TransitEncryptionModePreferred), + Config: testAccReplicationGroupConfig_transitEncryptionEnabled7x(rName, string(awstypes.TransitEncryptionModePreferred)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg3), testAccCheckReplicationGroupNotRecreated(&rg2, &rg3), resource.TestCheckResourceAttr(resourceName, "transit_encryption_enabled", acctest.CtTrue), - resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", elasticache.TransitEncryptionModePreferred), + resource.TestCheckResourceAttr(resourceName, "transit_encryption_mode", string(awstypes.TransitEncryptionModePreferred)), ), }, { @@ -1520,7 +1521,7 @@ func TestAccElastiCacheReplicationGroup_enableAtRestEncryption(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1553,7 +1554,7 @@ func TestAccElastiCacheReplicationGroup_useCMKKMSKeyID(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" resource.ParallelTest(t, resource.TestCase{ @@ -1579,7 +1580,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClusters_basic(t *testing.T) t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" clusterDataSourcePrefix := "data.aws_elasticache_cluster.test" @@ -1645,7 +1646,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersFailover_autoFailover t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1677,7 +1678,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersFailover_autoFailover { PreConfig: func() { // Ensure that primary is on the node we are trying to delete - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute if err := resourceReplicationGroupSetPrimaryClusterID(ctx, conn, rName, formatReplicationGroupClusterID(rName, 3), timeout); err != nil { @@ -1703,7 +1704,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersFailover_autoFailover t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1729,7 +1730,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersFailover_autoFailover { PreConfig: func() { // Ensure that primary is on the node we are trying to delete - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute // Must disable automatic failover first @@ -1766,7 +1767,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClusters_multiAZEnabled(t *te t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1792,7 +1793,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClusters_multiAZEnabled(t *te { PreConfig: func() { // Ensure that primary is on the node we are trying to delete - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute // Must disable automatic failover first @@ -1829,7 +1830,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1850,7 +1851,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea { PreConfig: func() { // Remove one of the Cache Clusters - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute cacheClusterID := formatReplicationGroupClusterID(rName, 2) @@ -1880,7 +1881,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1901,7 +1902,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea { PreConfig: func() { // Remove one of the Cache Clusters - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute cacheClusterID := formatReplicationGroupClusterID(rName, 2) @@ -1931,7 +1932,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -1952,7 +1953,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea { PreConfig: func() { // Remove one of the Cache Clusters - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute cacheClusterID := formatReplicationGroupClusterID(rName, 2) @@ -1982,7 +1983,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea t.Skip("skipping long-running test in short mode") } - var replicationGroup elasticache.ReplicationGroup + var replicationGroup awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -2003,7 +2004,7 @@ func TestAccElastiCacheReplicationGroup_NumberCacheClustersMemberClusterDisappea { PreConfig: func() { // Remove one of the Cache Clusters - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) timeout := 40 * time.Minute cacheClusterID := formatReplicationGroupClusterID(rName, 2) @@ -2033,7 +2034,7 @@ func TestAccElastiCacheReplicationGroup_tags(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" clusterDataSourcePrefix := "data.aws_elasticache_cluster.test" @@ -2088,7 +2089,7 @@ func TestAccElastiCacheReplicationGroup_tagWithOtherModification(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" clusterDataSourcePrefix := "data.aws_elasticache_cluster.test" @@ -2129,7 +2130,7 @@ func TestAccElastiCacheReplicationGroup_finalSnapshot(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -2156,7 +2157,7 @@ func TestAccElastiCacheReplicationGroup_autoMinorVersionUpgrade(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -2242,8 +2243,8 @@ func TestAccElastiCacheReplicationGroup_GlobalReplicationGroupID_basic(t *testin t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup - var pg elasticache.CacheParameterGroup + var rg awstypes.ReplicationGroup + var pg awstypes.CacheParameterGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" primaryGroupResourceName := "aws_elasticache_replication_group.primary" @@ -2291,8 +2292,8 @@ func TestAccElastiCacheReplicationGroup_GlobalReplicationGroupID_full(t *testing t.Skip("skipping long-running test in short mode") } - var rg1, rg2 elasticache.ReplicationGroup - var pg1, pg2 elasticache.CacheParameterGroup + var rg1, rg2 awstypes.ReplicationGroup + var pg1, pg2 awstypes.CacheParameterGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" primaryGroupResourceName := "aws_elasticache_replication_group.primary" @@ -2361,7 +2362,7 @@ func TestAccElastiCacheReplicationGroup_GlobalReplicationGroupID_disappears(t *t t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -2392,8 +2393,8 @@ func TestAccElastiCacheReplicationGroup_GlobalReplicationGroupIDClusterMode_basi t.Skip("skipping long-running test in short mode") } - var rg1, rg2 elasticache.ReplicationGroup - var pg1, pg2 elasticache.CacheParameterGroup + var rg1, rg2 awstypes.ReplicationGroup + var pg1, pg2 awstypes.CacheParameterGroup rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" primaryGroupResourceName := "aws_elasticache_replication_group.primary" @@ -2480,8 +2481,8 @@ func TestAccElastiCacheReplicationGroup_dataTiering(t *testing.T) { } var ( - rg elasticache.ReplicationGroup - version elasticache.CacheEngineVersion + rg awstypes.ReplicationGroup + version awstypes.CacheEngineVersion ) rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_elasticache_replication_group.test" @@ -2520,7 +2521,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_elasticache_replication_group.test" @@ -2531,7 +2532,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C CheckDestroy: testAccCheckReplicationGroupDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText), true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2557,7 +2558,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C }, }, { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText), true, string(awstypes.DestinationTypeKinesisFirehose), string(awstypes.LogFormatJson)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2573,7 +2574,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C ), }, { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, false, "", ""), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, false, true, string(awstypes.DestinationTypeKinesisFirehose), string(awstypes.LogFormatJson), false, "", ""), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2623,7 +2624,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C t.Skip("skipping long-running test in short mode") } - var rg elasticache.ReplicationGroup + var rg awstypes.ReplicationGroup rName := sdkacctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_elasticache_replication_group.test" @@ -2634,7 +2635,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C CheckDestroy: testAccCheckReplicationGroupDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText), true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2661,7 +2662,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C }, }, { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, elasticache.DestinationTypeCloudwatchLogs, elasticache.LogFormatText, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, string(awstypes.DestinationTypeCloudWatchLogs), string(awstypes.LogFormatText), true, string(awstypes.DestinationTypeKinesisFirehose), string(awstypes.LogFormatJson)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2678,7 +2679,7 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C ), }, { - Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, elasticache.DestinationTypeKinesisFirehose, elasticache.LogFormatJson, false, "", ""), + Config: testAccReplicationGroupConfig_dataSourceEngineRedisLogDeliveryConfigurations(rName, true, true, string(awstypes.DestinationTypeKinesisFirehose), string(awstypes.LogFormatJson), false, "", ""), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckReplicationGroupExists(ctx, resourceName, &rg), resource.TestCheckResourceAttr(resourceName, names.AttrEngine, "redis"), @@ -2724,14 +2725,14 @@ func TestAccElastiCacheReplicationGroup_Engine_Redis_LogDeliveryConfigurations_C }) } -func testAccCheckReplicationGroupExists(ctx context.Context, n string, v *elasticache.ReplicationGroup) resource.TestCheckFunc { +func testAccCheckReplicationGroupExists(ctx context.Context, n string, v *awstypes.ReplicationGroup) 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).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindReplicationGroupByID(ctx, conn, rs.Primary.ID) @@ -2747,7 +2748,7 @@ func testAccCheckReplicationGroupExists(ctx context.Context, n string, v *elasti func testAccCheckReplicationGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_replication_group" { @@ -2770,18 +2771,18 @@ func testAccCheckReplicationGroupDestroy(ctx context.Context) resource.TestCheck } } -func testAccCheckReplicationGroupParameterGroupExists(ctx context.Context, rg *elasticache.ReplicationGroup, v *elasticache.CacheParameterGroup) resource.TestCheckFunc { +func testAccCheckReplicationGroupParameterGroupExists(ctx context.Context, rg *awstypes.ReplicationGroup, v *awstypes.CacheParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) - cacheClusterID := aws.StringValue(rg.NodeGroups[0].NodeGroupMembers[0].CacheClusterId) + cacheClusterID := aws.ToString(rg.NodeGroups[0].NodeGroupMembers[0].CacheClusterId) cluster, err := tfelasticache.FindCacheClusterByID(ctx, conn, cacheClusterID) if err != nil { return fmt.Errorf("reading ElastiCache Cluster (%s): %w", cacheClusterID, err) } - name := aws.StringValue(cluster.CacheParameterGroup.CacheParameterGroupName) + name := aws.ToString(cluster.CacheParameterGroup.CacheParameterGroupName) output, err := tfelasticache.FindCacheParameterGroupByName(ctx, conn, name) if err != nil { @@ -2794,11 +2795,11 @@ func testAccCheckReplicationGroupParameterGroupExists(ctx context.Context, rg *e } } -func testAccCheckGlobalReplicationGroupMemberParameterGroupDestroy(ctx context.Context, v *elasticache.CacheParameterGroup) resource.TestCheckFunc { +func testAccCheckGlobalReplicationGroupMemberParameterGroupDestroy(ctx context.Context, v *awstypes.CacheParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) - name := aws.StringValue(v.CacheParameterGroupName) + name := aws.ToString(v.CacheParameterGroupName) _, err := tfelasticache.FindCacheParameterGroupByName(ctx, conn, name) if tfresource.NotFound(err) { @@ -2820,7 +2821,7 @@ func testAccCheckReplicationGroupUserGroup(ctx context.Context, n, userGroupID s return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) id := rs.Primary.ID output, err := tfelasticache.FindReplicationGroupByID(ctx, conn, id) @@ -2833,7 +2834,7 @@ func testAccCheckReplicationGroupUserGroup(ctx context.Context, n, userGroupID s return fmt.Errorf("ElastiCache Replication Group (%s) was not assigned any User Groups", id) } - if v := aws.StringValue(output.UserGroupIds[0]); v != userGroupID { + if v := output.UserGroupIds[0]; v != userGroupID { return fmt.Errorf("ElastiCache Replication Group (%s) was not assigned User Group (%s), User Group was (%s) instead", n, userGroupID, v) } @@ -2841,9 +2842,9 @@ func testAccCheckReplicationGroupUserGroup(ctx context.Context, n, userGroupID s } } -func testAccCheckReplicationGroupRecreated(i, j *elasticache.ReplicationGroup) resource.TestCheckFunc { +func testAccCheckReplicationGroupRecreated(i, j *awstypes.ReplicationGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.TimeValue(i.ReplicationGroupCreateTime).Equal(aws.TimeValue(j.ReplicationGroupCreateTime)) { + if aws.ToTime(i.ReplicationGroupCreateTime).Equal(aws.ToTime(j.ReplicationGroupCreateTime)) { return errors.New("ElastiCache Replication Group not recreated") } @@ -2851,9 +2852,9 @@ func testAccCheckReplicationGroupRecreated(i, j *elasticache.ReplicationGroup) r } } -func testAccCheckReplicationGroupNotRecreated(i, j *elasticache.ReplicationGroup) resource.TestCheckFunc { +func testAccCheckReplicationGroupNotRecreated(i, j *awstypes.ReplicationGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - if !aws.TimeValue(i.ReplicationGroupCreateTime).Equal(aws.TimeValue(j.ReplicationGroupCreateTime)) { + if !aws.ToTime(i.ReplicationGroupCreateTime).Equal(aws.ToTime(j.ReplicationGroupCreateTime)) { return errors.New("ElastiCache Replication Group recreated") } @@ -2863,8 +2864,8 @@ func testAccCheckReplicationGroupNotRecreated(i, j *elasticache.ReplicationGroup func testCheckEngineStuffDefault(ctx context.Context, resourceName string) resource.TestCheckFunc { var ( - version elasticache.CacheEngineVersion - parameterGroup elasticache.CacheParameterGroup + version awstypes.CacheEngineVersion + parameterGroup awstypes.CacheParameterGroup ) checks := []resource.TestCheckFunc{ @@ -2884,11 +2885,11 @@ func testCheckEngineStuffDefault(ctx context.Context, resourceName string) resou return resource.ComposeAggregateTestCheckFunc(checks...) } -func testCheckRedisEngineVersionLatest(ctx context.Context, v *elasticache.CacheEngineVersion) resource.TestCheckFunc { +func testCheckRedisEngineVersionLatest(ctx context.Context, v *awstypes.CacheEngineVersion) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) - versions, err := conn.DescribeCacheEngineVersionsWithContext(ctx, &elasticache.DescribeCacheEngineVersionsInput{ + versions, err := conn.DescribeCacheEngineVersions(ctx, &elasticache.DescribeCacheEngineVersionsInput{ Engine: aws.String("redis"), DefaultOnly: aws.Bool(true), }) @@ -2902,22 +2903,22 @@ func testCheckRedisEngineVersionLatest(ctx context.Context, v *elasticache.Cache return fmt.Errorf("too many results: %d", l) } - *v = *(versions.CacheEngineVersions[0]) + *v = versions.CacheEngineVersions[0] return nil } } -func testCheckRedisParameterGroupDefault(ctx context.Context, version *elasticache.CacheEngineVersion, v *elasticache.CacheParameterGroup) resource.TestCheckFunc { +func testCheckRedisParameterGroupDefault(ctx context.Context, version *awstypes.CacheEngineVersion, v *awstypes.CacheParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindCacheParameterGroup(ctx, conn, &elasticache.DescribeCacheParameterGroupsInput{}, tfslices.PredicateAnd( - func(v *elasticache.CacheParameterGroup) bool { - return aws.StringValue(v.CacheParameterGroupFamily) == aws.StringValue(version.CacheParameterGroupFamily) + func(v *awstypes.CacheParameterGroup) bool { + return aws.ToString(v.CacheParameterGroupFamily) == aws.ToString(version.CacheParameterGroupFamily) }, - func(v *elasticache.CacheParameterGroup) bool { - name := aws.StringValue(v.CacheParameterGroupName) + func(v *awstypes.CacheParameterGroup) bool { + name := aws.ToString(v.CacheParameterGroupName) return strings.HasPrefix(name, "default.") && !strings.HasSuffix(name, ".cluster.on") }, )) @@ -2934,8 +2935,8 @@ func testCheckRedisParameterGroupDefault(ctx context.Context, version *elasticac func testCheckEngineStuffClusterEnabledDefault(ctx context.Context, resourceName string) resource.TestCheckFunc { var ( - version elasticache.CacheEngineVersion - parameterGroup elasticache.CacheParameterGroup + version awstypes.CacheEngineVersion + parameterGroup awstypes.CacheParameterGroup ) checks := []resource.TestCheckFunc{ @@ -2955,16 +2956,16 @@ func testCheckEngineStuffClusterEnabledDefault(ctx context.Context, resourceName return resource.ComposeAggregateTestCheckFunc(checks...) } -func testCheckRedisParameterGroupClusterEnabledDefault(ctx context.Context, version *elasticache.CacheEngineVersion, v *elasticache.CacheParameterGroup) resource.TestCheckFunc { +func testCheckRedisParameterGroupClusterEnabledDefault(ctx context.Context, version *awstypes.CacheEngineVersion, v *awstypes.CacheParameterGroup) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindCacheParameterGroup(ctx, conn, &elasticache.DescribeCacheParameterGroupsInput{}, tfslices.PredicateAnd( - func(v *elasticache.CacheParameterGroup) bool { - return aws.StringValue(v.CacheParameterGroupFamily) == aws.StringValue(version.CacheParameterGroupFamily) + func(v *awstypes.CacheParameterGroup) bool { + return aws.ToString(v.CacheParameterGroupFamily) == aws.ToString(version.CacheParameterGroupFamily) }, - func(v *elasticache.CacheParameterGroup) bool { - name := aws.StringValue(v.CacheParameterGroupName) + func(v *awstypes.CacheParameterGroup) bool { + name := aws.ToString(v.CacheParameterGroupName) return strings.HasPrefix(name, "default.") && strings.HasSuffix(name, ".cluster.on") }, )) @@ -4359,7 +4360,7 @@ data "aws_elasticache_replication_group" "test" { `, rName, enableClusterMode, slowLogDeliveryEnabled, slowDeliveryDestination, slowDeliveryFormat, engineLogDeliveryEnabled, engineDeliveryDestination, engineLogDeliveryFormat) } -func resourceReplicationGroupDisableAutomaticFailover(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, timeout time.Duration) error { +func resourceReplicationGroupDisableAutomaticFailover(ctx context.Context, conn *elasticache.Client, replicationGroupID string, timeout time.Duration) error { return resourceReplicationGroupModify(ctx, conn, timeout, &elasticache.ModifyReplicationGroupInput{ ReplicationGroupId: aws.String(replicationGroupID), ApplyImmediately: aws.Bool(true), @@ -4368,7 +4369,7 @@ func resourceReplicationGroupDisableAutomaticFailover(ctx context.Context, conn }) } -func resourceReplicationGroupEnableAutomaticFailover(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID string, multiAZEnabled bool, timeout time.Duration) error { +func resourceReplicationGroupEnableAutomaticFailover(ctx context.Context, conn *elasticache.Client, replicationGroupID string, multiAZEnabled bool, timeout time.Duration) error { return resourceReplicationGroupModify(ctx, conn, timeout, &elasticache.ModifyReplicationGroupInput{ ReplicationGroupId: aws.String(replicationGroupID), ApplyImmediately: aws.Bool(true), @@ -4377,7 +4378,7 @@ func resourceReplicationGroupEnableAutomaticFailover(ctx context.Context, conn * }) } -func resourceReplicationGroupSetPrimaryClusterID(ctx context.Context, conn *elasticache.ElastiCache, replicationGroupID, primaryClusterID string, timeout time.Duration) error { +func resourceReplicationGroupSetPrimaryClusterID(ctx context.Context, conn *elasticache.Client, replicationGroupID, primaryClusterID string, timeout time.Duration) error { return resourceReplicationGroupModify(ctx, conn, timeout, &elasticache.ModifyReplicationGroupInput{ ReplicationGroupId: aws.String(replicationGroupID), ApplyImmediately: aws.Bool(true), @@ -4385,8 +4386,8 @@ func resourceReplicationGroupSetPrimaryClusterID(ctx context.Context, conn *elas }) } -func resourceReplicationGroupModify(ctx context.Context, conn *elasticache.ElastiCache, timeout time.Duration, input *elasticache.ModifyReplicationGroupInput) error { - _, err := conn.ModifyReplicationGroupWithContext(ctx, input) +func resourceReplicationGroupModify(ctx context.Context, conn *elasticache.Client, timeout time.Duration, input *elasticache.ModifyReplicationGroupInput) error { + _, err := conn.ModifyReplicationGroup(ctx, input) if err != nil { return fmt.Errorf("error requesting modification: %w", err) } @@ -4394,7 +4395,7 @@ func resourceReplicationGroupModify(ctx context.Context, conn *elasticache.Elast const ( delay = 30 * time.Second ) - _, err = tfelasticache.WaitReplicationGroupAvailable(ctx, conn, aws.StringValue(input.ReplicationGroupId), timeout, delay) + _, err = tfelasticache.WaitReplicationGroupAvailable(ctx, conn, aws.ToString(input.ReplicationGroupId), timeout, delay) if err != nil { return fmt.Errorf("error waiting for modification: %w", err) } diff --git a/internal/service/elasticache/serverless_cache.go b/internal/service/elasticache/serverless_cache.go index 5685e569fdd..cdc148a212e 100644 --- a/internal/service/elasticache/serverless_cache.go +++ b/internal/service/elasticache/serverless_cache.go @@ -255,7 +255,7 @@ func (r *serverlessCacheResource) Create(ctx context.Context, request resource.C return } - input.Tags = getTagsInV2(ctx) + input.Tags = getTagsIn(ctx) _, err := conn.CreateServerlessCache(ctx, input) diff --git a/internal/service/elasticache/service_endpoint_resolver_gen.go b/internal/service/elasticache/service_endpoint_resolver_gen.go index b815da2c226..b29997cfee0 100644 --- a/internal/service/elasticache/service_endpoint_resolver_gen.go +++ b/internal/service/elasticache/service_endpoint_resolver_gen.go @@ -6,78 +6,14 @@ import ( "context" "fmt" "net" - "net/url" aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" elasticache_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticache" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/errs" ) -var _ endpoints_sdkv1.Resolver = resolverSDKv1{} - -type resolverSDKv1 struct { - ctx context.Context -} - -func newEndpointResolverSDKv1(ctx context.Context) resolverSDKv1 { - return resolverSDKv1{ - ctx: ctx, - } -} - -func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoints_sdkv1.Options)) (endpoint endpoints_sdkv1.ResolvedEndpoint, err error) { - ctx := r.ctx - - var opt endpoints_sdkv1.Options - opt.Set(opts...) - - useFIPS := opt.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled - - defaultResolver := endpoints_sdkv1.DefaultResolver() - - if useFIPS { - ctx = tflog.SetField(ctx, "tf_aws.use_fips", useFIPS) - - endpoint, err = defaultResolver.EndpointFor(service, region, opts...) - if err != nil { - return endpoint, err - } - - tflog.Debug(ctx, "endpoint resolved", map[string]any{ - "tf_aws.endpoint": endpoint.URL, - }) - - var endpointURL *url.URL - endpointURL, err = url.Parse(endpoint.URL) - if err != nil { - return endpoint, err - } - - hostname := endpointURL.Hostname() - _, err = net.LookupHost(hostname) - if err != nil { - if dnsErr, ok := errs.As[*net.DNSError](err); ok && dnsErr.IsNotFound { - tflog.Debug(ctx, "default endpoint host not found, disabling FIPS", map[string]any{ - "tf_aws.hostname": hostname, - }) - opts = append(opts, func(o *endpoints_sdkv1.Options) { - o.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled - }) - } else { - err = fmt.Errorf("looking up accessanalyzer endpoint %q: %s", hostname, err) - return - } - } else { - return endpoint, err - } - } - - return defaultResolver.EndpointFor(service, region, opts...) -} - var _ elasticache_sdkv2.EndpointResolverV2 = resolverSDKv2{} type resolverSDKv2 struct { diff --git a/internal/service/elasticache/service_endpoints_gen_test.go b/internal/service/elasticache/service_endpoints_gen_test.go index 1559e3f8ff1..a51cb4b40ac 100644 --- a/internal/service/elasticache/service_endpoints_gen_test.go +++ b/internal/service/elasticache/service_endpoints_gen_test.go @@ -18,8 +18,6 @@ import ( aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" elasticache_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticache" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - elasticache_sdkv1 "github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -236,25 +234,13 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S }, } - t.Run("v1", func(t *testing.T) { - for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv - testcase := testcase + for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv + testcase := testcase - t.Run(name, func(t *testing.T) { - testEndpointCase(t, providerRegion, testcase, callServiceV1) - }) - } - }) - - t.Run("v2", func(t *testing.T) { - for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv - testcase := testcase - - t.Run(name, func(t *testing.T) { - testEndpointCase(t, providerRegion, testcase, callServiceV2) - }) - } - }) + t.Run(name, func(t *testing.T) { + testEndpointCase(t, providerRegion, testcase, callService) + }) + } } func defaultEndpoint(region string) (url.URL, error) { @@ -292,7 +278,7 @@ func defaultFIPSEndpoint(region string) (url.URL, error) { return ep.URI, nil } -func callServiceV2(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { +func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() client := meta.ElastiCacheClient(ctx) @@ -317,21 +303,6 @@ func callServiceV2(ctx context.Context, t *testing.T, meta *conns.AWSClient) api return result } -func callServiceV1(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { - t.Helper() - - client := meta.ElastiCacheConn(ctx) - - req, _ := client.DescribeCacheClustersRequest(&elasticache_sdkv1.DescribeCacheClustersInput{}) - - req.HTTPRequest.URL.Path = "/" - - return apiCallParams{ - endpoint: req.HTTPRequest.URL.String(), - region: aws_sdkv1.StringValue(client.Config.Region), - } -} - func withNoConfig(_ *caseSetup) { // no-op } diff --git a/internal/service/elasticache/service_package_gen.go b/internal/service/elasticache/service_package_gen.go index 211383c06b8..dc973a3bc2f 100644 --- a/internal/service/elasticache/service_package_gen.go +++ b/internal/service/elasticache/service_package_gen.go @@ -7,10 +7,6 @@ import ( aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" elasticache_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticache" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - elasticache_sdkv1 "github.com/aws/aws-sdk-go/service/elasticache" - "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -126,24 +122,6 @@ func (p *servicePackage) ServicePackageName() string { return names.ElastiCache } -// 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) (*elasticache_sdkv1.ElastiCache, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) - - cfg := aws_sdkv1.Config{} - - 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) - } else { - cfg.EndpointResolver = newEndpointResolverSDKv1(ctx) - } - - return elasticache_sdkv1.New(sess.Copy(&cfg)), nil -} - // 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) (*elasticache_sdkv2.Client, error) { cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) diff --git a/internal/service/elasticache/subnet_group.go b/internal/service/elasticache/subnet_group.go index b00bb973e42..44f753bb0c2 100644 --- a/internal/service/elasticache/subnet_group.go +++ b/internal/service/elasticache/subnet_group.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -83,23 +83,24 @@ func resourceSubnetGroup() *schema.Resource { func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition name := d.Get(names.AttrName).(string) input := &elasticache.CreateCacheSubnetGroupInput{ CacheSubnetGroupDescription: aws.String(d.Get(names.AttrDescription).(string)), CacheSubnetGroupName: aws.String(name), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), Tags: getTagsIn(ctx), } - output, err := conn.CreateCacheSubnetGroupWithContext(ctx, input) + output, err := conn.CreateCacheSubnetGroup(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.Tags = nil - output, err = conn.CreateCacheSubnetGroupWithContext(ctx, input) + output, err = conn.CreateCacheSubnetGroup(ctx, input) } if err != nil { @@ -114,10 +115,10 @@ func resourceSubnetGroupCreate(ctx context.Context, d *schema.ResourceData, meta // For partitions not supporting tag-on-create, attempt tag after create. if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 { - err := createTags(ctx, conn, aws.StringValue(output.CacheSubnetGroup.ARN), tags) + err := createTags(ctx, conn, aws.ToString(output.CacheSubnetGroup.ARN), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceSubnetGroupRead(ctx, d, meta)...) } @@ -131,7 +132,7 @@ 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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) group, err := findCacheSubnetGroupByName(ctx, conn, d.Id()) @@ -148,8 +149,8 @@ func resourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta i d.Set(names.AttrARN, group.ARN) d.Set(names.AttrDescription, group.CacheSubnetGroupDescription) d.Set(names.AttrName, group.CacheSubnetGroupName) - d.Set(names.AttrSubnetIDs, tfslices.ApplyToAll(group.Subnets, func(v *elasticache.Subnet) string { - return aws.StringValue(v.SubnetIdentifier) + d.Set(names.AttrSubnetIDs, tfslices.ApplyToAll(group.Subnets, func(v awstypes.Subnet) string { + return aws.ToString(v.SubnetIdentifier) })) d.Set(names.AttrVPCID, group.VpcId) @@ -158,16 +159,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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChanges(names.AttrSubnetIDs, names.AttrDescription) { input := &elasticache.ModifyCacheSubnetGroupInput{ CacheSubnetGroupDescription: aws.String(d.Get(names.AttrDescription).(string)), CacheSubnetGroupName: aws.String(d.Get(names.AttrName).(string)), - SubnetIds: flex.ExpandStringSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), + SubnetIds: flex.ExpandStringValueSet(d.Get(names.AttrSubnetIDs).(*schema.Set)), } - _, err := conn.ModifyCacheSubnetGroupWithContext(ctx, input) + _, err := conn.ModifyCacheSubnetGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating ElastiCache Subnet Group (%s): %s", d.Id(), err) @@ -179,16 +180,16 @@ 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).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) log.Printf("[DEBUG] Deleting ElastiCache Subnet Group: %s", d.Id()) _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, 5*time.Minute, func() (interface{}, error) { - return conn.DeleteCacheSubnetGroupWithContext(ctx, &elasticache.DeleteCacheSubnetGroupInput{ + return conn.DeleteCacheSubnetGroup(ctx, &elasticache.DeleteCacheSubnetGroupInput{ CacheSubnetGroupName: aws.String(d.Id()), }) }, "DependencyViolation") - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheSubnetGroupNotFoundFault) { + if errs.IsA[*awstypes.CacheSubnetGroupNotFoundFault](err) { return diags } @@ -211,50 +212,48 @@ func resourceSubnetGroupCustomizeDiff(ctx context.Context, diff *schema.Resource return nil } -func findCacheSubnetGroupByName(ctx context.Context, conn *elasticache.ElastiCache, name string) (*elasticache.CacheSubnetGroup, error) { +func findCacheSubnetGroupByName(ctx context.Context, conn *elasticache.Client, name string) (*awstypes.CacheSubnetGroup, error) { input := &elasticache.DescribeCacheSubnetGroupsInput{ CacheSubnetGroupName: aws.String(name), } - return findCacheSubnetGroup(ctx, conn, input, tfslices.PredicateTrue[*elasticache.CacheSubnetGroup]()) + return findCacheSubnetGroup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.CacheSubnetGroup]()) } -func findCacheSubnetGroup(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheSubnetGroupsInput, filter tfslices.Predicate[*elasticache.CacheSubnetGroup]) (*elasticache.CacheSubnetGroup, error) { +func findCacheSubnetGroup(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheSubnetGroupsInput, filter tfslices.Predicate[*awstypes.CacheSubnetGroup]) (*awstypes.CacheSubnetGroup, error) { output, err := findCacheSubnetGroups(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findCacheSubnetGroups(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeCacheSubnetGroupsInput, filter tfslices.Predicate[*elasticache.CacheSubnetGroup]) ([]*elasticache.CacheSubnetGroup, error) { - var output []*elasticache.CacheSubnetGroup +func findCacheSubnetGroups(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeCacheSubnetGroupsInput, filter tfslices.Predicate[*awstypes.CacheSubnetGroup]) ([]awstypes.CacheSubnetGroup, error) { + var output []awstypes.CacheSubnetGroup - err := conn.DescribeCacheSubnetGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeCacheSubnetGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeCacheSubnetGroupsPaginator(conn, input) - for _, v := range page.CacheSubnetGroups { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.CacheSubnetGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeCacheSubnetGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.CacheSubnetGroups { + if filter(&v) { + output = append(output, v) + } + } } return output, nil diff --git a/internal/service/elasticache/subnet_group_data_source.go b/internal/service/elasticache/subnet_group_data_source.go index 6809fc1aec0..eea470408c2 100644 --- a/internal/service/elasticache/subnet_group_data_source.go +++ b/internal/service/elasticache/subnet_group_data_source.go @@ -6,8 +6,8 @@ package elasticache import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -52,7 +52,7 @@ func dataSourceSubnetGroup() *schema.Resource { func dataSourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig name := d.Get(names.AttrName).(string) @@ -63,12 +63,12 @@ func dataSourceSubnetGroupRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("ElastiCache Subnet Group", err)) } - d.SetId(aws.StringValue(group.CacheSubnetGroupName)) + d.SetId(aws.ToString(group.CacheSubnetGroupName)) d.Set(names.AttrARN, group.ARN) d.Set(names.AttrDescription, group.CacheSubnetGroupDescription) d.Set(names.AttrName, group.CacheSubnetGroupName) - d.Set(names.AttrSubnetIDs, tfslices.ApplyToAll(group.Subnets, func(v *elasticache.Subnet) string { - return aws.StringValue(v.SubnetIdentifier) + d.Set(names.AttrSubnetIDs, tfslices.ApplyToAll(group.Subnets, func(v awstypes.Subnet) string { + return aws.ToString(v.SubnetIdentifier) })) d.Set(names.AttrVPCID, group.VpcId) diff --git a/internal/service/elasticache/subnet_group_test.go b/internal/service/elasticache/subnet_group_test.go index 368f3483550..3f3fde2c1dd 100644 --- a/internal/service/elasticache/subnet_group_test.go +++ b/internal/service/elasticache/subnet_group_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -21,7 +21,7 @@ import ( func TestAccElastiCacheSubnetGroup_basic(t *testing.T) { ctx := acctest.Context(t) - var csg elasticache.CacheSubnetGroup + var csg awstypes.CacheSubnetGroup resourceName := "aws_elasticache_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -54,7 +54,7 @@ func TestAccElastiCacheSubnetGroup_basic(t *testing.T) { func TestAccElastiCacheSubnetGroup_disappears(t *testing.T) { ctx := acctest.Context(t) - var csg elasticache.CacheSubnetGroup + var csg awstypes.CacheSubnetGroup resourceName := "aws_elasticache_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -78,7 +78,7 @@ func TestAccElastiCacheSubnetGroup_disappears(t *testing.T) { func TestAccElastiCacheSubnetGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var csg elasticache.CacheSubnetGroup + var csg awstypes.CacheSubnetGroup resourceName := "aws_elasticache_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -124,7 +124,7 @@ func TestAccElastiCacheSubnetGroup_tags(t *testing.T) { func TestAccElastiCacheSubnetGroup_update(t *testing.T) { ctx := acctest.Context(t) - var csg elasticache.CacheSubnetGroup + var csg awstypes.CacheSubnetGroup resourceName := "aws_elasticache_subnet_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -165,7 +165,7 @@ func TestAccElastiCacheSubnetGroup_update(t *testing.T) { func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_subnet_group" { @@ -189,7 +189,7 @@ func testAccCheckSubnetGroupDestroy(ctx context.Context) resource.TestCheckFunc } } -func testAccCheckSubnetGroupExists(ctx context.Context, n string, v *elasticache.CacheSubnetGroup) resource.TestCheckFunc { +func testAccCheckSubnetGroupExists(ctx context.Context, n string, v *awstypes.CacheSubnetGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -200,7 +200,7 @@ func testAccCheckSubnetGroupExists(ctx context.Context, n string, v *elasticache return fmt.Errorf("No ElastiCache Subnet Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindCacheSubnetGroupByName(ctx, conn, rs.Primary.ID) diff --git a/internal/service/elasticache/sweep.go b/internal/service/elasticache/sweep.go index 3093e348e09..c4f05fa5c68 100644 --- a/internal/service/elasticache/sweep.go +++ b/internal/service/elasticache/sweep.go @@ -10,12 +10,13 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/go-multierror" "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" ) // These timeouts are lower to fail faster during sweepers @@ -84,45 +85,44 @@ func sweepClusters(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) - - var sweeperErrs *multierror.Error - input := &elasticache.DescribeCacheClustersInput{ ShowCacheClustersNotInReplicationGroups: aws.Bool(true), } - err = conn.DescribeCacheClustersPagesWithContext(ctx, input, func(page *elasticache.DescribeCacheClustersOutput, lastPage bool) bool { - if len(page.CacheClusters) == 0 { - log.Print("[DEBUG] No ElastiCache Replication Groups to sweep") - return false + conn := client.ElastiCacheClient(ctx) + var sweeperErrs *multierror.Error + + pages := elasticache.NewDescribeCacheClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache Cluster sweep for %s: %s", region, err) + return sweeperErrs.ErrorOrNil() // In case we have completed some pages, but had errors } - for _, cluster := range page.CacheClusters { - id := aws.StringValue(cluster.CacheClusterId) + if err != nil { + sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("Error retrieving ElastiCache Clusters: %w", err)) + } + + for _, v := range page.CacheClusters { + id := aws.ToString(v.CacheClusterId) log.Printf("[INFO] Deleting ElastiCache Cluster: %s", id) - err := DeleteCacheCluster(ctx, conn, id, "") + err := deleteCacheCluster(ctx, conn, id, "") + if err != nil { log.Printf("[ERROR] Failed to delete ElastiCache Cache Cluster (%s): %s", id, err) sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error deleting ElastiCache Cache Cluster (%s): %w", id, err)) } + const ( timeout = 40 * time.Minute ) - _, err = waitCacheClusterDeleted(ctx, conn, id, timeout) - if err != nil { + if _, err := waitCacheClusterDeleted(ctx, conn, id, timeout); err != nil { log.Printf("[ERROR] Failed waiting for ElastiCache Cache Cluster (%s) to be deleted: %s", id, err) sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("error deleting ElastiCache Cache Cluster (%s): waiting for completion: %w", id, err)) } } - return !lastPage - }) - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache Cluster sweep for %s: %s", region, err) - return sweeperErrs.ErrorOrNil() // In case we have completed some pages, but had errors - } - if err != nil { - sweeperErrs = multierror.Append(sweeperErrs, fmt.Errorf("Error retrieving ElastiCache Clusters: %w", err)) } return sweeperErrs.ErrorOrNil() @@ -134,25 +134,34 @@ func sweepGlobalReplicationGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) - - var grgGroup multierror.Group - input := &elasticache.DescribeGlobalReplicationGroupsInput{ ShowMemberInfo: aws.Bool(true), } - err = conn.DescribeGlobalReplicationGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeGlobalReplicationGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + conn := client.ElastiCacheClient(ctx) + + var grgGroup multierror.Group + var grgErrs *multierror.Error + + pages := elasticache.NewDescribeGlobalReplicationGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache Global Replication Group sweep for %q: %s", region, err) + return grgErrs.ErrorOrNil() // In case we have completed some pages, but had errors + } + + if err != nil { + grgErrs = multierror.Append(grgErrs, fmt.Errorf("listing ElastiCache Global Replication Groups: %w", err)) } - for _, globalReplicationGroup := range page.GlobalReplicationGroups { - globalReplicationGroup := globalReplicationGroup + for _, v := range page.GlobalReplicationGroups { + globalReplicationGroup := v grgGroup.Go(func() error { - id := aws.StringValue(globalReplicationGroup.GlobalReplicationGroupId) + id := aws.ToString(globalReplicationGroup.GlobalReplicationGroupId) - disassociationErrors := DisassociateMembers(ctx, conn, globalReplicationGroup) + disassociationErrors := disassociateMembers(ctx, conn, globalReplicationGroup) if disassociationErrors != nil { return fmt.Errorf("disassociating ElastiCache Global Replication Group (%s) members: %w", id, disassociationErrors) } @@ -163,20 +172,9 @@ func sweepGlobalReplicationGroups(region string) error { return err }) } - - return !lastPage - }) - - grgErrs := grgGroup.Wait() - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache Global Replication Group sweep for %q: %s", region, err) - return grgErrs.ErrorOrNil() // In case we have completed some pages, but had errors } - if err != nil { - grgErrs = multierror.Append(grgErrs, fmt.Errorf("listing ElastiCache Global Replication Groups: %w", err)) - } + grgErrs = multierror.Append(grgErrs, grgGroup.Wait()) return grgErrs.ErrorOrNil() } @@ -187,92 +185,90 @@ func sweepParameterGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) + input := &elasticache.DescribeCacheParameterGroupsInput{} + conn := client.ElastiCacheClient(ctx) + sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeCacheParameterGroupsPagesWithContext(ctx, &elasticache.DescribeCacheParameterGroupsInput{}, func(page *elasticache.DescribeCacheParameterGroupsOutput, lastPage bool) bool { - if len(page.CacheParameterGroups) == 0 { - log.Print("[DEBUG] No ElastiCache Parameter Groups to sweep") - return false + pages := elasticache.NewDescribeCacheParameterGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache Parameter Group sweep for %s: %s", region, err) + return nil } - for _, parameterGroup := range page.CacheParameterGroups { - name := aws.StringValue(parameterGroup.CacheParameterGroupName) + if err != nil { + return fmt.Errorf("error listing ElastiCache Parameter Groups (%s): %w", region, err) + } + + for _, v := range page.CacheParameterGroups { + name := aws.ToString(v.CacheParameterGroupName) if strings.HasPrefix(name, "default.") { log.Printf("[INFO] Skipping ElastiCache Cache Parameter Group: %s", name) continue } - log.Printf("[INFO] Deleting ElastiCache Parameter Group: %s", name) - _, err := conn.DeleteCacheParameterGroupWithContext(ctx, &elasticache.DeleteCacheParameterGroupInput{ - CacheParameterGroupName: aws.String(name), - }) - if err != nil { - log.Printf("[ERROR] Failed to delete ElastiCache Parameter Group (%s): %s", name, err) - } + r := resourceParameterGroup() + d := r.Data(nil) + d.SetId(name) + + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - return !lastPage - }) + } + + err = sweep.SweepOrchestrator(ctx, sweepResources) + if err != nil { - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache Parameter Group sweep for %s: %s", region, err) - return nil - } - return fmt.Errorf("Error retrieving ElastiCache Parameter Group: %w", err) + return fmt.Errorf("error sweeping ElastiCache Parameter Groups (%s): %w", region, err) } + return nil } func sweepReplicationGroups(region string) error { ctx := sweep.Context(region) client, err := sweep.SharedRegionalSweepClient(ctx, region) - if err != nil { return fmt.Errorf("error getting client: %w", err) } - - conn := client.ElastiCacheConn(ctx) + input := &elasticache.DescribeReplicationGroupsInput{} + conn := client.ElastiCacheClient(ctx) sweepResources := make([]sweep.Sweepable, 0) - var errs *multierror.Error - err = conn.DescribeReplicationGroupsPagesWithContext(ctx, &elasticache.DescribeReplicationGroupsInput{}, func(page *elasticache.DescribeReplicationGroupsOutput, lastPage bool) bool { - if len(page.ReplicationGroups) == 0 { - log.Print("[DEBUG] No ElastiCache Replication Groups to sweep") - return !lastPage // in rare cases across API, one page may have empty results but not be last page + pages := elasticache.NewDescribeReplicationGroupsPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache Replication Group sweep for %s: %s", region, err) + return nil } - for _, replicationGroup := range page.ReplicationGroups { + if err != nil { + return fmt.Errorf("error listing ElastiCache Replication Groups (%s): %w", region, err) + } + + for _, v := range page.ReplicationGroups { r := resourceReplicationGroup() d := r.Data(nil) - - if replicationGroup.GlobalReplicationGroupInfo != nil { - d.Set("global_replication_group_id", replicationGroup.GlobalReplicationGroupInfo.GlobalReplicationGroupId) + d.SetId(aws.ToString(v.ReplicationGroupId)) + if v.GlobalReplicationGroupInfo != nil { + d.Set("global_replication_group_id", v.GlobalReplicationGroupInfo.GlobalReplicationGroupId) } - d.SetId(aws.StringValue(replicationGroup.ReplicationGroupId)) - sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if err != nil { - errs = multierror.Append(errs, fmt.Errorf("error describing ElastiCache Replication Groups: %w", err)) } - if err = sweep.SweepOrchestrator(ctx, sweepResources); err != nil { - errs = multierror.Append(errs, fmt.Errorf("error sweeping ElastiCache Replication Groups for %s: %w", region, err)) - } - - // waiting for deletion is not necessary in the sweeper since the resource's delete waits + err = sweep.SweepOrchestrator(ctx, sweepResources) - if awsv1.SkipSweepError(errs.ErrorOrNil()) { - log.Printf("[WARN] Skipping ElastiCache Replication Group sweep for %s: %s", region, errs) - return nil + if err != nil { + return fmt.Errorf("error sweeping ElastiCache Replication Groups (%s): %w", region, err) } - return errs.ErrorOrNil() + return nil } func sweepSubnetGroups(region string) error { @@ -281,17 +277,26 @@ func sweepSubnetGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) + conn := client.ElastiCacheClient(ctx) input := &elasticache.DescribeCacheSubnetGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeCacheSubnetGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeCacheSubnetGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := elasticache.NewDescribeCacheSubnetGroupsPaginator(conn, input) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache Subnet Group sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing ElastiCache Subnet Groups (%s): %w", region, err) } for _, v := range page.CacheSubnetGroups { - name := aws.StringValue(v.CacheSubnetGroupName) + name := aws.ToString(v.CacheSubnetGroupName) if name == "default" { log.Printf("[INFO] Skipping ElastiCache Subnet Group: %s", name) @@ -304,17 +309,6 @@ func sweepSubnetGroups(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache Subnet Group sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing ElastiCache Subnet Groups (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -332,17 +326,26 @@ func sweepUsers(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) + conn := client.ElastiCacheClient(ctx) input := &elasticache.DescribeUsersInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeUsersPagesWithContext(ctx, input, func(page *elasticache.DescribeUsersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := elasticache.NewDescribeUsersPaginator(conn, input) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache User sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing ElastiCache Users (%s): %w", region, err) } for _, v := range page.Users { - id := aws.StringValue(v.UserId) + id := aws.ToString(v.UserId) if id == "default" { log.Printf("[INFO] Skipping ElastiCache User: %s", id) @@ -355,17 +358,6 @@ func sweepUsers(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache User sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing ElastiCache Users (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -383,33 +375,31 @@ func sweepUserGroups(region string) error { if err != nil { return fmt.Errorf("error getting client: %w", err) } - conn := client.ElastiCacheConn(ctx) + conn := client.ElastiCacheClient(ctx) input := &elasticache.DescribeUserGroupsInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.DescribeUserGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeUserGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := elasticache.NewDescribeUserGroupsPaginator(conn, input) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping ElastiCache User Group sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("listing ElastiCache User Groups (%s): %w", region, err) } for _, v := range page.UserGroups { r := resourceUserGroup() d := r.Data(nil) - d.SetId(aws.StringValue(v.UserGroupId)) + d.SetId(aws.ToString(v.UserGroupId)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping ElastiCache User Group sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("listing ElastiCache User Groups (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -421,20 +411,20 @@ func sweepUserGroups(region string) error { return nil } -func DisassociateMembers(ctx context.Context, conn *elasticache.ElastiCache, globalReplicationGroup *elasticache.GlobalReplicationGroup) error { +func disassociateMembers(ctx context.Context, conn *elasticache.Client, globalReplicationGroup awstypes.GlobalReplicationGroup) error { var membersGroup multierror.Group for _, member := range globalReplicationGroup.Members { member := member - if aws.StringValue(member.Role) == globalReplicationGroupMemberRolePrimary { + if aws.ToString(member.Role) == globalReplicationGroupMemberRolePrimary { continue } - id := aws.StringValue(globalReplicationGroup.GlobalReplicationGroupId) + id := aws.ToString(globalReplicationGroup.GlobalReplicationGroupId) membersGroup.Go(func() error { - if err := disassociateReplicationGroup(ctx, conn, id, aws.StringValue(member.ReplicationGroupId), aws.StringValue(member.ReplicationGroupRegion), sweeperGlobalReplicationGroupDisassociationReadyTimeout); err != nil { + if err := disassociateReplicationGroup(ctx, conn, id, aws.ToString(member.ReplicationGroupId), aws.ToString(member.ReplicationGroupRegion), sweeperGlobalReplicationGroupDisassociationReadyTimeout); err != nil { log.Printf("[ERROR] %s", err) return err } diff --git a/internal/service/elasticache/tags_gen.go b/internal/service/elasticache/tags_gen.go index 251e46c6eee..3091fa7e41e 100644 --- a/internal/service/elasticache/tags_gen.go +++ b/internal/service/elasticache/tags_gen.go @@ -4,16 +4,14 @@ package elasticache import ( "context" "fmt" - "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "github.com/aws/aws-sdk-go/service/elasticache/elasticacheiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/types/option" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -21,22 +19,12 @@ import ( // listTags lists elasticache 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 elasticacheiface.ElastiCacheAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *elasticache.Client, identifier string, optFns ...func(*elasticache.Options)) (tftags.KeyValueTags, error) { input := &elasticache.ListTagsForResourceInput{ ResourceName: aws.String(identifier), } - output, err := tfresource.RetryGWhenMessageContains(ctx, 15*time.Minute, - func() (*elasticache.TagListMessage, error) { - return conn.ListTagsForResourceWithContext(ctx, input) - }, - []string{ - elasticache.ErrCodeInvalidReplicationGroupStateFault, - }, - []string{ - "not in available state", - }, - ) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -48,7 +36,7 @@ func listTags(ctx context.Context, conn elasticacheiface.ElastiCacheAPI, identif // ListTags lists elasticache 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).ElastiCacheConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).ElastiCacheClient(ctx), identifier) if err != nil { return err @@ -64,11 +52,11 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri // []*SERVICE.Tag handling // Tags returns elasticache service tags. -func Tags(tags tftags.KeyValueTags) []*elasticache.Tag { - result := make([]*elasticache.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 := &elasticache.Tag{ + tag := awstypes.Tag{ Key: aws.String(k), Value: aws.String(v), } @@ -80,11 +68,11 @@ func Tags(tags tftags.KeyValueTags) []*elasticache.Tag { } // KeyValueTags creates tftags.KeyValueTags from elasticache service tags. -func KeyValueTags(ctx context.Context, tags []*elasticache.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) @@ -92,7 +80,7 @@ func KeyValueTags(ctx context.Context, tags []*elasticache.Tag) tftags.KeyValueT // getTagsIn returns elasticache service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) []*elasticache.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 @@ -103,25 +91,25 @@ func getTagsIn(ctx context.Context) []*elasticache.Tag { } // setTagsOut sets elasticache service tags in Context. -func setTagsOut(ctx context.Context, tags []*elasticache.Tag) { +func setTagsOut(ctx context.Context, tags []awstypes.Tag) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } } // createTags creates elasticache service tags for new resources. -func createTags(ctx context.Context, conn elasticacheiface.ElastiCacheAPI, identifier string, tags []*elasticache.Tag) error { +func createTags(ctx context.Context, conn *elasticache.Client, identifier string, tags []awstypes.Tag, optFns ...func(*elasticache.Options)) error { if len(tags) == 0 { return nil } - return updateTags(ctx, conn, identifier, nil, KeyValueTags(ctx, tags)) + return updateTags(ctx, conn, identifier, nil, KeyValueTags(ctx, tags), optFns...) } // updateTags updates elasticache 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 elasticacheiface.ElastiCacheAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *elasticache.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*elasticache.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -132,20 +120,10 @@ func updateTags(ctx context.Context, conn elasticacheiface.ElastiCacheAPI, ident if len(removedTags) > 0 { input := &elasticache.RemoveTagsFromResourceInput{ ResourceName: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := tfresource.RetryWhenMessageContains(ctx, 15*time.Minute, - func() (any, error) { - return conn.RemoveTagsFromResourceWithContext(ctx, input) - }, - []string{ - elasticache.ErrCodeInvalidReplicationGroupStateFault, - }, - []string{ - "not in available state", - }, - ) + _, err := conn.RemoveTagsFromResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -160,17 +138,7 @@ func updateTags(ctx context.Context, conn elasticacheiface.ElastiCacheAPI, ident Tags: Tags(updatedTags), } - _, err := tfresource.RetryWhenMessageContains(ctx, 15*time.Minute, - func() (any, error) { - return conn.AddTagsToResourceWithContext(ctx, input) - }, - []string{ - elasticache.ErrCodeInvalidReplicationGroupStateFault, - }, - []string{ - "not in available state", - }, - ) + _, err := conn.AddTagsToResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -183,5 +151,5 @@ func updateTags(ctx context.Context, conn elasticacheiface.ElastiCacheAPI, ident // UpdateTags updates elasticache 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).ElastiCacheConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).ElastiCacheClient(ctx), identifier, oldTags, newTags) } diff --git a/internal/service/elasticache/tagsv2_gen.go b/internal/service/elasticache/tagsv2_gen.go deleted file mode 100644 index 2412beef028..00000000000 --- a/internal/service/elasticache/tagsv2_gen.go +++ /dev/null @@ -1,59 +0,0 @@ -// Code generated by internal/generate/tags/main.go; DO NOT EDIT. -package elasticache - -import ( - "context" - - "github.com/aws/aws-sdk-go-v2/aws" - awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types" - tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" - "github.com/hashicorp/terraform-provider-aws/internal/types/option" -) - -// []*SERVICE.Tag handling - -// TagsV2 returns elasticache service tags. -func TagsV2(tags tftags.KeyValueTags) []awstypes.Tag { - result := make([]awstypes.Tag, 0, len(tags)) - - for k, v := range tags.Map() { - tag := awstypes.Tag{ - Key: aws.String(k), - Value: aws.String(v), - } - - result = append(result, tag) - } - - return result -} - -// keyValueTagsV2 creates tftags.KeyValueTags from elasticache service tags. -func keyValueTagsV2(ctx context.Context, tags []awstypes.Tag) tftags.KeyValueTags { - m := make(map[string]*string, len(tags)) - - for _, tag := range tags { - m[aws.ToString(tag.Key)] = tag.Value - } - - return tftags.New(ctx, m) -} - -// getTagsInV2 returns elasticache service tags from Context. -// nil is returned if there are no input tags. -func getTagsInV2(ctx context.Context) []awstypes.Tag { - if inContext, ok := tftags.FromContext(ctx); ok { - if tags := TagsV2(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { - return tags - } - } - - return nil -} - -// setTagsOutV2 sets elasticache service tags in Context. -func setTagsOutV2(ctx context.Context, tags []awstypes.Tag) { - if inContext, ok := tftags.FromContext(ctx); ok { - inContext.TagsOut = option.Some(keyValueTagsV2(ctx, tags)) - } -} diff --git a/internal/service/elasticache/user.go b/internal/service/elasticache/user.go index 63bfc16cd24..45b3053a971 100644 --- a/internal/service/elasticache/user.go +++ b/internal/service/elasticache/user.go @@ -9,14 +9,15 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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/enum" "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" @@ -79,9 +80,9 @@ func resourceUser() *schema.Resource { Computed: true, }, names.AttrType: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(elasticache.InputAuthenticationType_Values(), false), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.Validate[awstypes.InputAuthenticationType](), }, }, }, @@ -128,7 +129,8 @@ func resourceUser() *schema.Resource { func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition userID := d.Get("user_id").(string) input := &elasticache.CreateUserInput{ @@ -145,23 +147,23 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf } if v, ok := d.GetOk("passwords"); ok && v.(*schema.Set).Len() > 0 { - input.Passwords = flex.ExpandStringSet(v.(*schema.Set)) + input.Passwords = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateUserWithContext(ctx, input) + output, err := conn.CreateUser(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.Tags = nil - output, err = conn.CreateUserWithContext(ctx, input) + output, err = conn.CreateUser(ctx, input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache User (%s): %s", userID, err) } - d.SetId(aws.StringValue(output.UserId)) + d.SetId(aws.ToString(output.UserId)) if _, err := waitUserCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache User (%s) create: %s", d.Id(), err) @@ -169,10 +171,10 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf // For partitions not supporting tag-on-create, attempt tag after create. if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 { - err := createTags(ctx, conn, aws.StringValue(output.ARN), tags) + err := createTags(ctx, conn, aws.ToString(output.ARN), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceUserRead(ctx, d, meta)...) } @@ -186,7 +188,7 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) // An ongoing OOB update (where the user is in "modifying" state) can cause "UserNotFound: ... is not available for tagging" errors. // https://github.com/hashicorp/terraform-provider-aws/issues/34002. @@ -206,9 +208,9 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set(names.AttrARN, user.ARN) if v := user.Authentication; v != nil { tfMap := map[string]interface{}{ - "password_count": aws.Int64Value(v.PasswordCount), + "password_count": aws.ToInt32(v.PasswordCount), "passwords": d.Get("authentication_mode.0.passwords"), - names.AttrType: aws.StringValue(v.Type), + names.AttrType: string(v.Type), } if err := d.Set("authentication_mode", []interface{}{tfMap}); err != nil { @@ -226,7 +228,7 @@ func resourceUserRead(ctx context.Context, d *schema.ResourceData, meta interfac func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &elasticache.ModifyUserInput{ @@ -248,10 +250,10 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf } if d.HasChange("passwords") { - input.Passwords = flex.ExpandStringSet(d.Get("passwords").(*schema.Set)) + input.Passwords = flex.ExpandStringValueSet(d.Get("passwords").(*schema.Set)) } - _, err := conn.ModifyUserWithContext(ctx, input) + _, err := conn.ModifyUser(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating ElastiCache User (%s): %s", d.Id(), err) @@ -267,14 +269,14 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) log.Printf("[INFO] Deleting ElastiCache User: %s", d.Id()) - _, err := conn.DeleteUserWithContext(ctx, &elasticache.DeleteUserInput{ + _, err := conn.DeleteUser(ctx, &elasticache.DeleteUserInput{ UserId: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeUserNotFoundFault) { + if errs.IsA[*awstypes.UserNotFoundFault](err) { return diags } @@ -289,56 +291,54 @@ func resourceUserDelete(ctx context.Context, d *schema.ResourceData, meta interf return diags } -func findUserByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.User, error) { +func findUserByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.User, error) { input := &elasticache.DescribeUsersInput{ UserId: aws.String(id), } - return findUser(ctx, conn, input, tfslices.PredicateTrue[*elasticache.User]()) + return findUser(ctx, conn, input, tfslices.PredicateTrue[*awstypes.User]()) } -func findUser(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeUsersInput, filter tfslices.Predicate[*elasticache.User]) (*elasticache.User, error) { +func findUser(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeUsersInput, filter tfslices.Predicate[*awstypes.User]) (*awstypes.User, error) { output, err := findUsers(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findUsers(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeUsersInput, filter tfslices.Predicate[*elasticache.User]) ([]*elasticache.User, error) { - var output []*elasticache.User +func findUsers(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeUsersInput, filter tfslices.Predicate[*awstypes.User]) ([]awstypes.User, error) { + var output []awstypes.User - err := conn.DescribeUsersPagesWithContext(ctx, input, func(page *elasticache.DescribeUsersOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeUsersPaginator(conn, input) - for _, v := range page.Users { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.UserNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeUserNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.Users { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func statusUser(ctx context.Context, conn *elasticache.ElastiCache, id string) retry.StateRefreshFunc { +func statusUser(ctx context.Context, conn *elasticache.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findUserByID(ctx, conn, id) @@ -350,7 +350,7 @@ func statusUser(ctx context.Context, conn *elasticache.ElastiCache, id string) r return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } @@ -361,7 +361,7 @@ const ( userStatusModifying = "modifying" ) -func waitUserCreated(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.User, error) { +func waitUserCreated(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.User, error) { stateConf := &retry.StateChangeConf{ Pending: []string{userStatusCreating}, Target: []string{userStatusActive}, @@ -371,14 +371,14 @@ func waitUserCreated(ctx context.Context, conn *elasticache.ElastiCache, id stri outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.User); ok { + if output, ok := outputRaw.(*awstypes.User); ok { return output, err } return nil, err } -func waitUserUpdated(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.User, error) { +func waitUserUpdated(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.User, error) { stateConf := &retry.StateChangeConf{ Pending: []string{userStatusModifying}, Target: []string{userStatusActive}, @@ -388,14 +388,14 @@ func waitUserUpdated(ctx context.Context, conn *elasticache.ElastiCache, id stri outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.User); ok { + if output, ok := outputRaw.(*awstypes.User); ok { return output, err } return nil, err } -func waitUserDeleted(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.User, error) { +func waitUserDeleted(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.User, error) { stateConf := &retry.StateChangeConf{ Pending: []string{userStatusDeleting}, Target: []string{}, @@ -405,26 +405,26 @@ func waitUserDeleted(ctx context.Context, conn *elasticache.ElastiCache, id stri outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.User); ok { + if output, ok := outputRaw.(*awstypes.User); ok { return output, err } return nil, err } -func expandAuthenticationMode(tfMap map[string]interface{}) *elasticache.AuthenticationMode { +func expandAuthenticationMode(tfMap map[string]interface{}) *awstypes.AuthenticationMode { if tfMap == nil { return nil } - apiObject := &elasticache.AuthenticationMode{} + apiObject := &awstypes.AuthenticationMode{} if v, ok := tfMap["passwords"].(*schema.Set); ok && v.Len() > 0 { - apiObject.Passwords = flex.ExpandStringSet(v) + apiObject.Passwords = flex.ExpandStringValueSet(v) } if v, ok := tfMap[names.AttrType].(string); ok && v != "" { - apiObject.Type = aws.String(v) + apiObject.Type = awstypes.InputAuthenticationType(v) } return apiObject diff --git a/internal/service/elasticache/user_data_source.go b/internal/service/elasticache/user_data_source.go index e5be202ddea..2e8e988f074 100644 --- a/internal/service/elasticache/user_data_source.go +++ b/internal/service/elasticache/user_data_source.go @@ -6,7 +6,7 @@ package elasticache import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "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" @@ -70,7 +70,7 @@ func dataSourceUser() *schema.Resource { func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) user, err := findUserByID(ctx, conn, d.Get("user_id").(string)) @@ -78,12 +78,12 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interf return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("ElastiCache User", err)) } - d.SetId(aws.StringValue(user.UserId)) + d.SetId(aws.ToString(user.UserId)) d.Set("access_string", user.AccessString) if v := user.Authentication; v != nil { tfMap := map[string]interface{}{ - "password_count": aws.Int64Value(v.PasswordCount), - names.AttrType: aws.StringValue(v.Type), + "password_count": aws.ToInt32(v.PasswordCount), + names.AttrType: string(v.Type), } if err := d.Set("authentication_mode", []interface{}{tfMap}); err != nil { diff --git a/internal/service/elasticache/user_group.go b/internal/service/elasticache/user_group.go index 3c7e55f2fb8..6ad3cc53379 100644 --- a/internal/service/elasticache/user_group.go +++ b/internal/service/elasticache/user_group.go @@ -9,9 +9,9 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -74,7 +74,8 @@ func resourceUserGroup() *schema.Resource { func resourceUserGroupCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) + partition := meta.(*conns.AWSClient).Partition userGroupID := d.Get("user_group_id").(string) input := &elasticache.CreateUserGroupInput{ @@ -84,23 +85,23 @@ func resourceUserGroupCreate(ctx context.Context, d *schema.ResourceData, meta i } if v, ok := d.GetOk("user_ids"); ok && v.(*schema.Set).Len() > 0 { - input.UserIds = flex.ExpandStringSet(v.(*schema.Set)) + input.UserIds = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateUserGroupWithContext(ctx, input) + output, err := conn.CreateUserGroup(ctx, input) // Some partitions (e.g. ISO) may not support tag-on-create. - if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if input.Tags != nil && errs.IsUnsupportedOperationInPartitionError(partition, err) { input.Tags = nil - output, err = conn.CreateUserGroupWithContext(ctx, input) + output, err = conn.CreateUserGroup(ctx, input) } if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache User Group (%s): %s", userGroupID, err) } - d.SetId(aws.StringValue(output.UserGroupId)) + d.SetId(aws.ToString(output.UserGroupId)) if _, err := waitUserGroupCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for ElastiCache User Group (%s) create: %s", d.Id(), err) @@ -108,10 +109,10 @@ func resourceUserGroupCreate(ctx context.Context, d *schema.ResourceData, meta i // For partitions not supporting tag-on-create, attempt tag after create. if tags := getTagsIn(ctx); input.Tags == nil && len(tags) > 0 { - err := createTags(ctx, conn, aws.StringValue(output.ARN), tags) + err := createTags(ctx, conn, aws.ToString(output.ARN), tags) // If default tags only, continue. Otherwise, error. - if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(conn.PartitionID, err) { + if v, ok := d.GetOk(names.AttrTags); (!ok || len(v.(map[string]interface{})) == 0) && errs.IsUnsupportedOperationInPartitionError(partition, err) { return append(diags, resourceUserGroupRead(ctx, d, meta)...) } @@ -125,7 +126,7 @@ func resourceUserGroupCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceUserGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) userGroup, err := findUserGroupByID(ctx, conn, d.Id()) @@ -141,7 +142,7 @@ func resourceUserGroupRead(ctx context.Context, d *schema.ResourceData, meta int d.Set(names.AttrARN, userGroup.ARN) d.Set(names.AttrEngine, userGroup.Engine) - d.Set("user_ids", aws.StringValueSlice(userGroup.UserIds)) + d.Set("user_ids", userGroup.UserIds) d.Set("user_group_id", userGroup.UserGroupId) return diags @@ -149,7 +150,7 @@ func resourceUserGroupRead(ctx context.Context, d *schema.ResourceData, meta int func resourceUserGroupUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) { input := &elasticache.ModifyUserGroupInput{ @@ -162,14 +163,14 @@ func resourceUserGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i add := n.(*schema.Set).Difference(o.(*schema.Set)) if add.Len() > 0 { - input.UserIdsToAdd = flex.ExpandStringSet(add) + input.UserIdsToAdd = flex.ExpandStringValueSet(add) } if del.Len() > 0 { - input.UserIdsToRemove = flex.ExpandStringSet(del) + input.UserIdsToRemove = flex.ExpandStringValueSet(del) } } - _, err := conn.ModifyUserGroupWithContext(ctx, input) + _, err := conn.ModifyUserGroup(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating ElastiCache User Group (%q): %s", d.Id(), err) @@ -185,14 +186,14 @@ func resourceUserGroupUpdate(ctx context.Context, d *schema.ResourceData, meta i func resourceUserGroupDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) log.Printf("[INFO] Deleting ElastiCache User Group: %s", d.Id()) - _, err := conn.DeleteUserGroupWithContext(ctx, &elasticache.DeleteUserGroupInput{ + _, err := conn.DeleteUserGroup(ctx, &elasticache.DeleteUserGroupInput{ UserGroupId: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeUserGroupNotFoundFault) { + if errs.IsA[*awstypes.UserGroupNotFoundFault](err) { return diags } @@ -207,56 +208,54 @@ func resourceUserGroupDelete(ctx context.Context, d *schema.ResourceData, meta i return diags } -func findUserGroupByID(ctx context.Context, conn *elasticache.ElastiCache, id string) (*elasticache.UserGroup, error) { +func findUserGroupByID(ctx context.Context, conn *elasticache.Client, id string) (*awstypes.UserGroup, error) { input := &elasticache.DescribeUserGroupsInput{ UserGroupId: aws.String(id), } - return findUserGroup(ctx, conn, input, tfslices.PredicateTrue[*elasticache.UserGroup]()) + return findUserGroup(ctx, conn, input, tfslices.PredicateTrue[*awstypes.UserGroup]()) } -func findUserGroup(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeUserGroupsInput, filter tfslices.Predicate[*elasticache.UserGroup]) (*elasticache.UserGroup, error) { +func findUserGroup(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeUserGroupsInput, filter tfslices.Predicate[*awstypes.UserGroup]) (*awstypes.UserGroup, error) { output, err := findUserGroups(ctx, conn, input, filter) if err != nil { return nil, err } - return tfresource.AssertSinglePtrResult(output) + return tfresource.AssertSingleValueResult(output) } -func findUserGroups(ctx context.Context, conn *elasticache.ElastiCache, input *elasticache.DescribeUserGroupsInput, filter tfslices.Predicate[*elasticache.UserGroup]) ([]*elasticache.UserGroup, error) { - var output []*elasticache.UserGroup +func findUserGroups(ctx context.Context, conn *elasticache.Client, input *elasticache.DescribeUserGroupsInput, filter tfslices.Predicate[*awstypes.UserGroup]) ([]awstypes.UserGroup, error) { + var output []awstypes.UserGroup - err := conn.DescribeUserGroupsPagesWithContext(ctx, input, func(page *elasticache.DescribeUserGroupsOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } + pages := elasticache.NewDescribeUserGroupsPaginator(conn, input) - for _, v := range page.UserGroups { - if v != nil && filter(v) { - output = append(output, v) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if errs.IsA[*awstypes.UserGroupNotFoundFault](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, } } - return !lastPage - }) - - if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeUserGroupNotFoundFault) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, + if err != nil { + return nil, err } - } - if err != nil { - return nil, err + for _, v := range page.UserGroups { + if filter(&v) { + output = append(output, v) + } + } } return output, nil } -func statusUserGroup(ctx context.Context, conn *elasticache.ElastiCache, id string) retry.StateRefreshFunc { +func statusUserGroup(ctx context.Context, conn *elasticache.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := findUserGroupByID(ctx, conn, id) @@ -268,7 +267,7 @@ func statusUserGroup(ctx context.Context, conn *elasticache.ElastiCache, id stri return nil, "", err } - return output, aws.StringValue(output.Status), nil + return output, aws.ToString(output.Status), nil } } @@ -279,7 +278,7 @@ const ( userGroupStatusModifying = "modifying" ) -func waitUserGroupCreated(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.UserGroup, error) { +func waitUserGroupCreated(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.UserGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{userGroupStatusCreating, userGroupStatusModifying}, Target: []string{userGroupStatusActive}, @@ -291,14 +290,14 @@ func waitUserGroupCreated(ctx context.Context, conn *elasticache.ElastiCache, id outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.UserGroup); ok { + if output, ok := outputRaw.(*awstypes.UserGroup); ok { return output, err } return nil, err } -func waitUserGroupUpdated(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.UserGroup, error) { //nolint:unparam +func waitUserGroupUpdated(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.UserGroup, error) { //nolint:unparam stateConf := &retry.StateChangeConf{ Pending: []string{userGroupStatusModifying}, Target: []string{userGroupStatusActive}, @@ -310,14 +309,14 @@ func waitUserGroupUpdated(ctx context.Context, conn *elasticache.ElastiCache, id outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.UserGroup); ok { + if output, ok := outputRaw.(*awstypes.UserGroup); ok { return output, err } return nil, err } -func waitUserGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, id string, timeout time.Duration) (*elasticache.UserGroup, error) { +func waitUserGroupDeleted(ctx context.Context, conn *elasticache.Client, id string, timeout time.Duration) (*awstypes.UserGroup, error) { stateConf := &retry.StateChangeConf{ Pending: []string{userGroupStatusDeleting}, Target: []string{}, @@ -329,7 +328,7 @@ func waitUserGroupDeleted(ctx context.Context, conn *elasticache.ElastiCache, id outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*elasticache.UserGroup); ok { + if output, ok := outputRaw.(*awstypes.UserGroup); ok { return output, err } diff --git a/internal/service/elasticache/user_group_association.go b/internal/service/elasticache/user_group_association.go index 801b6af7520..cd88840279f 100644 --- a/internal/service/elasticache/user_group_association.go +++ b/internal/service/elasticache/user_group_association.go @@ -8,9 +8,9 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" - "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/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -53,19 +53,22 @@ func resourceUserGroupAssociation() *schema.Resource { func resourceUserGroupAssociationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) userGroupID := d.Get("user_group_id").(string) userID := d.Get("user_id").(string) id := errs.Must(flex.FlattenResourceId([]string{userGroupID, userID}, userGroupAssociationResourceIDPartCount, true)) input := &elasticache.ModifyUserGroupInput{ UserGroupId: aws.String(userGroupID), - UserIdsToAdd: aws.StringSlice([]string{userID}), + UserIdsToAdd: []string{userID}, } - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, 10*time.Minute, func() (interface{}, error) { - return conn.ModifyUserGroupWithContext(ctx, input) - }, elasticache.ErrCodeInvalidUserGroupStateFault) + const ( + timeout = 10 * time.Minute + ) + _, err := tfresource.RetryWhenIsA[*awstypes.InvalidUserGroupStateFault](ctx, timeout, func() (interface{}, error) { + return conn.ModifyUserGroup(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating ElastiCache User Group Association (%s): %s", id, err) @@ -82,14 +85,14 @@ func resourceUserGroupAssociationCreate(ctx context.Context, d *schema.ResourceD func resourceUserGroupAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), userGroupAssociationResourceIDPartCount, true) if err != nil { return sdkdiag.AppendFromErr(diags, err) } - userGroupID, userID := parts[0], parts[1] + err = findUserGroupAssociationByTwoPartKey(ctx, conn, userGroupID, userID) if !d.IsNewResource() && tfresource.NotFound(err) { @@ -110,23 +113,26 @@ func resourceUserGroupAssociationRead(ctx context.Context, d *schema.ResourceDat func resourceUserGroupAssociationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).ElastiCacheConn(ctx) + conn := meta.(*conns.AWSClient).ElastiCacheClient(ctx) parts, err := flex.ExpandResourceId(d.Id(), userGroupAssociationResourceIDPartCount, true) if err != nil { return sdkdiag.AppendFromErr(diags, err) } + userGroupID, userID := parts[0], parts[1] log.Printf("[INFO] Deleting ElastiCache User Group Association: %s", d.Id()) - userGroupID, userID := parts[0], parts[1] - _, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, 10*time.Minute, func() (interface{}, error) { - return conn.ModifyUserGroupWithContext(ctx, &elasticache.ModifyUserGroupInput{ + const ( + timeout = 10 * time.Minute + ) + _, err = tfresource.RetryWhenIsA[*awstypes.InvalidUserGroupStateFault](ctx, timeout, func() (interface{}, error) { + return conn.ModifyUserGroup(ctx, &elasticache.ModifyUserGroupInput{ UserGroupId: aws.String(userGroupID), - UserIdsToRemove: aws.StringSlice([]string{userID}), + UserIdsToRemove: []string{userID}, }) - }, elasticache.ErrCodeInvalidUserGroupStateFault) + }) - if tfawserr.ErrMessageContains(err, elasticache.ErrCodeInvalidParameterValueException, "not a member") { + if errs.IsAErrorMessageContains[*awstypes.InvalidParameterValueException](err, "not a member") { return diags } @@ -141,7 +147,7 @@ func resourceUserGroupAssociationDelete(ctx context.Context, d *schema.ResourceD return diags } -func findUserGroupAssociationByTwoPartKey(ctx context.Context, conn *elasticache.ElastiCache, userGroupID, userID string) error { +func findUserGroupAssociationByTwoPartKey(ctx context.Context, conn *elasticache.Client, userGroupID, userID string) error { userGroup, err := findUserGroupByID(ctx, conn, userGroupID) if err != nil { @@ -149,7 +155,7 @@ func findUserGroupAssociationByTwoPartKey(ctx context.Context, conn *elasticache } for _, v := range userGroup.UserIds { - if aws.StringValue(v) == userID { + if v == userID { return nil } } diff --git a/internal/service/elasticache/user_group_association_test.go b/internal/service/elasticache/user_group_association_test.go index c00e8780cc1..fd5729e6cbc 100644 --- a/internal/service/elasticache/user_group_association_test.go +++ b/internal/service/elasticache/user_group_association_test.go @@ -140,7 +140,7 @@ func TestAccElastiCacheUserGroupAssociation_multiple(t *testing.T) { func testAccCheckUserGroupAssociationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_user_group_association" { @@ -171,7 +171,7 @@ func testAccCheckUserGroupAssociationExists(ctx context.Context, n string) resou return fmt.Errorf("Not found: %s", n) } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) err := tfelasticache.FindUserGroupAssociationByTwoPartKey(ctx, conn, rs.Primary.Attributes["user_group_id"], rs.Primary.Attributes["user_id"]) diff --git a/internal/service/elasticache/user_group_test.go b/internal/service/elasticache/user_group_test.go index 16ab296b15b..b9eabc4f387 100644 --- a/internal/service/elasticache/user_group_test.go +++ b/internal/service/elasticache/user_group_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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" @@ -21,7 +21,7 @@ import ( func TestAccElastiCacheUserGroup_basic(t *testing.T) { ctx := acctest.Context(t) - var userGroup elasticache.UserGroup + var userGroup awstypes.UserGroup rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user_group.test" @@ -51,7 +51,7 @@ func TestAccElastiCacheUserGroup_basic(t *testing.T) { func TestAccElastiCacheUserGroup_update(t *testing.T) { ctx := acctest.Context(t) - var userGroup elasticache.UserGroup + var userGroup awstypes.UserGroup rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user_group.test" @@ -94,7 +94,7 @@ func TestAccElastiCacheUserGroup_update(t *testing.T) { func TestAccElastiCacheUserGroup_tags(t *testing.T) { ctx := acctest.Context(t) - var userGroup elasticache.UserGroup + var userGroup awstypes.UserGroup rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user_group.test" @@ -135,7 +135,7 @@ func TestAccElastiCacheUserGroup_tags(t *testing.T) { func TestAccElastiCacheUserGroup_disappears(t *testing.T) { ctx := acctest.Context(t) - var userGroup elasticache.UserGroup + var userGroup awstypes.UserGroup rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user_group.test" @@ -159,7 +159,7 @@ func TestAccElastiCacheUserGroup_disappears(t *testing.T) { func testAccCheckUserGroupDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_user_group" { @@ -183,7 +183,7 @@ func testAccCheckUserGroupDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckUserGroupExists(ctx context.Context, n string, v *elasticache.UserGroup) resource.TestCheckFunc { +func testAccCheckUserGroupExists(ctx context.Context, n string, v *awstypes.UserGroup) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -194,7 +194,7 @@ func testAccCheckUserGroupExists(ctx context.Context, n string, v *elasticache.U return fmt.Errorf("No ElastiCache User Group ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindUserGroupByID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/elasticache/user_test.go b/internal/service/elasticache/user_test.go index 34841293f97..4cd562085b8 100644 --- a/internal/service/elasticache/user_test.go +++ b/internal/service/elasticache/user_test.go @@ -8,8 +8,9 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/elasticache" + awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/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 +23,7 @@ import ( func TestAccElastiCacheUser_basic(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -57,7 +58,7 @@ func TestAccElastiCacheUser_basic(t *testing.T) { func TestAccElastiCacheUser_password_auth_mode(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -96,7 +97,7 @@ func TestAccElastiCacheUser_password_auth_mode(t *testing.T) { func TestAccElastiCacheUser_iam_auth_mode(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -130,7 +131,7 @@ func TestAccElastiCacheUser_iam_auth_mode(t *testing.T) { func TestAccElastiCacheUser_update(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -168,7 +169,7 @@ func TestAccElastiCacheUser_update(t *testing.T) { func TestAccElastiCacheUser_update_password_auth_mode(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -232,7 +233,7 @@ func TestAccElastiCacheUser_update_password_auth_mode(t *testing.T) { func TestAccElastiCacheUser_tags(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -283,7 +284,7 @@ func TestAccElastiCacheUser_tags(t *testing.T) { func TestAccElastiCacheUser_disappears(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -308,7 +309,7 @@ func TestAccElastiCacheUser_disappears(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/34002. func TestAccElastiCacheUser_oobModify(t *testing.T) { ctx := acctest.Context(t) - var user elasticache.User + var user awstypes.User rName := sdkacctest.RandomWithPrefix("tf-acc") resourceName := "aws_elasticache_user.test" @@ -349,7 +350,7 @@ func TestAccElastiCacheUser_oobModify(t *testing.T) { func testAccCheckUserDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_elasticache_user" { @@ -373,7 +374,7 @@ func testAccCheckUserDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckUserExists(ctx context.Context, n string, v *elasticache.User) resource.TestCheckFunc { +func testAccCheckUserExists(ctx context.Context, n string, v *awstypes.User) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -384,7 +385,7 @@ func testAccCheckUserExists(ctx context.Context, n string, v *elasticache.User) return fmt.Errorf("No ElastiCache User ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) output, err := tfelasticache.FindUserByID(ctx, conn, rs.Primary.ID) @@ -398,11 +399,11 @@ func testAccCheckUserExists(ctx context.Context, n string, v *elasticache.User) } } -func testAccCheckUserUpdateOOB(ctx context.Context, v *elasticache.User) resource.TestCheckFunc { +func testAccCheckUserUpdateOOB(ctx context.Context, v *awstypes.User) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).ElastiCacheClient(ctx) - _, err := conn.ModifyUserWithContext(ctx, &elasticache.ModifyUserInput{ + _, err := conn.ModifyUser(ctx, &elasticache.ModifyUserInput{ AccessString: aws.String("on ~* +@all"), UserId: v.UserId, }) diff --git a/names/data/names_data.hcl b/names/data/names_data.hcl index 928c0c8fe83..7aa11bd84b3 100644 --- a/names/data/names_data.hcl +++ b/names/data/names_data.hcl @@ -3419,7 +3419,7 @@ service "elasticache" { sdk { id = "ElastiCache" - client_version = [1, 2] + client_version = [2] } names { @@ -3427,10 +3427,6 @@ service "elasticache" { human_friendly = "ElastiCache" } - client { - go_v1_client_typename = "ElastiCache" - } - endpoint_info { endpoint_api_call = "DescribeCacheClusters" } diff --git a/names/names.go b/names/names.go index 1b877a8b00f..004859175aa 100644 --- a/names/names.go +++ b/names/names.go @@ -69,6 +69,7 @@ const ( EKSEndpointID = "eks" ELBEndpointID = "elasticloadbalancing" EMREndpointID = "elasticmapreduce" + ElastiCacheEndpointID = "elasticache" EventsEndpointID = "events" EvidentlyEndpointID = "evidently" FMSEndpointID = "fms"