From a327be822c36d7da550907f3b2b376c17c0cc2e5 Mon Sep 17 00:00:00 2001 From: nur17 Date: Wed, 19 Jun 2024 16:34:18 +0800 Subject: [PATCH 1/8] added feature to pass subnet --- main.tf | 6 ++++++ variables.tf | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/main.tf b/main.tf index 1ff90e5..789face 100644 --- a/main.tf +++ b/main.tf @@ -24,6 +24,12 @@ resource "google_vpc_access_connector" "vpc_connector" { max_throughput = var.max_throughput ip_cidr_range = var.ip_cidr_range depends_on = [google_project_service.networking_api, google_project_service.serverless_vpc_api] + dynamic "subnet" { + for_each = var.subnet == null ? [] : [0] + content { + name = var.subnet + } + } timeouts { create = var.connector_timeout delete = var.connector_timeout diff --git a/variables.tf b/variables.tf index b0b3c9f..c77fe4d 100644 --- a/variables.tf +++ b/variables.tf @@ -19,6 +19,7 @@ variable "vpc_name" { variable "ip_cidr_range" { description = "A non-overlapping /28 IP CIDR range that is unused by the VPC Netowrk elsewhere. The VPC Connector will create connector instances on IP addresses in this range." type = string + default = null } # ---------------------------------------------------------------------------------------------------------------------- @@ -47,4 +48,10 @@ variable "max_throughput" { description = "Maximum throughput of the Serverless VPC Access connector in Mbps." type = number default = 300 +} + +variable "subnet" { + description = "Subnet to use for serverless coneector. Only way in case of shared vpc connector" + type = string + default = null } \ No newline at end of file From c099f073ad8acc9a7081e9e85b25c12088dd59e9 Mon Sep 17 00:00:00 2001 From: nur17 Date: Thu, 20 Jun 2024 01:38:15 +0800 Subject: [PATCH 2/8] added project id --- main.tf | 3 ++- variables.tf | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 789face..0b98987 100644 --- a/main.tf +++ b/main.tf @@ -27,7 +27,8 @@ resource "google_vpc_access_connector" "vpc_connector" { dynamic "subnet" { for_each = var.subnet == null ? [] : [0] content { - name = var.subnet + name = var.subnet + project_id = var.project_id } } timeouts { diff --git a/variables.tf b/variables.tf index c77fe4d..9da42e5 100644 --- a/variables.tf +++ b/variables.tf @@ -54,4 +54,10 @@ variable "subnet" { description = "Subnet to use for serverless coneector. Only way in case of shared vpc connector" type = string default = null +} + +variable "project_id" { + description = "project id of the subnet. Only required if subnet is in another shared host project" + type = string + default = null } \ No newline at end of file From e8fa3a509ba8c6381c17756ad04b131f9ae2a466 Mon Sep 17 00:00:00 2001 From: nur17 Date: Fri, 19 Jul 2024 13:42:22 +0800 Subject: [PATCH 3/8] added scaling options for high traffic workloads --- main.tf | 3 +++ variables.tf | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 0b98987..d87111e 100644 --- a/main.tf +++ b/main.tf @@ -21,6 +21,9 @@ resource "google_vpc_access_connector" "vpc_connector" { name = local.connector_name region = local.connector_region network = var.vpc_name + machine_type = var.machine_type + min_instances = var.min_instances + max_instances = var.max_instances max_throughput = var.max_throughput ip_cidr_range = var.ip_cidr_range depends_on = [google_project_service.networking_api, google_project_service.serverless_vpc_api] diff --git a/variables.tf b/variables.tf index 9da42e5..02237d3 100644 --- a/variables.tf +++ b/variables.tf @@ -51,13 +51,31 @@ variable "max_throughput" { } variable "subnet" { - description = "Subnet to use for serverless coneector. Only way in case of shared vpc connector" + description = "Subnet to use for serverless connector. Only way in case of shared vpc connector." type = string default = null } variable "project_id" { - description = "project id of the subnet. Only required if subnet is in another shared host project" + description = "Project id of the subnet. Only required if subnet is in another shared host project." type = string default = null -} \ No newline at end of file +} + +variable "machine_type" { + description = "(Optional) Machine type of VM Instance underlying connector. Default is e2-micro. Refer to this doc for selecting machine type https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling" + type = string + default = "e2-micro" +} + +variable "min_instances" { + description = "(Optional) Minimum value of instances in autoscaling group underlying the connector. Value must be between 2 and 9, inclusive. Must be lower than the value specified by max_instances." + type = number + default = 2 +} + +variable "max_instances" { + description = "(Optional) Maximum value of instances in autoscaling group underlying the connector. Value must be between 3 and 10, inclusive. Must be higher than the value specified by min_instances. Connectors don't scale in. To prevent connectors from scaling out more than you want, set the maximum number of instances to a low number." + type = number + default = 3 +} From 7826cf113d9f1fd79abd7a30c637a23d6abeaab3 Mon Sep 17 00:00:00 2001 From: nur17 Date: Fri, 19 Jul 2024 13:45:16 +0800 Subject: [PATCH 4/8] fixed descriptions --- .DS_Store | Bin 0 -> 6148 bytes variables.tf | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..83aa7fc99d37759724a5cd462669e1e1a1386529 GIT binary patch literal 6148 zcmeHKu};H447F(_BC&KtEZoA1)IT_?ASBlQ04kMArB>+xdp3TDPw3R|;@Lh>qNt1v z@GSXW&i2bCZ-`?N(fQkICNdR~8g3}>wv5g4<|8{RkqW4GkL`N4cy4$5QRV4?aVxo% zwQS^dz}Lr3Keua}X1Q&bh}9nt=hs&^$Gc&E^<#ej(tEba0aO|lpaN8Y3Q&Q6sQ`Mm zS$z@6l?qS+D)6mujh$k->&4FC002LT2Fp2Hd`u{!r#QZ-baYqHHz@Jh; zt7g&6@k*t)j$Y1sZGu0+zYMirj>TIs&|5J!)`~BCb;+)g&jq_crz7rkAb$i*7aA4# H4Fx^{L=z@A literal 0 HcmV?d00001 diff --git a/variables.tf b/variables.tf index 02237d3..7b13e7f 100644 --- a/variables.tf +++ b/variables.tf @@ -69,13 +69,13 @@ variable "machine_type" { } variable "min_instances" { - description = "(Optional) Minimum value of instances in autoscaling group underlying the connector. Value must be between 2 and 9, inclusive. Must be lower than the value specified by max_instances." + description = "(Optional) Minimum value of instances in autoscaling group underlying the connector. Value must be between 2 and 9, inclusive. Must be lower than the value specified by max_instances. Refer to this doc for setting min_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." type = number default = 2 } variable "max_instances" { - description = "(Optional) Maximum value of instances in autoscaling group underlying the connector. Value must be between 3 and 10, inclusive. Must be higher than the value specified by min_instances. Connectors don't scale in. To prevent connectors from scaling out more than you want, set the maximum number of instances to a low number." + description = "(Optional) Maximum value of instances in autoscaling group underlying the connector. Value must be between 3 and 10, inclusive. Must be higher than the value specified by min_instances. Connectors don't scale in. To prevent connectors from scaling out more than you want, set the maximum number of instances to a low number. Refer to this doc for setting max_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." type = number default = 3 } From d5525f0d4021104825eb755cb087f70dbcefb772 Mon Sep 17 00:00:00 2001 From: nur17 Date: Sat, 20 Jul 2024 18:36:39 +0800 Subject: [PATCH 5/8] removed .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 83aa7fc99d37759724a5cd462669e1e1a1386529..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKu};H447F(_BC&KtEZoA1)IT_?ASBlQ04kMArB>+xdp3TDPw3R|;@Lh>qNt1v z@GSXW&i2bCZ-`?N(fQkICNdR~8g3}>wv5g4<|8{RkqW4GkL`N4cy4$5QRV4?aVxo% zwQS^dz}Lr3Keua}X1Q&bh}9nt=hs&^$Gc&E^<#ej(tEba0aO|lpaN8Y3Q&Q6sQ`Mm zS$z@6l?qS+D)6mujh$k->&4FC002LT2Fp2Hd`u{!r#QZ-baYqHHz@Jh; zt7g&6@k*t)j$Y1sZGu0+zYMirj>TIs&|5J!)`~BCb;+)g&jq_crz7rkAb$i*7aA4# H4Fx^{L=z@A From 7963e755432277fea093d6e80129e621d3a6e1e8 Mon Sep 17 00:00:00 2001 From: nur17 Date: Mon, 22 Jul 2024 14:54:44 +0800 Subject: [PATCH 6/8] removed optional from variable description --- variables.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variables.tf b/variables.tf index 7b13e7f..e551231 100644 --- a/variables.tf +++ b/variables.tf @@ -63,19 +63,19 @@ variable "project_id" { } variable "machine_type" { - description = "(Optional) Machine type of VM Instance underlying connector. Default is e2-micro. Refer to this doc for selecting machine type https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling" + description = "Machine type of VM Instance underlying connector. Default is e2-micro. Refer to this doc for selecting machine type https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling" type = string default = "e2-micro" } variable "min_instances" { - description = "(Optional) Minimum value of instances in autoscaling group underlying the connector. Value must be between 2 and 9, inclusive. Must be lower than the value specified by max_instances. Refer to this doc for setting min_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." + description = "Minimum value of instances in autoscaling group underlying the connector. Value must be between 2 and 9, inclusive. Must be lower than the value specified by max_instances. Refer to this doc for setting min_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." type = number default = 2 } variable "max_instances" { - description = "(Optional) Maximum value of instances in autoscaling group underlying the connector. Value must be between 3 and 10, inclusive. Must be higher than the value specified by min_instances. Connectors don't scale in. To prevent connectors from scaling out more than you want, set the maximum number of instances to a low number. Refer to this doc for setting max_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." + description = "Maximum value of instances in autoscaling group underlying the connector. Value must be between 3 and 10, inclusive. Must be higher than the value specified by min_instances. Connectors don't scale in. To prevent connectors from scaling out more than you want, set the maximum number of instances to a low number. Refer to this doc for setting max_instances https://cloud.google.com/vpc/docs/serverless-vpc-access#scaling." type = number default = 3 } From 2bbe55ca247eeb677742b8f4dfb48f1904052c11 Mon Sep 17 00:00:00 2001 From: nur17 Date: Mon, 22 Jul 2024 15:57:54 +0800 Subject: [PATCH 7/8] renamed project_id to subnet_project_id --- main.tf | 2 +- variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index d87111e..7d1a927 100644 --- a/main.tf +++ b/main.tf @@ -31,7 +31,7 @@ resource "google_vpc_access_connector" "vpc_connector" { for_each = var.subnet == null ? [] : [0] content { name = var.subnet - project_id = var.project_id + project_id = var.subnet_project_id } } timeouts { diff --git a/variables.tf b/variables.tf index e551231..9b4058f 100644 --- a/variables.tf +++ b/variables.tf @@ -56,7 +56,7 @@ variable "subnet" { default = null } -variable "project_id" { +variable "subnet_project_id" { description = "Project id of the subnet. Only required if subnet is in another shared host project." type = string default = null From 610f026071f97b6a300aef90e97255fc5ee5d160 Mon Sep 17 00:00:00 2001 From: nur17 Date: Mon, 22 Jul 2024 18:47:00 +0800 Subject: [PATCH 8/8] removed max throughput --- main.tf | 17 ++++++++--------- variables.tf | 6 ------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/main.tf b/main.tf index 7d1a927..db31b63 100644 --- a/main.tf +++ b/main.tf @@ -18,15 +18,14 @@ resource "google_project_service" "serverless_vpc_api" { } resource "google_vpc_access_connector" "vpc_connector" { - name = local.connector_name - region = local.connector_region - network = var.vpc_name - machine_type = var.machine_type - min_instances = var.min_instances - max_instances = var.max_instances - max_throughput = var.max_throughput - ip_cidr_range = var.ip_cidr_range - depends_on = [google_project_service.networking_api, google_project_service.serverless_vpc_api] + name = local.connector_name + region = local.connector_region + network = var.vpc_name + machine_type = var.machine_type + min_instances = var.min_instances + max_instances = var.max_instances + ip_cidr_range = var.ip_cidr_range + depends_on = [google_project_service.networking_api, google_project_service.serverless_vpc_api] dynamic "subnet" { for_each = var.subnet == null ? [] : [0] content { diff --git a/variables.tf b/variables.tf index 9b4058f..4a0152d 100644 --- a/variables.tf +++ b/variables.tf @@ -44,12 +44,6 @@ variable "connector_timeout" { default = "10m" } -variable "max_throughput" { - description = "Maximum throughput of the Serverless VPC Access connector in Mbps." - type = number - default = 300 -} - variable "subnet" { description = "Subnet to use for serverless connector. Only way in case of shared vpc connector." type = string