Skip to content

Commit 7b921b6

Browse files
committed
🧹 Improve KMS key error message.
Signed-off-by: Vasil Sirakov <sirakov97@gmail.com>
1 parent fa5717a commit 7b921b6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

providers/aws/resources/aws_cloudtrail.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ func (a *mqlAwsCloudtrailTrail) logGroup() (*mqlAwsCloudwatchLoggroup, error) {
185185
func (a *mqlAwsCloudtrailTrail) kmsKey() (*mqlAwsKmsKey, error) {
186186
// add kms key if there is one
187187
if a.trailCache.KmsKeyId != nil {
188-
mqlKeyResource, err := NewResource(a.MqlRuntime, "aws.kms.key",
188+
mqlKeyResource, err := NewResource(a.MqlRuntime, ResourceAwsKmsKey,
189189
map[string]*llx.RawData{"arn": llx.StringDataPtr(a.trailCache.KmsKeyId)},
190190
)
191191
if err == nil {
192192
return mqlKeyResource.(*mqlAwsKmsKey), nil
193193
} else {
194-
log.Error().Err(err).Msg("cannot get key")
194+
log.Error().Err(err).Msg("could not create KMS key resource")
195195
}
196196
}
197197
a.KmsKey.State = plugin.StateIsSet | plugin.StateIsNull

providers/aws/resources/aws_kms.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package resources
66
import (
77
"context"
88
"errors"
9+
"fmt"
910

1011
"github.com/aws/aws-sdk-go-v2/aws/arn"
1112
"github.com/aws/aws-sdk-go-v2/service/kms"
@@ -187,10 +188,10 @@ func initAwsKmsKey(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[s
187188
arnVal, err := arn.Parse(a)
188189
if arnVal.AccountID != runtime.Connection.(*connection.AwsConnection).AccountId() {
189190
// sometimes there are references to keys in other accounts, like the master account of an org
190-
return nil, nil, errors.New("no access to key")
191+
return nil, nil, fmt.Errorf("cannot access key from a different AWS account %q", arnVal.AccountID)
191192
}
192193

193-
obj, err := CreateResource(runtime, "aws.kms", map[string]*llx.RawData{})
194+
obj, err := CreateResource(runtime, ResourceAwsKms, map[string]*llx.RawData{})
194195
if err != nil {
195196
return nil, nil, err
196197
}

0 commit comments

Comments
 (0)