From 9679667bdadbe7e805f7cd752e1af1b42a961afe Mon Sep 17 00:00:00 2001 From: Louis TOUSSAINT Date: Mon, 8 Feb 2021 19:59:55 +0100 Subject: [PATCH 1/2] ISSUE 184: Improve aws_iam_access_key_ext output by creating stringer --- pkg/resource/aws/aws_iam_access_key_ext.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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) +} From 2e0a36e9d8480c834b6b41f0f6ca1b18038b5bc3 Mon Sep 17 00:00:00 2001 From: Louis TOUSSAINT Date: Mon, 8 Feb 2021 20:12:59 +0100 Subject: [PATCH 2/2] ISSUE 184: Create test file for aws_iam_access_key stringer --- pkg/resource/aws/aws_iam_access_key_test.go | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pkg/resource/aws/aws_iam_access_key_test.go 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) + } + }) + } +}