Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for use random cloudtrail name #1658

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading