Skip to content

Commit d0e1a15

Browse files
authored
fix: BigQuery Log Alerting (#90)
* Fix README hyperlinks, split region variable in two variables, one for BQ and one for the CF, update required provider versions * add link to BigQuery and Cloud Function locations * adjust terraform version * simplify readme * change Requirements section * Chnage required version in example to 0.13.66 * revert required version change
1 parent baca384 commit d0e1a15

File tree

14 files changed

+180
-116
lines changed

14 files changed

+180
-116
lines changed

examples/bq-log-alerting/README.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,17 @@
22

33
This example deploys the BigQuery Log Alerting submodule in an existing project.
44

5-
## Prerequisites
5+
## Requirements
66

7-
To run this example, you'll need:
7+
Make sure you have the requirements listed in the submodule [README](../../modules/bq-log-alerting/README.md) Before running this example.
88

9-
- An existing "logging" project
10-
- A [Log export](https://github.com/terraform-google-modules/terraform-google-log-export) with a [BigQuery destination](https://github.com/terraform-google-modules/terraform-google-log-export/tree/master/modules/bigquery) in the logging project. The export filter should include at least:
11-
- "logName: /logs/cloudaudit.googleapis.com%2Factivity"
12-
- "logName: /logs/cloudaudit.googleapis.com%2Fdata_access"
13-
- "logName: /logs/compute.googleapis.com%2Fvpc_flows"
14-
- A Terraform Service Account with the [IAM Roles](../../../modules/bq-log-alerting/README.md) listed in the submodule documentation.
15-
- To enable in the logging project the [APIs](../../../modules/bq-log-alerting/README.md) listed in the submodule documentation.
16-
- To enable in the logging project [Google App Engine](https://cloud.google.com/appengine).
17-
To enable it manually use:
18-
19-
```shell
20-
gcloud app create \
21-
--region=<REGION> \
22-
--project=<LOGGING_PROJECT>
23-
```
9+
## Instructions
2410

25-
**Note 1:** The selected Google App Engine region cannot be changed after creation and only project Owners (`role/owner`) can enable Google App Engine.
11+
### Check if the Source "BQ Log Alerts" exist
2612

27-
**Note 2:** On deployment a Security Command Center Source called "BQ Log Alerts" will be created. If this source already exist due to the submodule been deployed at least once before, you need to obtain the existing Source name to be informed in the terraform variable **source_name**.
13+
On deployment a Security Command Center Source called "BQ Log Alerts" will be created.
14+
If this source already exist due to the submodule been deployed at least once before,
15+
you need to obtain the existing Source name to be informed in the terraform variable **source_name**.
2816
Run:
2917

3018
```shell
@@ -36,22 +24,59 @@ gcloud scc sources describe <ORG_ID> \
3624

3725
The source name format is `organizations/<ORG_ID>/sources/<SOURCE_ID>`.
3826

39-
The [terraform-example-foundation](https://github.com/terraform-google-modules/terraform-example-foundation) can be used as a reference for the creation of the logging project, the service account and the log export.
27+
### Activate impersonation of the service account
4028

41-
## Instructions
29+
To activate impersonation on the service account you can:
30+
31+
Set the `gcloud` config auth impersonation:
32+
33+
```shell
34+
gcloud config set auth/impersonate_service_account <TERRAFORM_SERVICE_ACCOUNT_EMAIL>
35+
```
36+
37+
Or
38+
39+
Change the [versions.tf](./versions.tf) file to set [impersonation on the provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#impersonate_service_account):
40+
41+
From
42+
43+
```terraform
44+
provider "google" {
45+
version = "~> 3.53.0"
46+
}
47+
48+
```
49+
50+
To
51+
52+
```terraform
53+
provider "google" {
54+
version = "~> 3.53.0"
55+
56+
impersonate_service_account = "<TERRAFORM_SERVICE_ACCOUNT_EMAIL>"
57+
}
58+
59+
```
60+
61+
### Run Terraform
4262

4363
1. Run `terraform init`
4464
1. Run `terraform plan` provide the requested variables values and review the output.
4565
1. Run `terraform apply`
4666

67+
### Deploy Use Cases
68+
69+
Deploy the [Use Cases](../../modules/bq-log-alerting/use-cases) that will provide the data for the Security Command Center findings.
70+
4771
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4872
## Inputs
4973

5074
| Name | Description | Type | Default | Required |
5175
|------|-------------|------|---------|:--------:|
76+
| bigquery\_location | Location for BigQuery resources. See https://cloud.google.com/bigquery/docs/locations for valid values. | `string` | `"US"` | no |
77+
| function\_region | Region for the Cloud function resources. See https://cloud.google.com/functions/docs/locations for valid values. | `string` | n/a | yes |
5278
| logging\_project | The project to deploy the submodule | `string` | n/a | yes |
5379
| org\_id | The organization ID for the associated services | `string` | n/a | yes |
54-
| region | Region for BigQuery resources. | `string` | n/a | yes |
5580
| source\_name | The Security Command Center Source name for the "BQ Log Alerts" Source if the source had been created before. The format is `organizations/<ORG_ID>/sources/<SOURCE_ID>` | `string` | `""` | no |
5681

5782
## Outputs

examples/bq-log-alerting/main.tf

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
/*****************************
18-
Provider configuration
19-
****************************/
20-
provider "google" {
21-
version = "~> 3.30"
22-
}
23-
2417
module "bq-log-alerting" {
25-
source = "../..//modules/bq-log-alerting"
26-
logging_project = var.logging_project
27-
region = var.region
28-
org_id = var.org_id
29-
source_name = var.source_name
30-
dry_run = false
18+
source = "../..//modules/bq-log-alerting"
19+
logging_project = var.logging_project
20+
bigquery_location = var.bigquery_location
21+
function_region = var.function_region
22+
org_id = var.org_id
23+
source_name = var.source_name
24+
dry_run = false
3125
}

examples/bq-log-alerting/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ variable "org_id" {
1919
type = string
2020
}
2121

22-
variable "region" {
23-
description = "Region for BigQuery resources."
22+
variable "function_region" {
23+
description = "Region for the Cloud function resources. See https://cloud.google.com/functions/docs/locations for valid values."
2424
type = string
2525
}
2626

27+
variable "bigquery_location" {
28+
description = "Location for BigQuery resources. See https://cloud.google.com/bigquery/docs/locations for valid values."
29+
type = string
30+
default = "US"
31+
}
32+
2733
variable "source_name" {
2834
description = "The Security Command Center Source name for the \"BQ Log Alerts\" Source if the source had been created before. The format is `organizations/<ORG_ID>/sources/<SOURCE_ID>`"
2935
type = string

examples/bq-log-alerting/versions.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
*/
1616

1717
terraform {
18-
required_version = ">=0.12.6, <0.14"
18+
required_version = ">=0.12.6"
19+
}
20+
21+
provider "google" {
22+
version = "~> 3.53.0"
1923
}

0 commit comments

Comments
 (0)