Merge pull request #229 from cloudskiff/issue_184_lotoussa

Improve aws_iam_access_key output
main
Elie 2021-02-09 14:02:33 +01:00 committed by GitHub
commit f55e41bb1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -1,6 +1,10 @@
package aws package aws
import "github.com/cloudskiff/driftctl/pkg/resource" import (
"fmt"
"github.com/cloudskiff/driftctl/pkg/resource"
)
func (r *AwsIamAccessKey) NormalizeForState() (resource.Resource, error) { func (r *AwsIamAccessKey) NormalizeForState() (resource.Resource, error) {
// As we can't read secrets from aws API once access_key created we need to set // 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) { func (r *AwsIamAccessKey) NormalizeForProvider() (resource.Resource, error) {
return r, nil 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)
}

View File

@ -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)
}
})
}
}