Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions test/examples/organization_api_enablement/cdr_ciem/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ The APIs needed for the CDR/CIEM feature are listed below:

# Set local variables for Organization ID and API services to enable
locals {
organizationID = "933620940614"
services = [
"pubsub.googleapis.com"
]
Expand All @@ -33,7 +32,11 @@ provider "google" {

# Get list of projects under the specified organization
data "google_projects" "organization_projects" {
filter = "parent.type:organization parent.id:${local.organizationID}"
filter = "parent.type:organization parent.id:${data.google_organization.org.org_id}"
}

data "google_organization" "org" {
domain = "draios.com"
}

data "local_file" "projects_from_folder" {
Expand Down Expand Up @@ -65,7 +68,7 @@ resource "null_resource" "get_projects_from_folders" {
provisioner "local-exec" {
command = <<EOF
#!/bin/bash
ORG_ID="933620940614"
ORG_DOMAIN="draios.com"

# array to store project IDs
declare -a FINAL_PROJECT_IDS
Expand Down Expand Up @@ -120,7 +123,15 @@ resource "null_resource" "get_projects_from_folders" {
done
}

echo "Listing all projects in folders for organization: $ORG_ID"
# start organization scraping
ORG_JSON=$(gcloud organizations list --filter="displayName:$ORG_DOMAIN" --format=json)
ORG_ID=$(echo "$ORG_JSON" | jq -r '.[0].name' | sed 's/organizations\///')
if [ -z "$ORG_ID" ]; then
echo "Organization with display name '$DISPLAY_NAME' not found."
exit 1
fi

echo "Listing all projects in folders for organization: $ORG_DOMAIN"
list_folders_recursive "$ORG_ID" "organization"
printf "%s\n" "$${FINAL_PROJECT_IDS[@]}" | jq -R . | jq -s . > "project_ids.json"
echo "Projects listed and saved to local file."
Expand Down
19 changes: 15 additions & 4 deletions test/examples/organization_api_enablement/cspm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ In addition, since CSPM is needed for onboard any GCP project these other APIs a

# Set local variables for Organization ID and API services to enable
locals {
organizationID = "933620940614"
services = [
# CSPM specific APIs
"sts.googleapis.com",
Expand Down Expand Up @@ -49,7 +48,11 @@ provider "google" {

# Get list of projects under the specified organization
data "google_projects" "organization_projects" {
filter = "parent.type:organization parent.id:${local.organizationID}"
filter = "parent.type:organization parent.id:${data.google_organization.org.org_id}"
}

data "google_organization" "org" {
domain = "draios.com"
}

data "local_file" "projects_from_folder" {
Expand Down Expand Up @@ -81,7 +84,7 @@ resource "null_resource" "get_projects_from_folders" {
provisioner "local-exec" {
command = <<EOF
#!/bin/bash
ORG_ID="933620940614"
ORG_DOMAIN="draios.com"

# array to store project IDs
declare -a FINAL_PROJECT_IDS
Expand Down Expand Up @@ -136,7 +139,15 @@ resource "null_resource" "get_projects_from_folders" {
done
}

echo "Listing all projects in folders for organization: $ORG_ID"
# start organization scraping
ORG_JSON=$(gcloud organizations list --filter="displayName:$ORG_DOMAIN" --format=json)
ORG_ID=$(echo "$ORG_JSON" | jq -r '.[0].name' | sed 's/organizations\///')
if [ -z "$ORG_ID" ]; then
echo "Organization with display name '$DISPLAY_NAME' not found."
exit 1
fi

echo "Listing all projects in folders for organization: $ORG_DOMAIN"
list_folders_recursive "$ORG_ID" "organization"
printf "%s\n" "$${FINAL_PROJECT_IDS[@]}" | jq -R . | jq -s . > "project_ids.json"
echo "Projects listed and saved to local file."
Expand Down
17 changes: 14 additions & 3 deletions test/examples/organization_api_enablement/vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ The APIs needed for the VM feature are listed below:

# Set local variables for Organization ID and API services to enable
locals {
organizationID = "933620940614"
services = [
"compute.googleapis.com"
]
Expand All @@ -33,7 +32,11 @@ provider "google" {

# Get list of projects under the specified organization
data "google_projects" "organization_projects" {
filter = "parent.type:organization parent.id:${local.organizationID}"
filter = "parent.type:organization parent.id:${data.google_organization.org.org_id}"
}

data "google_organization" "org" {
domain = "draios.com"
}

data "local_file" "projects_from_folder" {
Expand Down Expand Up @@ -66,7 +69,7 @@ resource "null_resource" "get_projects_from_folders" {
provisioner "local-exec" {
command = <<EOF
#!/bin/bash
ORG_ID="933620940614"
ORG_DOMAIN="draios.com"

# array to store project IDs
declare -a FINAL_PROJECT_IDS
Expand Down Expand Up @@ -121,6 +124,14 @@ resource "null_resource" "get_projects_from_folders" {
done
}

# start organization scraping
ORG_JSON=$(gcloud organizations list --filter="displayName:$ORG_DOMAIN" --format=json)
ORG_ID=$(echo "$ORG_JSON" | jq -r '.[0].name' | sed 's/organizations\///')
if [ -z "$ORG_ID" ]; then
echo "Organization with display name '$DISPLAY_NAME' not found."
exit 1
fi

echo "Listing all projects in folders for organization: $ORG_ID"
list_folders_recursive "$ORG_ID" "organization"
printf "%s\n" "$${FINAL_PROJECT_IDS[@]}" | jq -R . | jq -s . > "project_ids.json"
Expand Down
Loading