Skip to content

Commit

Permalink
Updating aws arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart committed Oct 13, 2022
1 parent 53f0b29 commit 37179bb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
18 changes: 9 additions & 9 deletions cli/cmd/generate_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ See help output for more details on the parameter value(s) required for Terrafor
aws.WithBucketEncryptionEnabled(GenerateAwsCommandState.BucketEncryptionEnabled),
aws.WithBucketSSEKeyArn(GenerateAwsCommandState.BucketSseKeyArn),
aws.WithSnsTopicName(GenerateAwsCommandState.SnsTopicName),
aws.WithSnsEncryptionEnabled(GenerateAwsCommandState.SnsEncryptionEnabled),
aws.WithSnsEncryptionKeyArn(GenerateAwsCommandState.SnsEncryptionKeyArn),
aws.WithSnsTopicEncryptionEnabled(GenerateAwsCommandState.SnsTopicEncryptionEnabled),
aws.WithSnsTopicEncryptionKeyArn(GenerateAwsCommandState.SnsTopicEncryptionKeyArn),
aws.WithSqsQueueName(GenerateAwsCommandState.SqsQueueName),
aws.WithSqsEncryptionEnabled(GenerateAwsCommandState.SqsEncryptionEnabled),
aws.WithSqsEncryptionKeyArn(GenerateAwsCommandState.SqsEncryptionKeyArn),
Expand Down Expand Up @@ -413,12 +413,12 @@ func initGenerateAwsTfCommandFlags() {
"location to write generated content (default is ~/lacework/aws)",
)
generateAwsTfCommand.PersistentFlags().BoolVar(
&GenerateAwsCommandState.SnsEncryptionEnabled,
&GenerateAwsCommandState.SnsTopicEncryptionEnabled,
"sns_topic_encryption_enabled",
true,
"enable encryption on SNS topic when creating one")
generateAwsTfCommand.PersistentFlags().StringVar(
&GenerateAwsCommandState.SnsEncryptionKeyArn,
&GenerateAwsCommandState.SnsTopicEncryptionKeyArn,
"sns_topic_encryption_key_arn",
"",
"specify existing KMS encryption key arn for SNS topic")
Expand Down Expand Up @@ -557,16 +557,16 @@ func promptAwsCtQuestions(config *aws.GenerateAwsTfConfigurationArgs, extraState
},
// If new bucket created, should this have encryption enabled
{
Prompt: &survey.Confirm{Message: QuestionSnsEnableEncryption, Default: config.SnsEncryptionEnabled},
Response: &config.SnsEncryptionEnabled,
Prompt: &survey.Confirm{Message: QuestionSnsEnableEncryption, Default: config.SnsTopicEncryptionEnabled},
Response: &config.SnsTopicEncryptionEnabled,
Checks: []*bool{&config.Cloudtrail, &newTopic},
},
// Allow the user to set the SSE Key ARN if required
{
Prompt: &survey.Input{Message: QuestionSnsEncryptionKeyArn, Default: config.SnsEncryptionKeyArn},
Response: &config.SnsEncryptionKeyArn,
Prompt: &survey.Input{Message: QuestionSnsEncryptionKeyArn, Default: config.SnsTopicEncryptionKeyArn},
Response: &config.SnsTopicEncryptionKeyArn,
Opts: []survey.AskOpt{survey.WithValidator(validateOptionalAwsArnFormat)},
Checks: []*bool{&config.Cloudtrail, &newTopic, &config.SnsEncryptionEnabled},
Checks: []*bool{&config.Cloudtrail, &newTopic, &config.SnsTopicEncryptionEnabled},
},
}, config.Cloudtrail); err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions integration/aws_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGenerationAwsSimple(t *testing.T) {
// Create the TF directly with lwgenerate and validate same result via CLI
buildTf, _ := aws.NewTerraform(region, true, true,
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestGenerationAwsCustomizedOutputLocation(t *testing.T) {
// Create the TF directly with lwgenerate and validate same result via CLI
buildTf, _ := aws.NewTerraform(region, true, true,
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, string(result))
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestGenerationAwsConfigOnly(t *testing.T) {
// Create the TF directly with lwgenerate and validate same result via CLI
buildTf, _ := aws.NewTerraform(region, true, false,
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestGenerationAwsAdvancedOptsDone(t *testing.T) {
// Create the TF directly with lwgenerate and validate same result via CLI
buildTf, _ := aws.NewTerraform(region, true, true,
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestGenerationAwsAdvancedOptsConsolidatedAndForceDestroy(t *testing.T) {
aws.UseConsolidatedCloudtrail(),
aws.EnableForceDestroyS3Bucket(),
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestGenerationAwsAdvancedOptsUseExistingCloudtrail(t *testing.T) {
buildTf, _ := aws.NewTerraform(region, true, true,
aws.ExistingCloudtrailBucketArn("arn:aws:s3:::bucket_name"),
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestGenerationAwsAdvancedOptsConsolidatedWithSubAccounts(t *testing.T) {
aws.WithAwsProfile("default"),
aws.WithSubaccounts(aws.NewAwsSubAccount("account1", "us-east-1"), aws.NewAwsSubAccount("account2", "us-east-2")),
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestGenerationAwsAdvancedOptsConsolidatedWithSubAccountsPassedByFlag(t *tes
aws.WithAwsProfile("default"),
aws.WithSubaccounts(aws.NewAwsSubAccount("account1", "us-east-1"), aws.NewAwsSubAccount("account2", "us-east-2")),
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestGenerationAwsAdvancedOptsUseExistingIAM(t *testing.T) {
buildTf, _ := aws.NewTerraform(region, true, true,
aws.UseExistingIamRole(aws.NewExistingIamRoleDetails(roleName, roleArn, roleExtId)),
aws.WithBucketEncryptionEnabled(true),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSqsEncryptionEnabled(true),
).Generate()
assert.Equal(t, buildTf, tfResult)
Expand Down Expand Up @@ -778,8 +778,8 @@ func TestGenerationAwsAdvancedOptsCreateNewElements(t *testing.T) {
aws.WithBucketEncryptionEnabled(true),
aws.WithBucketSSEKeyArn(kmsArn),
aws.WithSnsTopicName(topicName),
aws.WithSnsEncryptionEnabled(true),
aws.WithSnsEncryptionKeyArn(kmsArn),
aws.WithSnsTopicEncryptionEnabled(true),
aws.WithSnsTopicEncryptionKeyArn(kmsArn),
aws.WithSqsQueueName(queueName),
aws.WithSqsEncryptionEnabled(true),
aws.WithSqsEncryptionKeyArn(kmsArn),
Expand Down
22 changes: 11 additions & 11 deletions lwgenerate/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ type GenerateAwsTfConfigurationArgs struct {
SnsTopicName string

// Enable encryption of SNS if it is created
SnsEncryptionEnabled bool
SnsTopicEncryptionEnabled bool

// Indicates that the SNS Encryption flag has been actively set
// this is needed to show this it was set actively to false, rather
// than default value for bool
SnsEncryptionEnabledSet bool

// Arn of the KMS encryption key for SNS, required when SNS encryption in enabled
SnsEncryptionKeyArn string
SnsTopicEncryptionKeyArn string

// SSQ Queue name if creating one and not using an existing one
SqsQueueName string
Expand Down Expand Up @@ -293,18 +293,18 @@ func WithSnsTopicName(snsTopicName string) AwsTerraformModifier {
}
}

// WithSnsEncryptionEnabled Enable encryption on SNS Topic when created
func WithSnsEncryptionEnabled(snsEncryptionEnabled bool) AwsTerraformModifier {
// WithSnsTopicEncryptionEnabled Enable encryption on SNS Topic when created
func WithSnsTopicEncryptionEnabled(snsTopicEncryptionEnabled bool) AwsTerraformModifier {
return func(c *GenerateAwsTfConfigurationArgs) {
c.SnsEncryptionEnabled = snsEncryptionEnabled
c.SnsTopicEncryptionEnabled = snsTopicEncryptionEnabled
c.SnsEncryptionEnabledSet = true
}
}

// WithSnsEncryptionKeyArn Set existing KMS encryption key arn for SNS topic
func WithSnsEncryptionKeyArn(snsEncryptionKeyArn string) AwsTerraformModifier {
// WithSnsTopicEncryptionKeyArn Set existing KMS encryption key arn for SNS topic
func WithSnsTopicEncryptionKeyArn(snsTopicEncryptionKeyArn string) AwsTerraformModifier {
return func(c *GenerateAwsTfConfigurationArgs) {
c.SnsEncryptionKeyArn = snsEncryptionKeyArn
c.SnsTopicEncryptionKeyArn = snsTopicEncryptionKeyArn
}
}

Expand Down Expand Up @@ -525,9 +525,9 @@ func createCloudtrail(args *GenerateAwsTfConfigurationArgs) (*hclwrite.Block, er
attributes["sns_topic_name"] = args.SnsTopicName
}
if args.SnsEncryptionEnabledSet {
if args.SnsEncryptionEnabled {
if args.SnsEncryptionKeyArn != "" {
attributes["sns_topic_encryption_key_arn"] = args.SnsEncryptionKeyArn
if args.SnsTopicEncryptionEnabled {
if args.SnsTopicEncryptionKeyArn != "" {
attributes["sns_topic_encryption_key_arn"] = args.SnsTopicEncryptionKeyArn
}
} else {
attributes["sns_topic_encryption_enabled "] = false
Expand Down
10 changes: 5 additions & 5 deletions lwgenerate/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func TestGenerationCloudtrailSnsWithEncryption(t *testing.T) {
snsEncryptionArn := "arn:aws:kms:us-west-2:249446771485:key/2537e820-be82-4ded-8dca-504e199b0903"
hcl, err := NewTerraform("us-east-2", false, true,
WithSnsTopicName(snsTopicName),
WithSnsEncryptionEnabled(true),
WithSnsEncryptionKeyArn(snsEncryptionArn),
WithSnsTopicEncryptionEnabled(true),
WithSnsTopicEncryptionKeyArn(snsEncryptionArn),
).Generate()
assert.Nil(t, err)
assert.NotNil(t, hcl)
Expand All @@ -118,7 +118,7 @@ func TestGenerationCloudtrailSnsWithNoEncryption(t *testing.T) {
snsTopicName := "sns-topic-name"
hcl, err := NewTerraform("us-east-2", false, true,
WithSnsTopicName(snsTopicName),
WithSnsEncryptionEnabled(false),
WithSnsTopicEncryptionEnabled(false),
).Generate()
assert.Nil(t, err)
assert.NotNil(t, hcl)
Expand Down Expand Up @@ -181,8 +181,8 @@ func TestGenerationCloudtrailAllEncryptionElementsSet(t *testing.T) {
WithBucketEncryptionEnabled(true),
WithBucketSSEKeyArn(encryptionArn),
WithSnsTopicName(snsTopicName),
WithSnsEncryptionEnabled(true),
WithSnsEncryptionKeyArn(encryptionArn),
WithSnsTopicEncryptionEnabled(true),
WithSnsTopicEncryptionKeyArn(encryptionArn),
WithSqsQueueName(ssqQueueName),
WithSqsEncryptionEnabled(true),
WithSqsEncryptionKeyArn(encryptionArn),
Expand Down

0 comments on commit 37179bb

Please sign in to comment.