Skip to content

Commit

Permalink
feat: Add support for use random cloudtrail name (#1658)
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Jin <lei.jin@lacework.net>
  • Loading branch information
leijin-lw authored Sep 19, 2024
1 parent a3da143 commit 97a45bc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lwgenerate/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"slices"
"strings"

"github.com/google/uuid"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/pkg/errors"

Expand Down Expand Up @@ -294,6 +295,9 @@ type GenerateAwsTfConfigurationArgs struct {
// Lacework Organization
LaceworkOrganizationLevel bool

// Use random Cloudtrail name
UseCloudTrailRandomName bool

// Default AWS Provider Tags
ProviderDefaultTags map[string]interface{}

Expand Down Expand Up @@ -595,6 +599,13 @@ func WithControlTowerLogArchiveAccount(LogArchiveAccount *AwsSubAccount) AwsTerr
}
}

// WithUseCloudTrailRandomName CloudTrail random name
func WithUseCloudTrailRandomName(useCloudTrailRandomName bool) AwsTerraformModifier {
return func(c *GenerateAwsTfConfigurationArgs) {
c.UseCloudTrailRandomName = useCloudTrailRandomName
}
}

// WithControlTowerKmsKeyArn Set ControlTower custom KMS key ARN
func WithControlTowerKmsKeyArn(kmsKeyArn string) AwsTerraformModifier {
return func(c *GenerateAwsTfConfigurationArgs) {
Expand Down Expand Up @@ -1049,6 +1060,12 @@ func createCloudtrail(args *GenerateAwsTfConfigurationArgs) (*hclwrite.Block, er
if args.ConsolidatedCloudtrail {
attributes["consolidated_trail"] = true
}

if args.UseCloudTrailRandomName {
uid := uuid.New().String()[:8]
attributes["cloudtrail_name"] = fmt.Sprintf("lacework-cloudtrail-%s", uid)
}

// S3 Bucket attributes
if args.CloudtrailUseExistingTrail {
attributes["use_existing_cloudtrail"] = true
Expand Down

0 comments on commit 97a45bc

Please sign in to comment.