Skip to content

Commit

Permalink
add support for labeling resources
Browse files Browse the repository at this point in the history
  • Loading branch information
cleentfaar committed Dec 9, 2024
1 parent 4c0bca6 commit f0a2b6f
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ help: ## Show this help message.
@echo 'targets:'
@egrep '^(.+)\:(.+)?\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'

cs: build ## Checks for code style issues
docker-compose run --rm python black --check .
cs: ## Checks for code style issues
docker compose run --rm cs black --check .
terraform -chdir=terraform fmt -check -recursive .

cs-fix: build ## Fixes code style issues
docker-compose run --rm python black .
cs-fix: ## Fixes code style issues
docker compose run --rm cs black .
terraform -chdir=terraform fmt -recursive .

build: ## Builds the image including the setup.py file (run this when you've changed dependencies)
docker-compose build python
docker compose build python

test: build ## Runs all tests for this library
docker-compose run --rm python pytest $(ARGS)
docker compose run --rm python pytest $(ARGS)
16 changes: 16 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"

services:
python:
build: .
volumes:
- ./:/app
working_dir: /app

cs:
build:
dockerfile: ./docker/cs/Dockerfile
context: .
volumes:
- ./:/app
working_dir: /app
8 changes: 0 additions & 8 deletions docker-compose.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions docker/cs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE: this image is never used in production (relies on Google's runtime), it only serves to mimick production as much as possible for development purposes.
FROM python:3.10.4-slim-buster

RUN pip install -U \
black \
;
2 changes: 2 additions & 0 deletions terraform/bigquery_scheduled_data_transfer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ resource "google_bigquery_data_transfer_config" "default" {
schedule_options {
disable_auto_scheduling = var.enable_auto_scheduling ? false : true
}

labels = var.labels
}
6 changes: 6 additions & 0 deletions terraform/bigquery_scheduled_data_transfer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ variable "interval" {
description = "the interval at which this query should be executed, also affects `interval` variable available inside the query"
}

variable "labels" {
default = {}
description = "Labels that should be passed to the Google Cloud resource"
type = map(string)
}

variable "location" {
type = string
description = "Google Cloud location used to execute the data transfer. To reduce costs it is recommended to keep this the same as the tables where data is transferred from/to."
Expand Down
1 change: 1 addition & 0 deletions terraform/cloud_function/pubsub_triggered/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ resource "google_cloudfunctions_function" "function" {
update = "10m"
}

labels = var.labels
}
5 changes: 5 additions & 0 deletions terraform/cloud_function/pubsub_triggered/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ variable "function_vpc_connector_egress_settings" {
type = string
default = null
}
variable "labels" {
default = {}
description = "Labels that should be passed to the Google Cloud resource"
type = map(string)
}
variable "project_id" {
type = string
}
Expand Down
5 changes: 5 additions & 0 deletions terraform/cloud_function/scheduled/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resource "google_storage_bucket_object" "functioncode" {

bucket = var.source_code_bucket_name
source = data.archive_file.source.output_path
labels = var.labels
}

resource "google_cloudfunctions_function" "function" {
Expand All @@ -53,6 +54,8 @@ resource "google_cloudfunctions_function" "function" {
create = "10m"
update = "10m"
}

labels = var.labels
}

resource "google_cloud_scheduler_job" "scheduler_job" {
Expand Down Expand Up @@ -81,6 +84,7 @@ resource "google_cloud_scheduler_job" "scheduler_job" {
service_account_email = var.scheduler_service_account_email
}
}
labels = var.labels
}

resource "google_cloudfunctions_function_iam_member" "invoker" {
Expand All @@ -89,4 +93,5 @@ resource "google_cloudfunctions_function_iam_member" "invoker" {
project = google_cloudfunctions_function.function.project
region = google_cloudfunctions_function.function.region
role = "roles/cloudfunctions.invoker"
labels = var.labels
}
6 changes: 6 additions & 0 deletions terraform/cloud_function/scheduled/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ variable "function_vpc_connector_egress_settings" {
type = string
default = null
}

variable "labels" {
default = {}
description = "Labels that should be passed to the Google Cloud resource"
type = map(string)
}
variable "project_id" {
type = string
}
Expand Down
18 changes: 18 additions & 0 deletions terraform/routines.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ resource "google_bigquery_routine" "json_get_float" {
}

return_type = "{\"typeKind\" : \"FLOAT64\"}"
labels = {
billing_category = "fundamental"
}
}


Expand All @@ -122,6 +125,9 @@ resource "google_storage_bucket_object" "user_agent_parser_lib" {

bucket = module.platform-artifacts-bucket.bucket_name
source = "./woothee.js"
labels = {
billing_category = "fundamental"
}
}

resource "google_bigquery_routine" "user_agent_parser" {
Expand Down Expand Up @@ -182,6 +188,9 @@ resource "google_bigquery_routine" "user_agent_parser" {
}
}
EOF
labels = {
billing_category = "fundamental"
}
}

resource "google_bigquery_routine" "greatest_furnished_type" {
Expand Down Expand Up @@ -210,6 +219,9 @@ IF(
EOF
language = "SQL"
return_type = "{\"typeKind\": \"STRING\"}"
labels = {
billing_category = "fundamental"
}
}

resource "google_bigquery_routine" "parse_dutch_date" {
Expand Down Expand Up @@ -251,6 +263,9 @@ resource "google_bigquery_routine" "parse_dutch_date" {
SPLIT(date_str,' ')[OFFSET(0)])
) AS STRING)
EOF
labels = {
billing_category = "fundamental"
}
}

resource "google_bigquery_routine" "array_distinct" {
Expand All @@ -272,4 +287,7 @@ EOF
data_type = "{\"typeKind\": \"ARRAY\", \"arrayElementType\": {\"typeKind\": \"STRING\"}}"
name = "value"
}
labels = {
billing_category = "fundamental"
}
}
1 change: 1 addition & 0 deletions terraform/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "google_storage_bucket" "default" {
}
}
}
labels = var.labels
}


5 changes: 5 additions & 0 deletions terraform/storage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ variable "force_destroy" {
type = bool
default = false
}
variable "labels" {
type = map(string)
description = "Labels that should be passed to the Google Cloud resource"
default = {}
}
variable "lifecycle_rules" {
type = list(any)
default = []
Expand Down

0 comments on commit f0a2b6f

Please sign in to comment.