diff --git a/internal/service/elasticache/find.go b/internal/service/elasticache/find.go index 35bd046246a..06bd5fd1f17 100644 --- a/internal/service/elasticache/find.go +++ b/internal/service/elasticache/find.go @@ -46,27 +46,26 @@ func FindReplicationGroupByID(conn *elasticache.ElastiCache, id string) (*elasti return output.ReplicationGroups[0], nil } -func FindReplicationGroups(conn *elasticache.ElastiCache) ([]*elasticache.ReplicationGroup, error) { - input := &elasticache.DescribeReplicationGroupsInput{} +func FindReplicationGroups(conn *elasticache.ElastiCache, input *elasticache.DescribeReplicationGroupsInput) ([]*elasticache.ReplicationGroup, error, *string) { output, err := conn.DescribeReplicationGroups(input) if tfawserr.ErrCodeEquals(err, elasticache.ErrCodeReplicationGroupNotFoundFault) { return nil, &resource.NotFoundError{ LastError: err, LastRequest: input, - } + }, nil } if err != nil { - return nil, err + return nil, err, nil } if output == nil || len(output.ReplicationGroups) == 0 || output.ReplicationGroups[0] == nil { return nil, &resource.NotFoundError{ Message: "empty result", LastRequest: input, - } + }, nil } - return output.ReplicationGroups, nil + return output.ReplicationGroups, nil, output.Marker } // FindReplicationGroupMemberClustersByID retrieves all of an ElastiCache Replication Group's MemberClusters by the id of the Replication Group. diff --git a/internal/service/elasticache/replication_groups_data_source.go b/internal/service/elasticache/replication_groups_data_source.go index 156f760eba8..8793ba9f572 100644 --- a/internal/service/elasticache/replication_groups_data_source.go +++ b/internal/service/elasticache/replication_groups_data_source.go @@ -157,9 +157,23 @@ func dataSourceReplicationGroupsRead(d *schema.ResourceData, meta interface{}) e ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig var replication_groups []interface{} - replication_groups_paginate, err := FindReplicationGroups(conn) - if err != nil && err.Error() != "empty result" { - return fmt.Errorf("error reading ElastiCache Replication Group %w", err) + var replication_groups_paginate []*elasticache.ReplicationGroup + params := &elasticache.DescribeReplicationGroupsInput{} + + for true { + + resp, err, Marker := FindReplicationGroups(conn, params) + if err != nil && err.Error() != "empty result" { + return fmt.Errorf("error reading ElastiCache Replication Group %w", err) + } + + replication_groups_paginate = append(replication_groups_paginate, resp...) + + if Marker != nil { + params.Marker = Marker + } else { + break + } } if replication_groups_paginate == nil || len(replication_groups_paginate) < 1 || replication_groups_paginate[0] == nil { @@ -205,8 +219,7 @@ func dataSourceReplicationGroupsRead(d *schema.ResourceData, meta interface{}) e replication_group["configuration_endpoint_address"] = rg.ConfigurationEndpoint.Address } else { if rg.NodeGroups == nil { - d.SetId("") - return fmt.Errorf("ElastiCache Replication Group (%s) doesn't have node groups", aws.StringValue(rg.ReplicationGroupId)) + log.Printf("[WARN] ElastiCache Replication Group (%s) doesn't have node groups", aws.StringValue(rg.ReplicationGroupId)) } replication_group["port"] = rg.NodeGroups[0].PrimaryEndpoint.Port replication_group["primary_endpoint_address"] = rg.NodeGroups[0].PrimaryEndpoint.Address