Skip to content

Commit c25fcb9

Browse files
committed
fix: defending against nils in the TGW
1 parent cab7b81 commit c25fcb9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

provider/datasource_rediscloud_active_active_transit_gateway.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ func dataSourceActiveActiveTransitGatewayRead(ctx context.Context, d *schema.Res
8585
return diag.FromErr(err)
8686
}
8787

88+
// Check for nil response structure
89+
if tgwTask == nil {
90+
return diag.Errorf("Transit Gateway API returned nil task for subscription %d, region %d", subId, regionId)
91+
}
92+
if tgwTask.Response == nil {
93+
return diag.Errorf("Transit Gateway API returned nil response for subscription %d, region %d", subId, regionId)
94+
}
95+
if tgwTask.Response.Resource == nil {
96+
return diag.Errorf("Transit Gateway API returned nil resource for subscription %d, region %d - subscription may not be fully provisioned yet", subId, regionId)
97+
}
98+
8899
var filters []func(db *attachments.TransitGatewayAttachment) bool
89100

90101
if v, ok := d.GetOk("tgw_id"); ok {

provider/datasource_rediscloud_transit_gateway.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ func dataSourceTransitGatewayRead(ctx context.Context, d *schema.ResourceData, m
7979
return diag.FromErr(err)
8080
}
8181

82+
// Check for nil response structure
83+
if tgwTask == nil {
84+
return diag.Errorf("Transit Gateway API returned nil task for subscription %d", subId)
85+
}
86+
if tgwTask.Response == nil {
87+
return diag.Errorf("Transit Gateway API returned nil response for subscription %d", subId)
88+
}
89+
if tgwTask.Response.Resource == nil {
90+
return diag.Errorf("Transit Gateway API returned nil resource for subscription %d - subscription may not be fully provisioned yet", subId)
91+
}
92+
8293
var filters []func(db *attachments.TransitGatewayAttachment) bool
8394

8495
if v, ok := d.GetOk("tgw_id"); ok {
@@ -133,6 +144,12 @@ func dataSourceTransitGatewayRead(ctx context.Context, d *schema.ResourceData, m
133144

134145
func filterTgwAttachments(getAttachmentsTask *attachments.GetAttachmentsTask, filters []func(tgwa *attachments.TransitGatewayAttachment) bool) []*attachments.TransitGatewayAttachment {
135146
var filtered []*attachments.TransitGatewayAttachment
147+
148+
// Defensive nil checks - callers should validate before calling, but we guard here too
149+
if getAttachmentsTask == nil || getAttachmentsTask.Response == nil || getAttachmentsTask.Response.Resource == nil {
150+
return filtered
151+
}
152+
136153
for _, tgwa := range getAttachmentsTask.Response.Resource.TransitGatewayAttachment {
137154
if filterTgwAttachment(tgwa, filters) {
138155
filtered = append(filtered, tgwa)

0 commit comments

Comments
 (0)