diff --git a/examples/service-networking/README.md b/examples/service-networking/README.md index bfa73ded6..ded259414 100644 --- a/examples/service-networking/README.md +++ b/examples/service-networking/README.md @@ -1,5 +1,26 @@ # Terraform service networking example This example creates service networking with a global address. + +``` +resource "google_compute_network" "peering_network" { + name = "private-network" + auto_create_subnetworks = "false" + project = var.project_id +} + +module "service_networking" { + source = "terraform-google-modules/network/google//modules/service-networking" + version = "~> 9.0" + + project_id = var.project_id + network_name = google_compute_network.peering_network.name + global_addresses = [{ name : "global-address" }] + service = "servicenetworking.googleapis.com" +} +``` + +In the above terraform, a service networking connection is created. It enables managed services (cloud sql,memorystore) on internal IP addresses (VPC) to service consumers (cloud-run). Service consumers use private services access to privately connect to the service. + ## Inputs diff --git a/examples/service-networking/main.tf b/examples/service-networking/main.tf index 8c38e2648..3a777f8bc 100644 --- a/examples/service-networking/main.tf +++ b/examples/service-networking/main.tf @@ -25,7 +25,7 @@ module "service_networking" { version = "~> 9.0" project_id = var.project_id - network = { id : google_compute_network.peering_network.id } + network_name = google_compute_network.peering_network.name global_addresses = [{ name : "global-address" }] service = "servicenetworking.googleapis.com" } diff --git a/modules/service-networking/README.md b/modules/service-networking/README.md index 0544ab291..449cade7d 100644 --- a/modules/service-networking/README.md +++ b/modules/service-networking/README.md @@ -1,6 +1,7 @@ # Terraform Google service networking -This module creates global network address and a service networking +This module creates global network address and a service networking. The google_service_networking_connection terraform resource allows to establish a private connection between a Google Cloud Platform (GCP) VPC network and a supported Google service, such as Cloud SQL, BigQuery, or a third-party service. + ## Inputs @@ -12,9 +13,9 @@ This module creates global network address and a service networking | dns\_suffix | Dns suffix | `string` | `null` | no | | domain\_name | Domain name | `string` | `null` | no | | export\_custom\_routes | Export custom routes | `bool` | `false` | no | -| global\_addresses | List of global addresses to be created |
list(object({| n/a | yes | +| global\_addresses | List of global addresses to be created |
name : string,
purpose : optional(string, "VPC_PEERING"),
type : optional(string, "INTERNAL"),
prefix_length : optional(number, 16)
}))
list(object({| n/a | yes | | import\_custom\_routes | Import custom routes to peering rout config | `bool` | `false` | no | -| network | Network details including name and id |
name : string,
purpose : optional(string, "VPC_PEERING"),
type : optional(string, "INTERNAL"),
address : optional(string, null),
prefix_length : optional(number, 16)
}))
object({| n/a | yes | +| network\_name | Network name | `string` | n/a | yes | | project\_id | Project ID | `string` | n/a | yes | | service | Service to create service networking connection | `string` | n/a | yes | diff --git a/modules/service-networking/main.tf b/modules/service-networking/main.tf index ff417f92d..091650e07 100644 --- a/modules/service-networking/main.tf +++ b/modules/service-networking/main.tf @@ -20,12 +20,13 @@ resource "google_compute_global_address" "global_addresses" { name = each.value.name purpose = each.value.purpose address_type = each.value.type + address = each.value.address prefix_length = each.value.prefix_length - network = var.network.id + network = "projects/${var.project_id}/global/networks/${var.network_name}" } resource "google_service_networking_connection" "default" { - network = var.network.id + network = "projects/${var.project_id}/global/networks/${var.network_name}" service = var.service reserved_peering_ranges = [for name, _ in google_compute_global_address.global_addresses : name] deletion_policy = var.deletion_policy @@ -35,7 +36,7 @@ resource "google_compute_network_peering_routes_config" "peering_routes" { count = var.create_peering_routes_config ? 1 : 0 project = var.project_id peering = google_service_networking_connection.default.peering - network = var.network.name + network = var.network_name import_custom_routes = var.import_custom_routes export_custom_routes = var.export_custom_routes } @@ -44,7 +45,7 @@ resource "google_service_networking_peered_dns_domain" "default" { count = var.create_peered_dns_domain ? 1 : 0 project = var.project_id name = var.domain_name - network = var.network.name + network = var.network_name dns_suffix = var.dns_suffix service = var.service } diff --git a/modules/service-networking/metadata.yaml b/modules/service-networking/metadata.yaml index 36fac5bc3..3d28a0dbf 100644 --- a/modules/service-networking/metadata.yaml +++ b/modules/service-networking/metadata.yaml @@ -118,6 +118,7 @@ spec: name : string, purpose : optional(string, "VPC_PEERING"), type : optional(string, "INTERNAL"), + address : optional(string, null), prefix_length : optional(number, 16) })) required: true @@ -125,13 +126,9 @@ spec: description: Import custom routes to peering rout config varType: bool defaultValue: false - - name: network - description: Network details including name and id - varType: |- - object({ - name = optional(string, null), - id = string - }) + - name: network_name + description: Network name + varType: string required: true - name: project_id description: Project ID diff --git a/modules/service-networking/variables.tf b/modules/service-networking/variables.tf index 8bc3c5ade..50800d128 100644 --- a/modules/service-networking/variables.tf +++ b/modules/service-networking/variables.tf @@ -25,16 +25,14 @@ variable "global_addresses" { name : string, purpose : optional(string, "VPC_PEERING"), type : optional(string, "INTERNAL"), + address : optional(string, null), prefix_length : optional(number, 16) })) } -variable "network" { - description = "Network details including name and id" - type = object({ - name = optional(string, null), - id = string - }) +variable "network_name" { + description = "Network name" + type = string } variable "service" {
name = optional(string, null),
id = string
})