Skip to content

Commit 105da6e

Browse files
author
Aaron Lane
authored
Merge pull request #6 from zachberger/bugfix
Leverage terraform-google-event-function
2 parents a8795ad + 01f9f6a commit 105da6e

File tree

8 files changed

+31
-79
lines changed

8 files changed

+31
-79
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Make will use bash instead of sh
1919
SHELL := /usr/bin/env bash
2020

21-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.1.0
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.6.0
2222
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2323
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2424

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Then perform the following commands on the root folder:
3838

3939
| Name | Description | Type | Default | Required |
4040
|------|-------------|:----:|:-----:|:-----:|
41+
| bucket\_force\_destroy | When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first. | string | `"true"` | no |
4142
| bucket\_name | The name to apply to the bucket. Will default to a string of <project-id>-scheduled-function-XXXX> with XXXX being random characters. | string | `""` | no |
4243
| function\_available\_memory\_mb | The amount of memory in megabytes allotted for the function to use. | number | `"256"` | no |
4344
| function\_description | The description of the function. | string | `"Processes log export events provided through a Pub/Sub topic subscription."` | no |

build/int.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ tags:
3838
- 'integration'
3939
substitutions:
4040
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
41-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
41+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ tags:
2121
- 'lint'
2222
substitutions:
2323
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
24-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
24+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'

main.tf

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,61 +47,29 @@ module "pubsub_topic" {
4747
Cloud Function Resource Definitions
4848
*****************************************/
4949

50-
resource "google_cloudfunctions_function" "main" {
51-
name = var.function_name
52-
source_archive_bucket = google_storage_bucket.main.name
53-
source_archive_object = google_storage_bucket_object.main.name
54-
description = var.function_description
55-
available_memory_mb = var.function_available_memory_mb
56-
timeout = var.function_timeout_s
57-
entry_point = var.function_entry_point
50+
module "main" {
51+
source = "terraform-google-modules/event-function/google"
52+
version = "~> 1.1"
5853

59-
event_trigger {
54+
entry_point = var.function_entry_point
55+
event_trigger = {
6056
event_type = "google.pubsub.topic.publish"
6157
resource = module.pubsub_topic.topic
62-
63-
failure_policy {
64-
retry = var.function_event_trigger_failure_policy_retry
65-
}
6658
}
59+
name = var.function_name
60+
project_id = var.project_id
61+
region = var.region
62+
runtime = var.function_runtime
63+
source_directory = var.function_source_directory
6764

68-
labels = var.function_labels
69-
runtime = var.function_runtime
70-
environment_variables = var.function_environment_variables
71-
project = var.project_id
72-
region = var.region
73-
service_account_email = var.function_service_account_email
74-
}
75-
76-
data "archive_file" "main" {
77-
type = "zip"
78-
output_path = pathexpand("${var.function_source_directory}.zip")
79-
source_dir = pathexpand(var.function_source_directory)
80-
}
81-
82-
resource "random_string" "random_suffix" {
83-
length = 4
84-
upper = "false"
85-
special = "false"
86-
}
87-
88-
resource "google_storage_bucket" "main" {
89-
name = coalesce(
90-
var.bucket_name,
91-
"${var.project_id}-scheduled-function-${random_string.random_suffix.result}",
92-
)
93-
force_destroy = "true"
94-
location = var.region
95-
project = var.project_id
96-
storage_class = "REGIONAL"
97-
labels = var.function_source_archive_bucket_labels
98-
}
99-
100-
resource "google_storage_bucket_object" "main" {
101-
name = "event_function-${random_string.random_suffix.result}.zip"
102-
bucket = google_storage_bucket.main.name
103-
source = data.archive_file.main.output_path
104-
content_disposition = "attachment"
105-
content_encoding = "gzip"
106-
content_type = "application/zip"
65+
available_memory_mb = var.function_available_memory_mb
66+
bucket_force_destroy = var.bucket_force_destroy
67+
bucket_labels = var.function_source_archive_bucket_labels
68+
bucket_name = var.bucket_name
69+
description = var.function_description
70+
environment_variables = var.function_environment_variables
71+
event_trigger_failure_policy_retry = var.function_event_trigger_failure_policy_retry
72+
labels = var.function_labels
73+
service_account_email = var.function_service_account_email
74+
timeout_s = var.function_timeout_s
10775
}

modules/project_cleanup/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The following services must be enabled on the project housing the cleanup functi
2121

2222
| Name | Description | Type | Default | Required |
2323
|------|-------------|:----:|:-----:|:-----:|
24+
| function\_timeout\_s | The amount of time in seconds allotted for the execution of the function. | number | `"60"` | no |
2425
| job\_schedule | Cleaner function run frequency, in cron syntax | string | `"*/5 * * * *"` | no |
2526
| max\_project\_age\_in\_hours | The maximum number of hours that a GCP project, selected by `target_tag_name` and `target_tag_value`, can exist | number | `"6"` | no |
2627
| organization\_id | The organization ID whose projects to clean up | string | n/a | yes |

test/setup/make_source.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ variable "bucket_name" {
106106
description = "The name to apply to the bucket. Will default to a string of <project-id>-scheduled-function-XXXX> with XXXX being random characters."
107107
}
108108

109+
variable "bucket_force_destroy" {
110+
type = "string"
111+
default = "true"
112+
description = "When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first."
113+
}
114+
109115
variable "function_name" {
110116
type = string
111117
description = "The name to apply to the function"

0 commit comments

Comments
 (0)