From 587edfd8d57f4d507560f26cd84bc01cdd777aba Mon Sep 17 00:00:00 2001 From: apichick Date: Thu, 21 Nov 2024 09:05:12 +0100 Subject: [PATCH] =?UTF-8?q?Added=20min=5Finstances,=20max=5Finstances,=20m?= =?UTF-8?q?in=5Fthroughput=20and=20max=5Fthroughtpu=E2=80=A6=20(#2706)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added min_instances, max_instances, min_throughput and max_throughtput to connector configuration * refactor interface, also implement in v1 module * fix blueprint --------- Co-authored-by: Ludo --- .../unmanaged-instances-healthcheck/main.tf | 1 + modules/cloud-function-v1/README.md | 2 +- modules/cloud-function-v1/main.tf | 16 ++++++++++------ modules/cloud-function-v1/variables.tf | 16 ++++++++++++++++ modules/cloud-function-v2/README.md | 2 +- modules/cloud-function-v2/main.tf | 16 ++++++++++------ modules/cloud-function-v2/variables.tf | 16 ++++++++++++++++ 7 files changed, 55 insertions(+), 14 deletions(-) diff --git a/blueprints/cloud-operations/unmanaged-instances-healthcheck/main.tf b/blueprints/cloud-operations/unmanaged-instances-healthcheck/main.tf index 65aae68c96..33c6654e64 100644 --- a/blueprints/cloud-operations/unmanaged-instances-healthcheck/main.tf +++ b/blueprints/cloud-operations/unmanaged-instances-healthcheck/main.tf @@ -172,6 +172,7 @@ module "cf-healthchecker" { vpc_connector_config = { ip_cidr_range = "10.132.0.0/28" network = "vpc" + instances = {} } iam = { "roles/cloudfunctions.invoker" = [module.service-account-scheduler.iam_email] diff --git a/modules/cloud-function-v1/README.md b/modules/cloud-function-v1/README.md index b63982e38b..ca7f78c169 100644 --- a/modules/cloud-function-v1/README.md +++ b/modules/cloud-function-v1/README.md @@ -399,7 +399,7 @@ module "cf-http" { | [service_account_create](variables.tf#L194) | Auto-create service account. | bool | | false | | [trigger_config](variables.tf#L200) | Function trigger configuration. Leave null for HTTP trigger. | object({…}) | | null | | [vpc_connector](variables.tf#L210) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | object({…}) | | null | -| [vpc_connector_config](variables.tf#L220) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | +| [vpc_connector_config](variables.tf#L220) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | ## Outputs diff --git a/modules/cloud-function-v1/main.tf b/modules/cloud-function-v1/main.tf index 073f46b3c7..e51ded5416 100644 --- a/modules/cloud-function-v1/main.tf +++ b/modules/cloud-function-v1/main.tf @@ -42,12 +42,16 @@ locals { } resource "google_vpc_access_connector" "connector" { - count = try(var.vpc_connector.create, false) == false ? 0 : 1 - project = var.project_id - name = var.vpc_connector.name - region = var.region - ip_cidr_range = var.vpc_connector_config.ip_cidr_range - network = var.vpc_connector_config.network + count = try(var.vpc_connector.create, false) == true ? 1 : 0 + project = var.project_id + name = var.vpc_connector.name + region = var.region + ip_cidr_range = var.vpc_connector_config.ip_cidr_range + network = var.vpc_connector_config.network + max_instances = try(var.vpc_connector_config.instances.max, null) + min_instances = try(var.vpc_connector_config.instances.min, null) + max_throughput = try(var.vpc_connector_config.throughput.max, null) + min_throughput = try(var.vpc_connector_config.throughput.min, null) } resource "google_cloudfunctions_function" "function" { diff --git a/modules/cloud-function-v1/variables.tf b/modules/cloud-function-v1/variables.tf index d29d5e0cd6..98f1f10afe 100644 --- a/modules/cloud-function-v1/variables.tf +++ b/modules/cloud-function-v1/variables.tf @@ -222,6 +222,22 @@ variable "vpc_connector_config" { type = object({ ip_cidr_range = string network = string + instances = optional(object({ + max = optional(number) + min = optional(number, 2) + })) + throughput = optional(object({ + max = optional(number, 300) + min = optional(number, 200) + })) }) default = null + validation { + condition = ( + var.vpc_connector_config == null || + try(var.vpc_connector_config.instances, null) != null || + try(var.vpc_connector_config.throughput, null) != null + ) + error_message = "VPC connector must specify either instances or throughput." + } } diff --git a/modules/cloud-function-v2/README.md b/modules/cloud-function-v2/README.md index 0fc90148ca..2e6c08ce52 100644 --- a/modules/cloud-function-v2/README.md +++ b/modules/cloud-function-v2/README.md @@ -332,7 +332,7 @@ module "cf-http" { | [service_account_create](variables.tf#L191) | Auto-create service account. | bool | | false | | [trigger_config](variables.tf#L197) | Function trigger configuration. Leave null for HTTP trigger. | object({…}) | | null | | [vpc_connector](variables.tf#L215) | VPC connector configuration. Set create to 'true' if a new connector needs to be created. | object({…}) | | null | -| [vpc_connector_config](variables.tf#L225) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | +| [vpc_connector_config](variables.tf#L225) | VPC connector network configuration. Must be provided if new VPC connector is being created. | object({…}) | | null | ## Outputs diff --git a/modules/cloud-function-v2/main.tf b/modules/cloud-function-v2/main.tf index 672591d4de..691720106c 100644 --- a/modules/cloud-function-v2/main.tf +++ b/modules/cloud-function-v2/main.tf @@ -50,12 +50,16 @@ locals { } resource "google_vpc_access_connector" "connector" { - count = try(var.vpc_connector.create, false) == true ? 1 : 0 - project = var.project_id - name = var.vpc_connector.name - region = var.region - ip_cidr_range = var.vpc_connector_config.ip_cidr_range - network = var.vpc_connector_config.network + count = try(var.vpc_connector.create, false) == true ? 1 : 0 + project = var.project_id + name = var.vpc_connector.name + region = var.region + ip_cidr_range = var.vpc_connector_config.ip_cidr_range + network = var.vpc_connector_config.network + max_instances = try(var.vpc_connector_config.instances.max, null) + min_instances = try(var.vpc_connector_config.instances.min, null) + max_throughput = try(var.vpc_connector_config.throughput.max, null) + min_throughput = try(var.vpc_connector_config.throughput.min, null) } resource "google_cloudfunctions2_function" "function" { diff --git a/modules/cloud-function-v2/variables.tf b/modules/cloud-function-v2/variables.tf index c960aad756..f51ba347db 100644 --- a/modules/cloud-function-v2/variables.tf +++ b/modules/cloud-function-v2/variables.tf @@ -227,6 +227,22 @@ variable "vpc_connector_config" { type = object({ ip_cidr_range = string network = string + instances = optional(object({ + max = optional(number) + min = optional(number, 2) + })) + throughput = optional(object({ + max = optional(number, 300) + min = optional(number, 200) + })) }) default = null + validation { + condition = ( + var.vpc_connector_config == null || + try(var.vpc_connector_config.instances, null) != null || + try(var.vpc_connector_config.throughput, null) != null + ) + error_message = "VPC connector must specify either instances or throughput." + } }