From d9018d01836ca5dd0effafa73c89bf3e1867f36c Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Tue, 16 Jul 2024 16:48:00 +0000 Subject: [PATCH] feat(GROW-2949): Provide organization_id for project level integration Signed-off-by: Lei Jin --- lwgenerate/gcp/gcp.go | 13 +++++++++++++ lwgenerate/gcp/gcp_test.go | 12 ++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lwgenerate/gcp/gcp.go b/lwgenerate/gcp/gcp.go index a0c93d67f..52e9cd2fb 100644 --- a/lwgenerate/gcp/gcp.go +++ b/lwgenerate/gcp/gcp.go @@ -141,6 +141,10 @@ type GenerateGcpTfConfigurationArgs struct { Projects []string + // GCP organization id for agentless integration. Agentless integration requires an organization id + // even for project level integration + AgentlessOrganizationId string + // Default GCP Provider labels ProviderDefaultLabels map[string]interface{} @@ -231,6 +235,13 @@ func WithUsePubSubAudit(usePubSub bool) GcpTerraformModifier { } } +// WithAgentlessOrganizationId Set the agentless organization id for GCP provider +func WithAgentlessOrganizationId(organizationId string) GcpTerraformModifier { + return func(c *GenerateGcpTfConfigurationArgs) { + c.AgentlessOrganizationId = organizationId + } +} + // WithGcpServiceAccountCredentials Set the path for the GCP Service Account to be utilized by the GCP provider func WithGcpServiceAccountCredentials(path string) GcpTerraformModifier { return func(c *GenerateGcpTfConfigurationArgs) { @@ -632,6 +643,8 @@ func createAgentless(args *GenerateGcpTfConfigurationArgs) ([]*hclwrite.Block, e if args.OrganizationIntegration { attributes["integration_type"] = "ORGANIZATION" attributes["organization_id"] = args.GcpOrganizationId + } else if len(args.AgentlessOrganizationId) > 0 { + attributes["organization_id"] = args.AgentlessOrganizationId } } if i > 0 { diff --git a/lwgenerate/gcp/gcp_test.go b/lwgenerate/gcp/gcp_test.go index 31dd74b65..1dbeff972 100644 --- a/lwgenerate/gcp/gcp_test.go +++ b/lwgenerate/gcp/gcp_test.go @@ -720,6 +720,7 @@ func TestGenerateGcpTfConfigurationArgs_Generate_Agentless(t *testing.T) { "TestGenerationProjectLevelAgentless", gcp.NewTerraform(true, false, false, false, gcp.WithProjectId(projectName), + gcp.WithAgentlessOrganizationId("123456789"), gcp.WithRegions([]string{"us-east1"}), ), fmt.Sprintf("%s\n%s", RequiredProviders, moduleImportProjectLevelAgentless), @@ -729,6 +730,7 @@ func TestGenerateGcpTfConfigurationArgs_Generate_Agentless(t *testing.T) { gcp.NewTerraform(true, false, false, false, gcp.WithProjectId(projectName), gcp.WithRegions([]string{"us-east1"}), + gcp.WithAgentlessOrganizationId("123456789"), gcp.WithProjectFilterList([]string{"p1", "p2"}), ), fmt.Sprintf("%s\n%s", RequiredProviders, moduleImportProjectLevelAgentlessWithProjectFilterList), @@ -1181,10 +1183,11 @@ var moduleImportProjectLevelAgentless = `provider "google" { } module "lacework_gcp_agentless_scanning_global" { - source = "lacework/agentless-scanning/gcp" - version = "~> 2.0" - global = true - regional = true + source = "lacework/agentless-scanning/gcp" + version = "~> 2.0" + global = true + organization_id = "123456789" + regional = true providers = { google = google.us-east1 @@ -1202,6 +1205,7 @@ module "lacework_gcp_agentless_scanning_global" { source = "lacework/agentless-scanning/gcp" version = "~> 2.0" global = true + organization_id = "123456789" project_filter_list = ["p1", "p2"] regional = true