Skip to content

Commit

Permalink
test: log aws account being used
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
richardcase committed Dec 12, 2024
1 parent 10234ff commit 8bb15ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/e2e/shared/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/shared/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8bb15ba

Please sign in to comment.