Skip to content

Commit

Permalink
Merge pull request #6 from zachberger/bugfix
Browse files Browse the repository at this point in the history
Leverage terraform-google-event-function
  • Loading branch information
Aaron Lane authored Nov 25, 2019
2 parents a8795ad + 01f9f6a commit 105da6e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.1.0
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.6.0
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
REGISTRY_URL := gcr.io/cloud-foundation-cicd

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Then perform the following commands on the root folder:

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| bucket\_force\_destroy | When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first. | string | `"true"` | no |
| 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 |
| function\_available\_memory\_mb | The amount of memory in megabytes allotted for the function to use. | number | `"256"` | no |
| function\_description | The description of the function. | string | `"Processes log export events provided through a Pub/Sub topic subscription."` | no |
Expand Down
2 changes: 1 addition & 1 deletion build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ tags:
- 'integration'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'
2 changes: 1 addition & 1 deletion build/lint.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ tags:
- 'lint'
substitutions:
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.1.0'
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.6.0'
72 changes: 20 additions & 52 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,29 @@ module "pubsub_topic" {
Cloud Function Resource Definitions
*****************************************/

resource "google_cloudfunctions_function" "main" {
name = var.function_name
source_archive_bucket = google_storage_bucket.main.name
source_archive_object = google_storage_bucket_object.main.name
description = var.function_description
available_memory_mb = var.function_available_memory_mb
timeout = var.function_timeout_s
entry_point = var.function_entry_point
module "main" {
source = "terraform-google-modules/event-function/google"
version = "~> 1.1"

event_trigger {
entry_point = var.function_entry_point
event_trigger = {
event_type = "google.pubsub.topic.publish"
resource = module.pubsub_topic.topic

failure_policy {
retry = var.function_event_trigger_failure_policy_retry
}
}
name = var.function_name
project_id = var.project_id
region = var.region
runtime = var.function_runtime
source_directory = var.function_source_directory

labels = var.function_labels
runtime = var.function_runtime
environment_variables = var.function_environment_variables
project = var.project_id
region = var.region
service_account_email = var.function_service_account_email
}

data "archive_file" "main" {
type = "zip"
output_path = pathexpand("${var.function_source_directory}.zip")
source_dir = pathexpand(var.function_source_directory)
}

resource "random_string" "random_suffix" {
length = 4
upper = "false"
special = "false"
}

resource "google_storage_bucket" "main" {
name = coalesce(
var.bucket_name,
"${var.project_id}-scheduled-function-${random_string.random_suffix.result}",
)
force_destroy = "true"
location = var.region
project = var.project_id
storage_class = "REGIONAL"
labels = var.function_source_archive_bucket_labels
}

resource "google_storage_bucket_object" "main" {
name = "event_function-${random_string.random_suffix.result}.zip"
bucket = google_storage_bucket.main.name
source = data.archive_file.main.output_path
content_disposition = "attachment"
content_encoding = "gzip"
content_type = "application/zip"
available_memory_mb = var.function_available_memory_mb
bucket_force_destroy = var.bucket_force_destroy
bucket_labels = var.function_source_archive_bucket_labels
bucket_name = var.bucket_name
description = var.function_description
environment_variables = var.function_environment_variables
event_trigger_failure_policy_retry = var.function_event_trigger_failure_policy_retry
labels = var.function_labels
service_account_email = var.function_service_account_email
timeout_s = var.function_timeout_s
}
1 change: 1 addition & 0 deletions modules/project_cleanup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following services must be enabled on the project housing the cleanup functi

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| function\_timeout\_s | The amount of time in seconds allotted for the execution of the function. | number | `"60"` | no |
| job\_schedule | Cleaner function run frequency, in cron syntax | string | `"*/5 * * * *"` | no |
| 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 |
| organization\_id | The organization ID whose projects to clean up | string | n/a | yes |
Expand Down
24 changes: 0 additions & 24 deletions test/setup/make_source.sh

This file was deleted.

6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ variable "bucket_name" {
description = "The name to apply to the bucket. Will default to a string of <project-id>-scheduled-function-XXXX> with XXXX being random characters."
}

variable "bucket_force_destroy" {
type = "string"
default = "true"
description = "When deleting the GCS bucket containing the cloud function, delete all objects in the bucket first."
}

variable "function_name" {
type = string
description = "The name to apply to the function"
Expand Down

0 comments on commit 105da6e

Please sign in to comment.