diff --git a/.gitignore b/.gitignore index 496ee2c..af56f61 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_Store \ No newline at end of file +.DS_Store +.idea/ diff --git a/gcp/cloud-function-gen2/main.tf b/gcp/cloud-function-gen2/main.tf index 166b9f4..ac637b6 100644 --- a/gcp/cloud-function-gen2/main.tf +++ b/gcp/cloud-function-gen2/main.tf @@ -29,6 +29,8 @@ locals { default_runtime = "go116" } }[var.function_type] + + is_generic_event_type = var.event_type != "PUBSUB" && var.event_type != "STORAGE" } /****************************************** @@ -97,7 +99,7 @@ resource "google_cloudfunctions2_function" "function" { } dynamic "event_trigger" { - for_each = var.event_trigger != null ? [var.event_trigger] : [] + for_each = local.is_generic_event_type ? [var.event_trigger] : [] content { trigger_region = var.region event_type = event_trigger.value["event_type"] diff --git a/test/gcp/cloud-function-gen2.tf b/test/gcp/cloud-function-gen2.tf index 23c5e7b..948a418 100644 --- a/test/gcp/cloud-function-gen2.tf +++ b/test/gcp/cloud-function-gen2.tf @@ -16,13 +16,61 @@ module "cloud-function-my-awesome-cf" { repository_name = "my-awesome-cf" project_id = "mgt-build-56d2ff6b" timeout_seconds = 60 + event_trigger = { + trigger_region = "europe-west2" + event_type = "http" + retry_policy = "" + service_account_email = "test-service-account-email" + event_filters = [] + } trigger_substitutions = { _RUNTIME = "nodejs16" _ENTRYPOINT = "helloWorld" _FUNCTION_SA = "test-service-account-email" _FUNCTION_PATH = "services/my-awesome-cf/functions/my-awesome-cf" _FUNCTION_TYPE_TRIGGER = "trigger-http" + } + environment_variables = { + LOCATION = "europe-west2" + } + secret_keys = [] + threshold_value = 0 + function_entry_point = "helloWorld" +} +module "cloud-function-my-awesome-cf-storage" { + source = "../../gcp/cloud-function-gen2" + function_name = "my-awesome-cf" + function_type = "node" + function_description = "My awesome cloud function" + environment = "preview" + region = "europe-west2" + notification_channels = [] + service_name = "my-awesome-cf" + bucket_functions = "test-bucket-functions" + service_account_email = "test-service-account-email" + function_path = "services/my-awesome-cf/functions/my-awesome-cf" + max_instance_count = 3 + min_instance_count = 1 + branching_strategy = "master" + repository_name = "my-awesome-cf" + project_id = "mgt-build-56d2ff6b" + timeout_seconds = 60 + event_type = "STORAGE" + event_trigger = { + bucket_name = "test-bucket" + trigger_region = "europe-west2" + event_type = "google.storage.object.finalize" + retry_policy = "" + service_account_email = "test-service-account-email" + event_filters = [] + } + trigger_substitutions = { + _RUNTIME = "nodejs16" + _ENTRYPOINT = "helloWorld" + _FUNCTION_SA = "test-service-account-email" + _FUNCTION_PATH = "services/my-awesome-cf/functions/my-awesome-cf" + _FUNCTION_TYPE_TRIGGER = "trigger-http" } environment_variables = { LOCATION = "europe-west2"