From 4df6c90d12fd0bc7a068286a5e05afff63bfb1ab Mon Sep 17 00:00:00 2001 From: Miren Esnaola Date: Fri, 12 May 2023 13:49:22 +0200 Subject: [PATCH] Made available CPUs configurable in Cloud Functions module --- modules/cloud-function/README.md | 30 ++++++++++++++--------------- modules/cloud-function/main.tf | 1 + modules/cloud-function/variables.tf | 2 ++ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/modules/cloud-function/README.md b/modules/cloud-function/README.md index 4983f27f1..7a0abe7c4 100644 --- a/modules/cloud-function/README.md +++ b/modules/cloud-function/README.md @@ -256,25 +256,25 @@ module "cf-http-two" { |---|---|:---:|:---:|:---:| | [bucket_name](variables.tf#L26) | Name of the bucket that will be used for the function code. It will be created with prefix prepended if bucket_config is not null. | string | ✓ | | | [bundle_config](variables.tf#L37) | Cloud function source folder and generated zip bundle paths. Output path defaults to '/tmp/bundle.zip' if null. | object({…}) | ✓ | | -| [name](variables.tf#L94) | Name used for cloud function and associated resources. | string | ✓ | | -| [project_id](variables.tf#L109) | Project id used for all resources. | string | ✓ | | +| [name](variables.tf#L96) | Name used for cloud function and associated resources. | string | ✓ | | +| [project_id](variables.tf#L111) | Project id used for all resources. | string | ✓ | | | [bucket_config](variables.tf#L17) | Enable and configure auto-created bucket. Set fields to null to use defaults. | object({…}) | | null | | [build_worker_pool](variables.tf#L31) | Build worker pool, in projects//locations//workerPools/ format. | string | | null | | [description](variables.tf#L46) | Optional description. | string | | "Terraform managed." | | [environment_variables](variables.tf#L52) | Cloud function environment variables. | map(string) | | {} | -| [function_config](variables.tf#L58) | Cloud function configuration. Defaults to using main as entrypoint, 1 instance with 256MiB of memory, and 180 second timeout. | object({…}) | | {…} | -| [iam](variables.tf#L76) | IAM bindings for topic in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | -| [ingress_settings](variables.tf#L82) | Control traffic that reaches the cloud function. Allowed values are ALLOW_ALL, ALLOW_INTERNAL_AND_GCLB and ALLOW_INTERNAL_ONLY . | string | | null | -| [labels](variables.tf#L88) | Resource labels. | map(string) | | {} | -| [prefix](variables.tf#L99) | Optional prefix used for resource names. | string | | null | -| [region](variables.tf#L114) | Region used for all resources. | string | | "europe-west1" | -| [secrets](variables.tf#L120) | Secret Manager secrets. Key is the variable name or mountpoint, volume versions are in version:path format. | map(object({…})) | | {} | -| [service_account](variables.tf#L132) | Service account email. Unused if service account is auto-created. | string | | null | -| [service_account_create](variables.tf#L138) | Auto-create service account. | bool | | false | -| [trigger_config](variables.tf#L144) | Function trigger configuration. Leave null for HTTP trigger. | object({…}) | | { v1 = null, v2 = null } | -| [v2](variables.tf#L173) | Whether to use Cloud Function version 2nd Gen or 1st Gen. | bool | | false | -| [vpc_connector](variables.tf#L179) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | object({…}) | | null | -| [vpc_connector_config](variables.tf#L189) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | +| [function_config](variables.tf#L58) | Cloud function configuration. Defaults to using main as entrypoint, 1 instance with 256MiB of memory, and 180 second timeout. | object({…}) | | {…} | +| [iam](variables.tf#L78) | IAM bindings for topic in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | +| [ingress_settings](variables.tf#L84) | Control traffic that reaches the cloud function. Allowed values are ALLOW_ALL, ALLOW_INTERNAL_AND_GCLB and ALLOW_INTERNAL_ONLY . | string | | null | +| [labels](variables.tf#L90) | Resource labels. | map(string) | | {} | +| [prefix](variables.tf#L101) | Optional prefix used for resource names. | string | | null | +| [region](variables.tf#L116) | Region used for all resources. | string | | "europe-west1" | +| [secrets](variables.tf#L122) | Secret Manager secrets. Key is the variable name or mountpoint, volume versions are in version:path format. | map(object({…})) | | {} | +| [service_account](variables.tf#L134) | Service account email. Unused if service account is auto-created. | string | | null | +| [service_account_create](variables.tf#L140) | Auto-create service account. | bool | | false | +| [trigger_config](variables.tf#L146) | Function trigger configuration. Leave null for HTTP trigger. | object({…}) | | { v1 = null, v2 = null } | +| [v2](variables.tf#L175) | Whether to use Cloud Function version 2nd Gen or 1st Gen. | bool | | false | +| [vpc_connector](variables.tf#L181) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | object({…}) | | null | +| [vpc_connector_config](variables.tf#L191) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | ## Outputs diff --git a/modules/cloud-function/main.tf b/modules/cloud-function/main.tf index b5a861b2a..2078a4833 100644 --- a/modules/cloud-function/main.tf +++ b/modules/cloud-function/main.tf @@ -168,6 +168,7 @@ resource "google_cloudfunctions2_function" "function" { max_instance_count = var.function_config.instance_count min_instance_count = 0 available_memory = "${var.function_config.memory_mb}M" + available_cpu = var.function_config.cpu timeout_seconds = var.function_config.timeout_seconds environment_variables = var.environment_variables ingress_settings = var.ingress_settings diff --git a/modules/cloud-function/variables.tf b/modules/cloud-function/variables.tf index 5f4b28c94..0bb258ee4 100644 --- a/modules/cloud-function/variables.tf +++ b/modules/cloud-function/variables.tf @@ -61,6 +61,7 @@ variable "function_config" { entry_point = optional(string, "main") instance_count = optional(number, 1) memory_mb = optional(number, 256) # Memory in MB + cpu = optional(string, "0.166") runtime = optional(string, "python310") timeout_seconds = optional(number, 180) }) @@ -68,6 +69,7 @@ variable "function_config" { entry_point = "main" instance_count = 1 memory_mb = 256 + cpu = "0.166" runtime = "python310" timeout_seconds = 180 }