Skip to content

Commit

Permalink
fix: add redis groups pagination (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
msalman899 authored Mar 30, 2023
1 parent de17900 commit 073e87d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
11 changes: 5 additions & 6 deletions internal/service/elasticache/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 18 additions & 5 deletions internal/service/elasticache/replication_groups_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 073e87d

Please sign in to comment.