Skip to content

Commit f2b149d

Browse files
authored
Merge pull request #5 from aquasecurity/muliple-dedicated-example
Adding `multiple-dedicated-project` example
2 parents 608ddc8 + 6824d87 commit f2b149d

File tree

9 files changed

+239
-45
lines changed

9 files changed

+239
-45
lines changed

.github/workflows/pr-checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
TEST_CASES=(
2222
examples/dedicated-project
2323
examples/same-project
24+
examples/multiple-dedicated-project
2425
)
2526
2627
for tcase in ${TEST_CASES[@]}; do

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ to enable seamless integration with Aqua’s platform.
1919
- [Pre-requisites](#Pre-requisites)
2020
- [Usage](#usage)
2121
- [Examples](#examples)
22-
- [Using Existing Network](#using-existing-network-and-firewall)
2322
- [Using Dedicated Project](#using-an-existing-dedicated-project)
23+
- [Using Existing Network](#using-existing-network-and-firewall)
2424

2525
## Pre-requisites
2626

@@ -103,6 +103,7 @@ module "aqua_gcp_onboarding" {
103103
type = local.type
104104
project_id = module.aqua_gcp_dedicated_project.project_id # Dedicated project for Aqua resources
105105
region = local.region
106+
dedicated_project = local.dedicated
106107
org_name = local.org_name
107108
aqua_tenant_id = local.tenant_id
108109
aqua_aws_account_id = local.aqua_aws_account_id
@@ -142,47 +143,63 @@ module "aqua_gcp_project_attachment" {
142143

143144
For more examples and use cases, please refer to the examples folder in the repository.
144145

146+
## Using an Existing Dedicated Project
145147

146-
## Using Existing Network and Firewall
148+
If you have an existing dedicated project that you want to use to host Aqua Security resources, you can import it into the Terraform configuration.
147149

150+
To do so, use the following Terraform import command:
148151

149-
If you prefer to use an existing network and firewall instead of creating new ones,
150-
you can do so by setting `create_network = false` in the module's input variables.
151-
In this case, you will need to create,
152-
prior to onboarding, network and firewall resources with the following naming convention:
152+
`terraform import module.aqua_gcp_dedicated_project.google_project.project <dedicated_project_id>`
153153

154154

155-
* Firewall: `<project_id>-rules-aqua-aas`
156-
* Network: `<project_id>-network`
155+
Replace `<dedicated_project_id>` with the ID of your existing dedicated project.
157156

158-
When using a dedicated project, the `<project_id>` should follow the format `"aqua-agentless-${local.tenant_id}-${local.org_hash}"`.
157+
It's important to note that the dedicated project ID should follow the naming convention `"aqua-agentless-${local.tenant_id}-${local.org_hash}"`, where local.org_hash is calculated as:
159158

159+
`org_hash = substr(sha1(<org_name>), 0, 6)`
160160

161-
## Using an Existing Dedicated Project
161+
You can also check for the naming convention using the bash command:
162162

163-
If you have an existing dedicated project that you want to use to host Aqua Security resources, you can import it into the Terraform configuration.
163+
```bash
164+
#!/bin/bash
164165

165-
To do so, use the following Terraform import command:
166+
# Replace with your Aqua tenant ID
167+
TENANT_ID="<your_tenant_id>"
166168

167-
`terraform import module.aqua_gcp_dedicated_project.google_project.project <dedicated_project_id>`
169+
# Replace with your organization name
170+
ORG_NAME="<your_org_name>"
168171

172+
# Calculate the org_hash
173+
ORG_HASH=$(echo -n "${ORG_NAME}" | shasum -a 1 | awk '{ print $1 }' | cut -c1-6)
169174

170-
Replace `<dedicated_project_id>` with the ID of your existing dedicated project.
175+
# Print the dedicated project ID naming convention
176+
echo "aqua-agentless-${TENANT_ID}-${ORG_HASH}"
177+
```
171178

172-
It's important to note that the dedicated project ID should follow the naming convention `"aqua-agentless-${local.tenant_id}-${local.org_hash}"`, where local.org_hash is calculated as:
179+
For example, if your Aqua tenant ID is `12345` and the first six characters of the SHA1 hash of your organization name are `12a456`, the dedicated project ID should be `aqua-agentless-12345-12a456`.
173180

174-
`org_hash = substr(sha1(<org_name>), 0, 6)`
175181

182+
## Using Existing Network and Firewall
176183

177-
For example, if your Aqua tenant ID is `12345` and the first six characters of the SHA1 hash of your organization name are `12a456`, the dedicated project ID should be `aqua-agentless-12345-12a456`.
184+
185+
If you prefer to use an existing network and firewall instead of creating new ones,
186+
you can do so by setting `create_network = false` in the module's input variables.
187+
In this case, you will need to create,
188+
prior to onboarding, network and firewall resources with the following naming convention:
189+
190+
191+
* Firewall: `<project_id>-rules-aqua-aas`
192+
* Network: `<project_id>-network`
193+
194+
When using a dedicated project, the `<project_id>` should follow the format `"aqua-agentless-${local.tenant_id}-${local.org_hash}"` as mentioned above.
178195

179196

180197
<!-- BEGIN_TF_DOCS -->
181198
## Requirements
182199

183200
| Name | Version |
184201
|------|---------|
185-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.6.4 |
202+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.4 |
186203
| <a name="requirement_external"></a> [external](#requirement\_external) | ~> 2.3.3 |
187204
| <a name="requirement_google"></a> [google](#requirement\_google) | ~> 5.20.0 |
188205
| <a name="requirement_http"></a> [http](#requirement\_http) | ~> 3.4.2 |

examples/dedicated-project/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ This example demonstrates how to onboard a GCP project by creating a dedicated p
1111
Before running this example, ensure that you have the following:
1212

1313
1. Terraform installed (version 1.6.4 or later).
14-
2. `Gcloud` CLI installed and configured.
14+
2. `gcloud` CLI installed and configured.
1515
3. Aqua Security account API credentials.
1616

1717
## Usage
1818

1919
1. Obtain the Terraform configuration file generated by the Aqua platform.
2020
2. Important: Replace `<aqua_api_key>` and `<aqua_api_secret>` with your generated API credentials.
2121
3. Run `terraform init` to initialize the Terraform working directory.
22-
4. Run `terraform apply` to create the dedicated project.
22+
4. Run `terraform apply` to create the resources.
2323

2424
## What's Happening
2525

examples/dedicated-project/main.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ locals {
44
region = "us-central1"
55
dedicated = true
66
type = "single"
7-
org_name = "<org_name>"
8-
aqua_tenant_id = "<tenant_id>"
9-
project_id = "<project_id>"
7+
org_name = "my-org-name"
8+
aqua_tenant_id = "12345"
9+
project_id = "my-project-id"
1010
aqua_aws_account_id = "123456789101"
11-
aqua_bucket_name = "<aqua_bucket_name>"
12-
aqua_configuration_id = "<aqua_configuration_id>"
11+
aqua_bucket_name = "generic-bucket-name"
12+
aqua_configuration_id = "234e3cea-d84a-4b9e-bb36-92518e6a5772"
1313
aqua_cspm_group_id = 123456
14-
aqua_custom_labels = {}
15-
aqua_api_key = "<aqua_api_key>"
16-
aqua_api_secret = "<aqua_api_secret>"
17-
aqua_autoconnect_url = "https://<aqua_autoconnect_url>.com"
18-
aqua_volscan_api_token = "<aqua_volscan_api_token>"
19-
aqua_volscan_api_url = "https://<aqua_volscan_api_url>.com"
14+
aqua_custom_labels = { custom = "label" }
15+
aqua_api_key = "<REPLACE_ME>"
16+
aqua_api_secret = "<REPLACE_ME>"
17+
aqua_autoconnect_url = "https://example-aqua-autoconnect-url.com"
18+
aqua_volscan_api_token = "<REPLACE_ME>"
19+
aqua_volscan_api_url = "https://example-aqua-volscan-api-url.com"
2020
dedicated_project_id = "aqua-agentless-${local.aqua_tenant_id}-${local.org_hash}"
2121
labels = merge(local.aqua_custom_labels, { "aqua-agentless-scanner" = "true" })
2222
org_hash = substr(sha1(local.org_name), 0, 6)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# GCP Multi-Project Onboarding Example
2+
3+
---
4+
5+
## Overview
6+
7+
This example demonstrates how to onboard multiple existing Google Cloud Platform (GCP) projects to Aqua Security. It creates a dedicated project for provisioning Aqua resources and then attaches the existing projects to the dedicated project for Aqua Security integration.
8+
9+
## Pre-requisites
10+
11+
Before running this example, ensure that you have the following:
12+
13+
1. Terraform installed (version 1.6.4 or later).
14+
2. `gcloud` CLI installed and configured.
15+
3. Aqua Security account API credentials.
16+
17+
## Usage
18+
19+
1. Obtain the Terraform configuration file generated by the Aqua Security UI. This file will have most of the required values pre-filled, except for the API key and secret.
20+
2. Important: Replace `<aqua_api_key>` and `<aqua_api_secret>` with your generated API credentials.
21+
3. Run `terraform init` to initialize the Terraform working directory.
22+
4. Run `terraform apply` to create the resources.
23+
24+
## What's Happening
25+
26+
1. The `aqua_gcp_dedicated_project` module is called to create a dedicated GCP project with the name `aqua-agentless-<tenant_id>-<org_hash>`, where `org_hash` is the first six characters of the SHA1 hash of your organization name.
27+
2. The `aqua_gcp_onboarding` module is called to provision the necessary resources (service accounts, roles, networking, etc.) in the dedicated GCP project.
28+
3. The `aqua_gcp_project_attachment` module is called to create the required IAM resources in the existing project and trigger the Aqua API to onboard the project.
29+
5. The `aqua_gcp_additional_project_attachment` module is called to create the required IAM resources in the additional project (`my-additional-project-id`) and trigger the Aqua API to onboard the project.
30+
31+
## Outputs
32+
33+
- `onboarding_status`: The output from the `aqua_gcp_project_attachment` module, displaying the result of the onboarding process for the project `<project_id>`.
34+
- `additional_project_onboarding_status`: The output from the `aqua_gcp_additional_project_attachment` module, displaying the result of the onboarding process for the project `my-additional-project-id`.
35+
36+
## Cleanup
37+
38+
To remove the dedicated project and all associated resources created by this example, run `terraform destroy`.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
# Defining local variables
3+
locals {
4+
region = "us-central1"
5+
dedicated = true
6+
type = "single"
7+
org_name = "my-org-name"
8+
aqua_tenant_id = "12345"
9+
project_id = "my-project-id"
10+
aqua_aws_account_id = "123456789101"
11+
aqua_bucket_name = "generic-bucket-name"
12+
aqua_configuration_id = "234e3cea-d84a-4b9e-bb36-92518e6a5772"
13+
aqua_cspm_group_id = 123456
14+
aqua_custom_labels = {}
15+
aqua_api_key = "<REPLACE_ME>"
16+
aqua_api_secret = "<REPLACE_ME>"
17+
aqua_autoconnect_url = "https://example-aqua-autoconnect-url.com"
18+
aqua_volscan_api_token = "<REPLACE_ME>"
19+
aqua_volscan_api_url = "https://example-aqua-volscan-api-url.com"
20+
dedicated_project_id = "aqua-agentless-${local.aqua_tenant_id}-${local.org_hash}"
21+
labels = merge(local.aqua_custom_labels, { "aqua-agentless-scanner" = "true" })
22+
org_hash = substr(sha1(local.org_name), 0, 6)
23+
}
24+
25+
################################
26+
27+
# Defining the root google provider
28+
provider "google" {
29+
project = local.project_id
30+
region = local.region
31+
default_labels = local.labels
32+
}
33+
34+
# Creating a dedicated project
35+
module "aqua_gcp_dedicated_project" {
36+
source = "../../modules/dedicated_project"
37+
org_name = local.org_name
38+
project_id = local.dedicated_project_id
39+
root_project_id = local.project_id
40+
labels = local.labels
41+
}
42+
43+
################################
44+
45+
# Defining the dedicated google provider
46+
provider "google" {
47+
alias = "dedicated"
48+
project = module.aqua_gcp_dedicated_project.project_id
49+
region = local.region
50+
default_labels = local.labels
51+
}
52+
53+
# Creating discovery and scanning resources on the project
54+
module "aqua_gcp_onboarding" {
55+
source = "../../"
56+
providers = {
57+
google.onboarding = google.dedicated
58+
}
59+
type = local.type
60+
project_id = module.aqua_gcp_dedicated_project.project_id
61+
dedicated_project = local.dedicated
62+
region = local.region
63+
org_name = local.org_name
64+
aqua_tenant_id = local.aqua_tenant_id
65+
aqua_aws_account_id = local.aqua_aws_account_id
66+
aqua_bucket_name = local.aqua_bucket_name
67+
aqua_custom_labels = local.aqua_custom_labels
68+
aqua_volscan_api_token = local.aqua_volscan_api_token
69+
aqua_volscan_api_url = local.aqua_volscan_api_url
70+
depends_on = [module.aqua_gcp_dedicated_project]
71+
}
72+
73+
################################
74+
75+
# Onboarding a project and attaching it to the dedicated project
76+
module "aqua_gcp_project_attachment" {
77+
source = "../../modules/project_attachment"
78+
providers = {
79+
google = google
80+
}
81+
aqua_api_key = local.aqua_api_key
82+
aqua_api_secret = local.aqua_api_secret
83+
aqua_autoconnect_url = local.aqua_autoconnect_url
84+
aqua_bucket_name = local.aqua_bucket_name
85+
aqua_configuration_id = local.aqua_configuration_id
86+
aqua_cspm_group_id = local.aqua_cspm_group_id
87+
org_name = local.org_name
88+
project_id = local.project_id
89+
dedicated_project = local.dedicated
90+
labels = local.aqua_custom_labels
91+
create_role_id = module.aqua_gcp_onboarding.create_role_id
92+
onboarding_service_account_email = module.aqua_gcp_onboarding.service_account_email
93+
onboarding_workload_identity_pool_id = module.aqua_gcp_onboarding.workload_identity_pool_id
94+
onboarding_workload_identity_pool_provider_id = module.aqua_gcp_onboarding.workload_identity_pool_provider_id
95+
onboarding_project_number = module.aqua_gcp_onboarding.project_number
96+
depends_on = [module.aqua_gcp_onboarding]
97+
}
98+
99+
output "onboarding_status" {
100+
value = module.aqua_gcp_project_attachment.onboarding_status
101+
}
102+
103+
#################################
104+
105+
# Defining the additional google provider
106+
provider "google" {
107+
alias = "additional"
108+
project = "my-additional-project-id"
109+
region = local.region
110+
default_labels = local.labels
111+
}
112+
113+
## Onboarding an additional project and attaching it to the dedicated project
114+
module "aqua_gcp_additional_project_attachment" {
115+
source = "../../modules/project_attachment"
116+
providers = {
117+
google = google.additional # Referencing the additional Google provider
118+
}
119+
aqua_api_key = local.aqua_api_key
120+
aqua_api_secret = local.aqua_api_secret
121+
aqua_autoconnect_url = local.aqua_autoconnect_url
122+
aqua_bucket_name = local.aqua_bucket_name
123+
aqua_configuration_id = local.aqua_configuration_id
124+
aqua_cspm_group_id = local.aqua_cspm_group_id
125+
org_name = local.org_name
126+
project_id = local.project_id
127+
dedicated_project = local.dedicated
128+
labels = local.aqua_custom_labels
129+
create_role_id = module.aqua_gcp_onboarding.create_role_id
130+
onboarding_service_account_email = module.aqua_gcp_onboarding.service_account_email
131+
onboarding_workload_identity_pool_id = module.aqua_gcp_onboarding.workload_identity_pool_id
132+
onboarding_workload_identity_pool_provider_id = module.aqua_gcp_onboarding.workload_identity_pool_provider_id
133+
onboarding_project_number = module.aqua_gcp_onboarding.project_number
134+
depends_on = [module.aqua_gcp_onboarding]
135+
}
136+
137+
output "additional_project_onboarding_status" {
138+
value = module.aqua_gcp_additional_project_attachment.onboarding_status
139+
}
140+

examples/same-project/main.tf

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ locals {
44
region = "us-central1"
55
dedicated = false
66
type = "single"
7-
org_name = "<org_name>"
8-
aqua_tenant_id = "<tenant_id>"
9-
project_id = "<project_id>"
7+
org_name = "" # Leave empty for same-project onboarding
8+
aqua_tenant_id = "12345"
9+
project_id = "my-project-id"
1010
aqua_aws_account_id = "123456789101"
11-
aqua_bucket_name = "<aqua_bucket_name>"
12-
aqua_configuration_id = "<aqua_configuration_id>"
11+
aqua_bucket_name = "generic-bucket-name"
12+
aqua_configuration_id = "234e3cea-d84a-4b9e-bb36-92518e6a5772"
1313
aqua_cspm_group_id = 123456
1414
aqua_custom_labels = { label = "true" }
15-
aqua_api_key = "<aqua_api_key>"
16-
aqua_api_secret = "<aqua_api_secret>"
17-
aqua_autoconnect_url = "https://<aqua_autoconnect_url>.com"
18-
aqua_volscan_api_token = "<aqua_volscan_api_token>"
19-
aqua_volscan_api_url = "https://<aqua_volscan_api_url>.com"
20-
dedicated_project_id = "aqua-agentless-${local.aqua_tenant_id}-${local.org_hash}"
15+
aqua_api_key = "<REPLACE_ME>"
16+
aqua_api_secret = "<REPLACE_ME>"
17+
aqua_autoconnect_url = "https://example-aqua-autoconnect-url.com"
18+
aqua_volscan_api_token = "<REPLACE_ME>"
19+
aqua_volscan_api_url = "https://example-aqua-volscan-api-url.com"
2120
labels = merge(local.aqua_custom_labels, { "aqua-agentless-scanner" = "true" })
22-
org_hash = substr(sha1(local.org_name), 0, 6)
2321
}
2422

2523
################################

modules/project_attachment/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# modules/project_attachment/versions.tf
22

33
terraform {
4-
required_version = "~> 1.6.4"
4+
required_version = ">= 1.6.4"
55
required_providers {
66
google = {
77
source = "hashicorp/google"

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# versions.tf
22

33
terraform {
4-
required_version = "~> 1.6.4"
4+
required_version = ">= 1.6.4"
55
required_providers {
66
google = {
77
source = "hashicorp/google"

0 commit comments

Comments
 (0)