Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_elasticache_replication_group: fix crash setting replicas_per_node_group #38797

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
r/aws_elasticache_replication_group: fix crash setting `replicas_per_…
…node_group`

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 committed Aug 9, 2024
commit 366b28eaad849aa3ee17a60bcdd2b6db0f16230e
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
@@ -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)
Loading