Skip to content

Commit

Permalink
Add BigQuery dataset for cloud cost management (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcurtis authored Feb 24, 2024
1 parent 5018923 commit db412d0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ You can check the [test/fixtures](test/fixtures/) directory for example configur

Required APIs (managed with the [terraform-google-project](https://github.com/osinfra-io/terraform-google-project) child module):

- `bigquerydatatransfer.googleapis.com` (If `enable_cloud_cost_management` is `true`)
- `bigquery.googleapis.com` (If `enable_cloud_cost_management` is `true`)
- `cloudasset.googleapis.com`
- `cloudbilling.googleapis.com`
- `cloudresourcemanager.googleapis.com`
Expand Down
6 changes: 4 additions & 2 deletions global/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ No requirements.

| Name | Version |
|------|---------|
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | 3.33.0 |
| <a name="provider_google"></a> [google](#provider\_google) | 5.8.0 |
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | 3.36.1 |
| <a name="provider_google"></a> [google](#provider\_google) | 5.17.0 |

## Modules

Expand All @@ -23,6 +23,7 @@ No modules.
| Name | Type |
|------|------|
| [datadog_integration_gcp_sts.this](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/integration_gcp_sts) | resource |
| [google_bigquery_dataset.billing_export](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/bigquery_dataset) | resource |
| [google_logging_project_sink.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/logging_project_sink) | resource |
| [google_project_iam_member.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_iam_member) | resource |
| [google_pubsub_subscription.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription) | resource |
Expand All @@ -37,6 +38,7 @@ No modules.
|------|-------------|------|---------|:--------:|
| <a name="input_api_key"></a> [api\_key](#input\_api\_key) | Datadog API key | `string` | n/a | yes |
| <a name="input_cost_center"></a> [cost\_center](#input\_cost\_center) | The cost center to use for resource labels | `string` | n/a | yes |
| <a name="input_enable_cloud_cost_management"></a> [enable\_cloud\_cost\_management](#input\_enable\_cloud\_cost\_management) | Whether Datadog collects cloud cost management data from your GCP project, this should only be set to true in a single project | `bool` | `false` | no |
| <a name="input_is_cspm_enabled"></a> [is\_cspm\_enabled](#input\_is\_cspm\_enabled) | Whether Datadog collects cloud security posture management resources from your GCP project | `bool` | `false` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | A map of key/value pairs to assign to the resources being created | `map(string)` | <pre>{<br> "system": "datadog"<br>}</pre> | no |
| <a name="input_project"></a> [project](#input\_project) | Google Cloud Project ID being monitored | `string` | n/a | yes |
Expand Down
13 changes: 13 additions & 0 deletions global/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ resource "datadog_integration_gcp_sts" "this" {
host_filters = ["datadog:monitored"]
}

# Google BigQuery Dataset Resource
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/bigquery_dataset

resource "google_bigquery_dataset" "billing_export" {
count = var.enable_cloud_cost_management ? 1 : 0

dataset_id = "billing_export"
description = "Cloud Billing data to export to BigQuery"
friendly_name = "Billing Export"
labels = local.labels
project = var.project
}

# Google Service Account Resource
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account

Expand Down
6 changes: 6 additions & 0 deletions global/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ variable "cost_center" {
type = string
}

variable "enable_cloud_cost_management" {
description = "Whether Datadog collects cloud cost management data from your GCP project, this should only be set to true in a single project"
type = bool
default = false
}

variable "is_cspm_enabled" {
description = "Whether Datadog collects cloud security posture management resources from your GCP project"
type = bool
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/default_integration/infracost-usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ resource_type_default_usage:
# snapshot_storage_gb: 0.0 # Snapshot storage for unacknowledged messages in GB.
google_pubsub_topic:
monthly_message_data_tb: 0.1 # Monthly amount of message data published to the topic in TB.
##
## The following usage values apply to each resource of the given type, which is useful when you want to define defaults.
## All values are commented-out, you can uncomment resource types and customize as needed.
##
# google_bigquery_dataset:
# monthly_queries_tb: 0.0 # Monthly number of bytes processed (also referred to as bytes read) in TB.
# resource_usage:
##
## The following usage values apply to individual resources and override any value defined in the resource_type_default_usage section.
## All values are commented-out, you can uncomment resources and customize as needed.
##
# module.test.google_bigquery_dataset.billing_export[0]:
# monthly_queries_tb: 0.0 # Monthly number of bytes processed (also referred to as bytes read) in TB.
# module.test.google_logging_project_sink.this:
# monthly_logging_data_gb: 0.0 # Monthly logging data in GB.
# module.test.google_pubsub_subscription.this:
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/default_integration/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ provider "datadog" {
module "test" {
source = "../../../global"

api_key = var.api_key
cost_center = "x000"
is_cspm_enabled = true
api_key = var.api_key
cost_center = "x000"
enable_cloud_cost_management = true
is_cspm_enabled = true

labels = {
env = "sb"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/default_integration/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ variable "app_key" {
variable "project" {
type = string
default = "test-vpc-host-tf12-sb"
}
}

0 comments on commit db412d0

Please sign in to comment.