Skip to content

Commit fdc1bcf

Browse files
authored
feat: add agentless to generate command for AWS (#1423)
* feat(GROW-2540): add Agentless to generate command
1 parent 478dcaa commit fdc1bcf

File tree

9 files changed

+193
-65
lines changed

9 files changed

+193
-65
lines changed

cli/cmd/generate_aws.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
var (
1717
// Define question text here so they can be reused in testing
18+
QuestionEnableAgentless = "Enable Agentless integration?"
1819
QuestionAwsEnableConfig = "Enable configuration integration?"
1920
QuestionCustomizeConfigName = "Customize Config integration name?"
2021
QuestionConfigName = "Specify name of config integration (optional)"
@@ -57,6 +58,7 @@ var (
5758

5859
// select options
5960
AwsAdvancedOptDone = "Done"
61+
AdvancedOptAgentless = "Additional Agentless options (placeholder)"
6062
AdvancedOptCloudTrail = "Additional CloudTrail options"
6163
AdvancedOptIamRole = "Configure Lacework integration with an existing IAM role"
6264
AdvancedOptAwsAccounts = "Add additional AWS Accounts to Lacework"
@@ -137,6 +139,7 @@ See help output for more details on the parameter value(s) required for Terrafor
137139
// Create new struct
138140
data := aws.NewTerraform(
139141
GenerateAwsCommandState.AwsRegion,
142+
GenerateAwsCommandState.Agentless,
140143
GenerateAwsCommandState.Config,
141144
GenerateAwsCommandState.Cloudtrail,
142145
mods...)
@@ -315,6 +318,11 @@ func (a *AwsGenerateCommandExtraState) writeCache() {
315318
func initGenerateAwsTfCommandFlags() {
316319
// add flags to sub commands
317320
// TODO Share the help with the interactive generation
321+
generateAwsTfCommand.PersistentFlags().BoolVar(
322+
&GenerateAwsCommandState.Agentless,
323+
"agentless",
324+
false,
325+
"enable agentless integration")
318326
generateAwsTfCommand.PersistentFlags().BoolVar(
319327
&GenerateAwsCommandState.Cloudtrail,
320328
"cloudtrail",
@@ -486,6 +494,10 @@ func validateAwsProfile(val interface{}) error {
486494
return validateStringWithRegex(val, fmt.Sprintf(`^%s$`, AwsProfileRegex), "invalid profile name supplied")
487495
}
488496

497+
func promptAgentlessQuestions(config *aws.GenerateAwsTfConfigurationArgs) error {
498+
return nil
499+
}
500+
489501
func promptAwsCtQuestions(config *aws.GenerateAwsTfConfigurationArgs, extraState *AwsGenerateCommandExtraState) error {
490502
// Only ask these questions if configure cloudtrail is true
491503
if err := SurveyMultipleQuestionWithValidation([]SurveyQuestionWithValidationArgs{
@@ -770,6 +782,11 @@ func askAdvancedAwsOptions(config *aws.GenerateAwsTfConfigurationArgs, extraStat
770782
// we can have other accounts even if we only have Config integration (Scenario 7)
771783
var options []string
772784

785+
// Only show Advanced Agentless options if Agentless integration is set to true
786+
if config.Agentless {
787+
options = append(options, AdvancedOptAgentless)
788+
}
789+
773790
// Determine if user specified name for Config is potentially required
774791
if config.Config {
775792
options = append(options, QuestionCustomizeConfigName)
@@ -799,6 +816,10 @@ func askAdvancedAwsOptions(config *aws.GenerateAwsTfConfigurationArgs, extraStat
799816

800817
// Based on response, prompt for actions
801818
switch answer {
819+
case AdvancedOptAgentless:
820+
if err := promptAgentlessQuestions(config); err != nil {
821+
return err
822+
}
802823
case AdvancedOptCloudTrail:
803824
if err := promptAwsCtQuestions(config, extraState); err != nil {
804825
return err
@@ -843,11 +864,6 @@ func askAdvancedAwsOptions(config *aws.GenerateAwsTfConfigurationArgs, extraStat
843864
return nil
844865
}
845866

846-
func configOrCloudtrailEnabled(config *aws.GenerateAwsTfConfigurationArgs) *bool {
847-
cloudtrailOrConfigEnabled := config.Cloudtrail || config.Config
848-
return &cloudtrailOrConfigEnabled
849-
}
850-
851867
func awsConfigIsEmpty(g *aws.GenerateAwsTfConfigurationArgs) bool {
852868
return !g.Cloudtrail &&
853869
!g.Config &&
@@ -893,6 +909,10 @@ func promptAwsGenerate(
893909
// These are the core questions that should be asked. Region required for provider block
894910
if err := SurveyMultipleQuestionWithValidation(
895911
[]SurveyQuestionWithValidationArgs{
912+
{
913+
Prompt: &survey.Confirm{Message: QuestionEnableAgentless, Default: config.Agentless},
914+
Response: &config.Agentless,
915+
},
896916
{
897917
Prompt: &survey.Confirm{Message: QuestionAwsEnableConfig, Default: config.Config},
898918
Response: &config.Config,
@@ -905,20 +925,19 @@ func promptAwsGenerate(
905925
return err
906926
}
907927

928+
// Validate one of agentless, config or cloudtrail was enabled; otherwise error out
929+
if !config.Agentless && !config.Config && !config.Cloudtrail {
930+
return errors.New("must enable agentless, cloudtrail or config")
931+
}
932+
908933
if err := SurveyQuestionInteractiveOnly(SurveyQuestionWithValidationArgs{
909934
Prompt: &survey.Input{Message: QuestionAwsRegion, Default: config.AwsRegion},
910935
Response: &config.AwsRegion,
911936
Opts: []survey.AskOpt{survey.WithValidator(survey.Required), survey.WithValidator(validateAwsRegion)},
912-
Checks: []*bool{configOrCloudtrailEnabled(config)},
913937
}); err != nil {
914938
return err
915939
}
916940

917-
// Validate one of config or cloudtrail was enabled; otherwise error out
918-
if !config.Config && !config.Cloudtrail {
919-
return errors.New("must enable cloudtrail or config")
920-
}
921-
922941
// Find out if the customer wants to specify more advanced features
923942
if err := SurveyQuestionInteractiveOnly(SurveyQuestionWithValidationArgs{
924943
Prompt: &survey.Confirm{Message: QuestionAwsConfigAdvanced, Default: extraState.AskAdvanced},

cli/cmd/generate_aws_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestMissingValidEntityToConfigure(t *testing.T) {
3636
data := aws.GenerateAwsTfConfigurationArgs{}
3737
err := promptAwsGenerate(&data, &aws.ExistingIamRoleDetails{}, &AwsGenerateCommandExtraState{Output: "/tmp"})
3838
assert.Error(t, err)
39-
assert.Equal(t, "must enable cloudtrail or config", err.Error())
39+
assert.Equal(t, "must enable agentless, cloudtrail or config", err.Error())
4040
}
4141

4242
func TestArnRegex(t *testing.T) {

cli/docs/lacework_generate_cloud-account_aws.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ lacework generate cloud-account aws [flags]
3737
### Options
3838

3939
```
40+
--agentless enable agentless integration
4041
--apply run terraform apply without executing plan or prompting
4142
--aws_profile string specify aws profile
4243
--aws_region string specify aws region

0 commit comments

Comments
 (0)