Skip to content

Commit

Permalink
fix(cli): Remove Additional Cloudtrail/AuditLog options when Cloudtra…
Browse files Browse the repository at this point in the history
…il/AuditLog Integration is set to No (#782)

* fix(cli): Remove Additional Cloudtrail/AuditLog options when Cloudtrail/AuditLog Integration is set to No

Signed-off-by: Ross <[email protected]>

* fix(cli): Revert default profiel change

Signed-off-by: Ross <[email protected]>

* fix(cli): Update integration tests

Signed-off-by: Ross <[email protected]>
  • Loading branch information
rmoles committed Apr 27, 2022
1 parent 3b3aacf commit c9d7f48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
11 changes: 9 additions & 2 deletions cli/cmd/generate_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,18 @@ func askAdvancedAwsOptions(config *aws.GenerateAwsTfConfigurationArgs, extraStat
// difficult when the options are dynamic (which they are)
//
// Only ask about more accounts if consolidated cloudtrail is setup (matching scenarios doc)
options := []string{AdvancedOptCloudTrail, AdvancedOptIamRole}
var options []string

// Only show Advanced CloudTrail options if CloudTrail integration is set to true
if config.Cloudtrail {
options = append(options, AdvancedOptCloudTrail)
}

if config.ConsolidatedCloudtrail {
options = append(options, AdvancedOptAwsAccounts)
}
options = append(options, AwsAdvancedOptLocation, AwsAdvancedOptDone)

options = append(options, AdvancedOptIamRole, AwsAdvancedOptLocation, AwsAdvancedOptDone)
if err := SurveyQuestionInteractiveOnly(SurveyQuestionWithValidationArgs{
Prompt: &survey.Select{
Message: "Which options would you like to configure?",
Expand Down
9 changes: 7 additions & 2 deletions cli/cmd/generate_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,14 @@ func askAdvancedOptions(config *gcp.GenerateGcpTfConfigurationArgs, extraState *
// Construction of this slice is a bit strange at first look, but the reason for that is because we have to do string
// validation to know which option was selected due to how survey works; and doing it by index (also supported) is
// difficult when the options are dynamic (which they are)
options := []string{GcpAdvancedOptAuditLog, GcpAdvancedOptExistingServiceAccount, GcpAdvancedOptIntegrationName}
var options []string

options = append(options, GcpAdvancedOptLocation, GcpAdvancedOptDone)
// Only show Advanced AuditLog options if AuditLog integration is set to true
if config.AuditLog {
options = append(options, GcpAdvancedOptAuditLog)
}

options = append(options, GcpAdvancedOptExistingServiceAccount, GcpAdvancedOptIntegrationName, GcpAdvancedOptLocation, GcpAdvancedOptDone)
if err := SurveyQuestionInteractiveOnly(SurveyQuestionWithValidationArgs{
Prompt: &survey.Select{
Message: "Which options would you like to configure?",
Expand Down
8 changes: 3 additions & 5 deletions integration/aws_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ func TestGenerationAdvancedOptsConsolidatedWithSubAccounts(t *testing.T) {
expectString(t, c, cmd.QuestionAwsAnotherAdvancedOpt)
c.SendLine("y")
expectString(t, c, cmd.AwsAdvancedOptDone)
c.Send("\x1B[B") // Down arrow twice and enter on the submenu to add subaccounts
c.SendLine("\x1B[B")
c.SendLine("\x1B[B") // Down arrow once and enter on the submenu to add subaccounts
expectString(t, c, cmd.QuestionPrimaryAwsAccountProfile)
c.SendLine("default")
expectString(t, c, cmd.QuestionSubAccountProfileName)
Expand Down Expand Up @@ -377,8 +376,7 @@ func TestGenerationAdvancedOptsConsolidatedWithSubAccountsPassedByFlag(t *testin
expectString(t, c, cmd.QuestionAwsConfigAdvanced)
c.SendLine("y")
expectString(t, c, cmd.AwsAdvancedOptDone)
c.Send("\x1B[B") // Down arrow twice and enter on the submenu to add subaccounts
c.SendLine("\x1B[B")
c.SendLine("\x1B[B") // Down arrow once and enter on the submenu to add subaccounts
expectString(t, c, cmd.QuestionPrimaryAwsAccountProfile)
c.SendLine("default")
expectString(t, c, fmt.Sprintf(cmd.QuestionSubAccountReplace, "testaccount:us-east-1, testaccount1:us-east-2"))
Expand Down Expand Up @@ -423,7 +421,7 @@ func TestGenerationAdvancedOptsConsolidatedWithSubAccountsPassedByFlag(t *testin
assert.Equal(t, buildTf, tfResult)
}

// Test use existing IAM rolej
// Test use existing IAM role
func TestGenerationAdvancedOptsUseExistingIAM(t *testing.T) {
os.Setenv("LW_NOCACHE", "true")
defer os.Setenv("LW_NOCACHE", "")
Expand Down

0 comments on commit c9d7f48

Please sign in to comment.