Skip to content

Commit

Permalink
r/aws_elasticache_replication_group: fix crash setting `replicas_per_…
Browse files Browse the repository at this point in the history
…node_group` (#38797)

In cases where the `NodeGroups` list in the read ouput is empty, the provider would crash attempting to read the `NodeGroupMembers` count from the first item in the list.

```console
% make testacc PKG=elasticache TESTS="TestAccElastiCacheReplicationGroup_basic|TestAccElastiCacheReplicationGroup_ClusterMode_basic"
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.6 test ./internal/service/elasticache/... -v -count 1 -parallel 20 -run='TestAccElastiCacheReplicationGroup_basic|TestAccElastiCacheReplicationGroup_ClusterMode_basic'  -timeout 360m

--- PASS: TestAccElastiCacheReplicationGroup_basic_v5 (775.08s)
--- PASS: TestAccElastiCacheReplicationGroup_basic (775.23s)
--- PASS: TestAccElastiCacheReplicationGroup_ClusterMode_basic (915.76s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/elasticache        921.685s
```
  • Loading branch information
jar-b authored Aug 9, 2024
1 parent 66dceda commit e8c4241
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/38797.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_elasticache_replication_group: Fix crash when setting `replicas_per_node_group` if node groups are empty
```
4 changes: 3 additions & 1 deletion internal/service/elasticache/replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ func resourceReplicationGroupRead(ctx context.Context, d *schema.ResourceData, m
}

d.Set("num_node_groups", len(rgp.NodeGroups))
d.Set("replicas_per_node_group", len(rgp.NodeGroups[0].NodeGroupMembers)-1)
if len(rgp.NodeGroups) > 0 {
d.Set("replicas_per_node_group", len(rgp.NodeGroups[0].NodeGroupMembers)-1)
}

d.Set("cluster_enabled", rgp.ClusterEnabled)
d.Set("cluster_mode", rgp.ClusterMode)
Expand Down

0 comments on commit e8c4241

Please sign in to comment.