Skip to content

Commit e2775cf

Browse files
authored
fix: add correct terraform attribute for Pub Sub Audit log generation (#1265)
1 parent 3475b5f commit e2775cf

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

integration/gcp_generation_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,45 @@ func TestGenerationPubSubAuditlogOnlyGcp(t *testing.T) {
182182
assert.Equal(t, buildTf, tfResult)
183183
}
184184

185+
func TestGenerationPubSubAuditlogOrgGcp(t *testing.T) {
186+
os.Setenv("LW_NOCACHE", "true")
187+
defer os.Setenv("LW_NOCACHE", "")
188+
var final string
189+
190+
tfResult := runGcpGenerateTest(t,
191+
func(c *expect.Console) {
192+
expectsCliOutput(t, c, []MsgRspHandler{
193+
MsgRsp{cmd.QuestionGcpEnableConfiguration, "n"},
194+
MsgRsp{cmd.QuestionGcpEnableAuditLog, "y"},
195+
MsgRsp{cmd.QuestionGcpProjectID, projectId},
196+
MsgRsp{cmd.QuestionGcpOrganizationIntegration, "y"},
197+
MsgRsp{cmd.QuestionGcpOrganizationID, organizationId},
198+
MsgRsp{cmd.QuestionGcpServiceAccountCredsPath, ""},
199+
MsgRsp{cmd.QuestionGcpConfigureAdvanced, "y"},
200+
MsgMenu{cmd.GcpAdvancedOptAuditLog, 0},
201+
MsgRsp{cmd.QuestionUsePubSubAudit, "y"},
202+
MsgRsp{cmd.QuestionGcpUseExistingSink, "n"},
203+
MsgRsp{cmd.QuestionGcpCustomFilter, ""},
204+
MsgRsp{cmd.QuestionGcpAnotherAdvancedOpt, "n"},
205+
MsgRsp{cmd.QuestionRunTfPlan, "n"},
206+
})
207+
208+
final, _ = c.ExpectEOF()
209+
},
210+
"generate",
211+
"cloud-account",
212+
"gcp",
213+
)
214+
215+
assertTerraformSaved(t, final)
216+
217+
buildTf, _ := gcp.NewTerraform(false, true, true,
218+
gcp.WithProjectId(projectId),
219+
gcp.WithOrganizationIntegration(true),
220+
gcp.WithOrganizationId(organizationId),
221+
).Generate()
222+
assert.Equal(t, buildTf, tfResult)
223+
}
185224
func TestGenerationAuditlogEnableUBLA(t *testing.T) {
186225
os.Setenv("LW_NOCACHE", "true")
187226
defer os.Setenv("LW_NOCACHE", "")

lwgenerate/gcp/gcp.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ func createAuditLog(args *GenerateGcpTfConfigurationArgs) (*hclwrite.Block, erro
611611
// if organization integration is true, override configModuleName to use the organization level module
612612
configurationModuleName = "gcp_organization_level_config"
613613
auditLogModuleName = "gcp_organization_level_audit_log"
614-
attributes["org_integration"] = args.OrganizationIntegration
614+
// Determine if this is the a pub-sub audit log
615+
if args.UsePubSubAudit {
616+
attributes["integration_type"] = "ORGANIZATION"
617+
} else {
618+
attributes["org_integration"] = args.OrganizationIntegration
619+
}
615620
attributes["organization_id"] = args.GcpOrganizationId
616621

617622
if len(args.FoldersToInclude) > 0 {

lwgenerate/gcp/gcp_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ var moduleImportOrganizationLevelAuditLogWithConfiguration = `module "gcp_organi
932932
var moduleImportOrganizationLevelPubSubAuditLogWithConfiguration = `module "gcp_organization_level_audit_log" {
933933
source = "lacework/pub-sub-audit-log/gcp"
934934
version = "~> 0.2"
935-
org_integration = true
935+
integration_type = "ORGANIZATION"
936936
organization_id = "123456789"
937937
service_account_name = module.gcp_organization_level_config.service_account_name
938938
service_account_private_key = module.gcp_organization_level_config.service_account_private_key
@@ -949,10 +949,10 @@ var moduleImportOrganizationLevelAuditLogWithoutConfiguration = `module "gcp_org
949949
`
950950

951951
var moduleImportOrganizationLevelPubSubAuditLogWithoutConfiguration = `module "gcp_organization_level_audit_log" {
952-
source = "lacework/pub-sub-audit-log/gcp"
953-
version = "~> 0.2"
954-
org_integration = true
955-
organization_id = "123456789"
952+
source = "lacework/pub-sub-audit-log/gcp"
953+
version = "~> 0.2"
954+
integration_type = "ORGANIZATION"
955+
organization_id = "123456789"
956956
}
957957
`
958958
var moduleImportOrganizationLevelAuditLogCustomIntegrationName = `module "gcp_organization_level_audit_log" {
@@ -966,8 +966,8 @@ var moduleImportOrganizationLevelAuditLogCustomIntegrationName = `module "gcp_or
966966
var moduleImportOrganizationLevelPubSubAuditLogCustomIntegrationName = `module "gcp_organization_level_audit_log" {
967967
source = "lacework/pub-sub-audit-log/gcp"
968968
version = "~> 0.2"
969+
integration_type = "ORGANIZATION"
969970
lacework_integration_name = "custom_integration_name"
970-
org_integration = true
971971
organization_id = "123456789"
972972
}
973973
`

0 commit comments

Comments
 (0)