Skip to content

Commit

Permalink
Merge pull request #4 from nurairasia/shared-vpc-connector
Browse files Browse the repository at this point in the history
Added shared vpc connector and scaling options
  • Loading branch information
nurairasia authored Jul 22, 2024
2 parents ffd7a6d + 610f026 commit 762a8e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
21 changes: 15 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ 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
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 {
name = var.subnet
project_id = var.subnet_project_id
}
}
timeouts {
create = var.connector_timeout
delete = var.connector_timeout
Expand Down
33 changes: 29 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

# ----------------------------------------------------------------------------------------------------------------------
Expand All @@ -43,8 +44,32 @@ variable "connector_timeout" {
default = "10m"
}

variable "max_throughput" {
description = "Maximum throughput of the Serverless VPC Access connector in Mbps."
variable "subnet" {
description = "Subnet to use for serverless connector. Only way in case of shared vpc connector."
type = string
default = null
}

variable "subnet_project_id" {
description = "Project id of the subnet. Only required if subnet is in another shared host project."
type = string
default = null
}

variable "machine_type" {
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 = "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 = "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 = 300
}
default = 3
}

0 comments on commit 762a8e3

Please sign in to comment.