From 8bb15baafcc6dbf10c3fd51c83a99f944a376483 Mon Sep 17 00:00:00 2001 From: Richard Case Date: Thu, 12 Dec 2024 07:59:32 +0000 Subject: [PATCH] test: log aws account being used Small update to the e2e tests to the AWS account being used. This is to help in the future with any issues that may be associated with a specific AWS account. Signed-off-by: Richard Case --- test/e2e/shared/aws.go | 18 ++++++++++++++++-- test/e2e/shared/suite.go | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/test/e2e/shared/aws.go b/test/e2e/shared/aws.go index 31a6ac283a..073709c589 100644 --- a/test/e2e/shared/aws.go +++ b/test/e2e/shared/aws.go @@ -46,6 +46,7 @@ import ( "github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/servicequotas" + "github.com/aws/aws-sdk-go/service/sts" cfn_iam "github.com/awslabs/goformation/v4/cloudformation/iam" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -635,6 +636,19 @@ func GetPolicyArn(prov client.ConfigProvider, name string) string { return "" } +func logAccountDetails(prov client.ConfigProvider) { + By("Getting AWS account details") + stsSvc := sts.New(prov) + + output, err := stsSvc.GetCallerIdentity(&sts.GetCallerIdentityInput{}) + if err != nil { + fmt.Fprintf(GinkgoWriter, "couldn't get sts caller identity: err=%s", err) + return + } + + fmt.Fprintf(GinkgoWriter, "Using AWS account: %s", *output.Account) +} + // deleteCloudFormationStack removes the provisioned clusterawsadm stack. func deleteCloudFormationStack(prov client.ConfigProvider, t *cfn_bootstrap.Template) { By(fmt.Sprintf("Deleting %s CloudFormation stack", t.Spec.StackName)) @@ -837,7 +851,7 @@ func DumpCloudTrailEvents(e2eCtx *E2EContext) { if err != nil { fmt.Fprintf(GinkgoWriter, "Failed to marshal AWS CloudTrail events: err=%v", err) } - if err := os.WriteFile(logPath, dat, 0600); err != nil { + if err := os.WriteFile(logPath, dat, 0o600); err != nil { fmt.Fprintf(GinkgoWriter, "couldn't write cloudtrail events to file: file=%s err=%s", logPath, err) return } @@ -1008,7 +1022,7 @@ func dumpEKSCluster(cluster *eks.Cluster, logPath string) { } defer f.Close() - if err := os.WriteFile(f.Name(), clusterYAML, 0600); err != nil { + if err := os.WriteFile(f.Name(), clusterYAML, 0o600); err != nil { fmt.Fprintf(GinkgoWriter, "couldn't write cluster yaml to file: name=%s file=%s err=%s", *cluster.Name, f.Name(), err) return } diff --git a/test/e2e/shared/suite.go b/test/e2e/shared/suite.go index 135cfbe161..0a6c65619e 100644 --- a/test/e2e/shared/suite.go +++ b/test/e2e/shared/suite.go @@ -129,6 +129,9 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte { Expect(err).NotTo(HaveOccurred()) e2eCtx.AWSSession = NewAWSSession() + + logAccountDetails(e2eCtx.AWSSession) + bootstrapTemplate := getBootstrapTemplate(e2eCtx) bootstrapTags := map[string]string{"capa-e2e-test": "true"} e2eCtx.CloudFormationTemplate = renderCustomCloudFormation(bootstrapTemplate)