@@ -2,6 +2,7 @@ package ec2
22
33import (
44 "context"
5+ "fmt"
56
67 "github.com/OpsHelmInc/cloudquery/client"
78 "github.com/OpsHelmInc/cloudquery/resources/services/ec2/models"
@@ -12,22 +13,37 @@ import (
1213func fetchEc2RegionalConfigs (ctx context.Context , meta schema.ClientMeta , _ * schema.Resource , res chan <- interface {}) error {
1314 c := meta .(* client.Client )
1415
16+ var errs []error
17+
1518 svc := c .Services ().Ec2
1619 var regionalConfig models.RegionalConfig
1720 resp , err := svc .GetEbsDefaultKmsKeyId (ctx , & ec2.GetEbsDefaultKmsKeyIdInput {})
1821 if err != nil {
19- return err
22+ c .Logger ().Error ().Err (err ).Msg ("error calling GetEbsDefaultKmsKeyId" )
23+ errs = append (errs , err )
24+ } else if resp != nil {
25+ regionalConfig .EbsDefaultKmsKeyId = resp .KmsKeyId
2026 }
21- regionalConfig .EbsDefaultKmsKeyId = resp .KmsKeyId
2227
2328 ebsResp , err := svc .GetEbsEncryptionByDefault (ctx , & ec2.GetEbsEncryptionByDefaultInput {})
2429 if err != nil {
25- return err
30+ c .Logger ().Error ().Err (err ).Msg ("error calling GetEbsDefaultKmsKeyId" )
31+ errs = append (errs , err )
2632 }
2733
28- if ebsResp .EbsEncryptionByDefault != nil {
34+ if ebsResp != nil && ebsResp .EbsEncryptionByDefault != nil {
2935 regionalConfig .EbsEncryptionEnabledByDefault = * ebsResp .EbsEncryptionByDefault
3036 }
37+
3138 res <- regionalConfig
39+
40+ // TODO(kyle): errors.Join when we update to go 1.20
41+ if len (errs ) == 1 {
42+ return errs [0 ]
43+ } else if len (errs ) > 1 {
44+ // right now the length can only be 0, 1, or 2... so, concat the errors
45+ return fmt .Errorf ("errors getting regional config: %s, %s" , errs [0 ], errs [1 ])
46+ }
47+
3248 return nil
3349}
0 commit comments