Skip to content

Commit 3a646b3

Browse files
authored
Merge pull request #5250 from richardcase/e2e_log_account
🌱 test: log aws account being used
2 parents 10234ff + 8bb15ba commit 3a646b3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/e2e/shared/aws.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/aws/aws-sdk-go/service/elb"
4747
"github.com/aws/aws-sdk-go/service/iam"
4848
"github.com/aws/aws-sdk-go/service/servicequotas"
49+
"github.com/aws/aws-sdk-go/service/sts"
4950
cfn_iam "github.com/awslabs/goformation/v4/cloudformation/iam"
5051
. "github.com/onsi/ginkgo/v2"
5152
. "github.com/onsi/gomega"
@@ -635,6 +636,19 @@ func GetPolicyArn(prov client.ConfigProvider, name string) string {
635636
return ""
636637
}
637638

639+
func logAccountDetails(prov client.ConfigProvider) {
640+
By("Getting AWS account details")
641+
stsSvc := sts.New(prov)
642+
643+
output, err := stsSvc.GetCallerIdentity(&sts.GetCallerIdentityInput{})
644+
if err != nil {
645+
fmt.Fprintf(GinkgoWriter, "couldn't get sts caller identity: err=%s", err)
646+
return
647+
}
648+
649+
fmt.Fprintf(GinkgoWriter, "Using AWS account: %s", *output.Account)
650+
}
651+
638652
// deleteCloudFormationStack removes the provisioned clusterawsadm stack.
639653
func deleteCloudFormationStack(prov client.ConfigProvider, t *cfn_bootstrap.Template) {
640654
By(fmt.Sprintf("Deleting %s CloudFormation stack", t.Spec.StackName))
@@ -837,7 +851,7 @@ func DumpCloudTrailEvents(e2eCtx *E2EContext) {
837851
if err != nil {
838852
fmt.Fprintf(GinkgoWriter, "Failed to marshal AWS CloudTrail events: err=%v", err)
839853
}
840-
if err := os.WriteFile(logPath, dat, 0600); err != nil {
854+
if err := os.WriteFile(logPath, dat, 0o600); err != nil {
841855
fmt.Fprintf(GinkgoWriter, "couldn't write cloudtrail events to file: file=%s err=%s", logPath, err)
842856
return
843857
}
@@ -1008,7 +1022,7 @@ func dumpEKSCluster(cluster *eks.Cluster, logPath string) {
10081022
}
10091023
defer f.Close()
10101024

1011-
if err := os.WriteFile(f.Name(), clusterYAML, 0600); err != nil {
1025+
if err := os.WriteFile(f.Name(), clusterYAML, 0o600); err != nil {
10121026
fmt.Fprintf(GinkgoWriter, "couldn't write cluster yaml to file: name=%s file=%s err=%s", *cluster.Name, f.Name(), err)
10131027
return
10141028
}

test/e2e/shared/suite.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte {
129129

130130
Expect(err).NotTo(HaveOccurred())
131131
e2eCtx.AWSSession = NewAWSSession()
132+
133+
logAccountDetails(e2eCtx.AWSSession)
134+
132135
bootstrapTemplate := getBootstrapTemplate(e2eCtx)
133136
bootstrapTags := map[string]string{"capa-e2e-test": "true"}
134137
e2eCtx.CloudFormationTemplate = renderCustomCloudFormation(bootstrapTemplate)

0 commit comments

Comments
 (0)