Skip to content

Commit 97a45bc

Browse files
authored
feat: Add support for use random cloudtrail name (#1658)
Signed-off-by: Lei Jin <[email protected]>
1 parent a3da143 commit 97a45bc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lwgenerate/aws/aws.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"slices"
99
"strings"
1010

11+
"github.com/google/uuid"
1112
"github.com/hashicorp/hcl/v2/hclwrite"
1213
"github.com/pkg/errors"
1314

@@ -294,6 +295,9 @@ type GenerateAwsTfConfigurationArgs struct {
294295
// Lacework Organization
295296
LaceworkOrganizationLevel bool
296297

298+
// Use random Cloudtrail name
299+
UseCloudTrailRandomName bool
300+
297301
// Default AWS Provider Tags
298302
ProviderDefaultTags map[string]interface{}
299303

@@ -595,6 +599,13 @@ func WithControlTowerLogArchiveAccount(LogArchiveAccount *AwsSubAccount) AwsTerr
595599
}
596600
}
597601

602+
// WithUseCloudTrailRandomName CloudTrail random name
603+
func WithUseCloudTrailRandomName(useCloudTrailRandomName bool) AwsTerraformModifier {
604+
return func(c *GenerateAwsTfConfigurationArgs) {
605+
c.UseCloudTrailRandomName = useCloudTrailRandomName
606+
}
607+
}
608+
598609
// WithControlTowerKmsKeyArn Set ControlTower custom KMS key ARN
599610
func WithControlTowerKmsKeyArn(kmsKeyArn string) AwsTerraformModifier {
600611
return func(c *GenerateAwsTfConfigurationArgs) {
@@ -1049,6 +1060,12 @@ func createCloudtrail(args *GenerateAwsTfConfigurationArgs) (*hclwrite.Block, er
10491060
if args.ConsolidatedCloudtrail {
10501061
attributes["consolidated_trail"] = true
10511062
}
1063+
1064+
if args.UseCloudTrailRandomName {
1065+
uid := uuid.New().String()[:8]
1066+
attributes["cloudtrail_name"] = fmt.Sprintf("lacework-cloudtrail-%s", uid)
1067+
}
1068+
10521069
// S3 Bucket attributes
10531070
if args.CloudtrailUseExistingTrail {
10541071
attributes["use_existing_cloudtrail"] = true

0 commit comments

Comments
 (0)