diff --git a/pkg/resource/aws/aws_iam_access_key_ext.go b/pkg/resource/aws/aws_iam_access_key_ext.go index 696eae4e..1d415bc5 100644 --- a/pkg/resource/aws/aws_iam_access_key_ext.go +++ b/pkg/resource/aws/aws_iam_access_key_ext.go @@ -1,6 +1,10 @@ package aws -import "github.com/cloudskiff/driftctl/pkg/resource" +import ( + "fmt" + + "github.com/cloudskiff/driftctl/pkg/resource" +) func (r *AwsIamAccessKey) NormalizeForState() (resource.Resource, error) { // As we can't read secrets from aws API once access_key created we need to set @@ -14,3 +18,10 @@ func (r *AwsIamAccessKey) NormalizeForState() (resource.Resource, error) { func (r *AwsIamAccessKey) NormalizeForProvider() (resource.Resource, error) { return r, nil } + +func (r *AwsIamAccessKey) String() string { + if r.User == nil { + return r.TerraformId() + } + return fmt.Sprintf("%s (User: %s)", r.TerraformId(), *r.User) +} diff --git a/pkg/resource/aws/aws_iam_access_key_test.go b/pkg/resource/aws/aws_iam_access_key_test.go new file mode 100644 index 00000000..330d5cd8 --- /dev/null +++ b/pkg/resource/aws/aws_iam_access_key_test.go @@ -0,0 +1,37 @@ +package aws + +import ( + "testing" + + "github.com/aws/aws-sdk-go/aws" +) + +func TestAwsIamAccessKey_String(t *testing.T) { + tests := []struct { + user string + access AwsIamAccessKey + want string + }{ + {user: "test iam access key stringer with user and id", + access: AwsIamAccessKey{ + User: aws.String("test_user"), + Id: "AKIA2SIQ53JH4CMB42VB", + }, + want: "AKIA2SIQ53JH4CMB42VB (User: test_user)", + }, + {user: "test iam access key stringer without user", + access: AwsIamAccessKey{ + User: nil, + Id: "AKIA2SIQ53JH4CMB42VB", + }, + want: "AKIA2SIQ53JH4CMB42VB", + }, + } + for _, tt := range tests { + t.Run(tt.user, func(t *testing.T) { + if got := tt.access.String(); got != tt.want { + t.Errorf("String() = %v, want %v", got, tt.want) + } + }) + } +}