Skip to content

Add triggers to Cloud Functions v2 #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ module "cf" {
name = var.name
bucket_name = "${var.name}-${random_pet.random.id}"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
bundle_config = {
source_dir = "cf"
output_path = var.bundle_path
excludes = null
}
service_account = module.service-account.email
trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
retry = null
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}
}

Expand Down
21 changes: 13 additions & 8 deletions blueprints/cloud-operations/network-dashboard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,21 @@ module "cloud-function" {
name = "network-dashboard-cloud-function"
bucket_name = "${local.monitoring_project}-network-dashboard-bucket"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
region = var.region

bundle_config = {
source_dir = "cloud-function"
output_path = "cloud-function.zip"
excludes = null
}

function_config = {
timeout = 480 # Timeout in seconds, increase it if your CF timeouts and use v2 if > 9 minutes.
entry_point = "main"
runtime = "python39"
instances = 1
memory = 256 # Memory in MB
memory_mb = 256

}

Expand All @@ -169,10 +167,17 @@ module "cloud-function" {
# Internal only doesn't seem to work with CFv2:
ingress_settings = var.cf_version == "V2" ? "ALLOW_ALL" : "ALLOW_INTERNAL_ONLY"

trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
retry = null
trigger_config = var.cf_version == "V2" ? {
v2 = {
event_type = "google.cloud.pubsub.topic.v1.messagePublished"
pubsub_topic = module.pubsub.topic.id
service_account_create = true
}
} : {
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}
}

Expand Down
11 changes: 5 additions & 6 deletions blueprints/cloud-operations/quota-monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ module "cf" {
name = var.name
bucket_name = "${var.name}-${random_pet.random.id}"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
bundle_config = {
source_dir = "cf"
output_path = var.bundle_path
excludes = null
}
# https://github.com/hashicorp/terraform-provider-archive/issues/40
# https://issuetracker.google.com/issues/155215191
Expand All @@ -68,9 +66,10 @@ module "cf" {
}
service_account_create = true
trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
retry = null
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ module "cf" {
name = var.name
bucket_name = "${var.name}-${random_pet.random.id}"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
bundle_config = {
source_dir = "cf"
output_path = var.bundle_path
excludes = null
}
service_account = module.service-account.email
trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
retry = null
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}
}

Expand All @@ -115,8 +114,8 @@ module "cffile" {
name = var.name_cffile
bucket_name = "${var.name_cffile}-${random_pet.random.id}"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
lifecycle_delete_age_days = null
}
bundle_config = {
source_dir = "cffile"
Expand All @@ -125,9 +124,11 @@ module "cffile" {
}
service_account = module.service-account.email
trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub_file.topic.id
retry = null
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub_file.topic.id
retry = null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,28 @@ module "cf-restarter" {
region = var.region
bucket_name = "cf-bundle-bucket-${random_pet.random.id}"
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
bundle_config = {
source_dir = "${path.module}/function/restarter"
output_path = "restarter.zip"
excludes = []
}
service_account = module.service-account-restarter.email

function_config = {
entry_point = "RestartInstance"
ingress_settings = null
instances = 1
memory = 256
instance_count = 1
memory_mb = 256
runtime = "go116"
timeout = 300
}

trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
retry = null
v1 = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}

}
Expand All @@ -151,15 +150,14 @@ module "cf-healthchecker" {
bundle_config = {
source_dir = "${path.module}/function/healthchecker"
output_path = "healthchecker.zip"
excludes = []
}
service_account = module.service-account-healthchecker.email

function_config = {
entry_point = "HealthCheck"
ingress_settings = null
instances = 1
memory = 256
instance_count = 1
memory_mb = 256
runtime = "go116"
timeout = 300
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ module "function-hello" {
bundle_config = {
source_dir = "${path.module}/assets"
output_path = "bundle.zip"
excludes = null
}
bucket_config = {
location = var.region
lifecycle_delete_age = null
location = var.region
}
iam = {
"roles/cloudfunctions.invoker" = ["allUsers"]
Expand Down
4 changes: 2 additions & 2 deletions blueprints/serverless/api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ module "functions" {
region = each.value
ingress_settings = "ALLOW_ALL"
bucket_config = {
location = null
lifecycle_delete_age = 1
location = null
lifecycle_delete_age_days = 1
}
bundle_config = {
source_dir = "${path.module}/function"
Expand Down
Loading