Skip to content

Commit

Permalink
feat(GROW-2949): Provide organization_id for project level integration
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Jin <lei.jin@lacework.net>
  • Loading branch information
leijin-lw committed Jul 16, 2024
1 parent 5edd4ca commit d9018d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lwgenerate/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions lwgenerate/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d9018d0

Please sign in to comment.