Skip to content

Commit

Permalink
Update input variables, metadata and README
Browse files Browse the repository at this point in the history
  • Loading branch information
q2w committed Aug 22, 2024
1 parent ef05732 commit 015be39
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
21 changes: 21 additions & 0 deletions examples/service-networking/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

Expand Down
2 changes: 1 addition & 1 deletion examples/service-networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 4 additions & 3 deletions modules/service-networking/README.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

Expand All @@ -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 | <pre>list(object({<br> name : string,<br> purpose : optional(string, "VPC_PEERING"),<br> type : optional(string, "INTERNAL"),<br> prefix_length : optional(number, 16)<br> }))</pre> | n/a | yes |
| global\_addresses | List of global addresses to be created | <pre>list(object({<br> name : string,<br> purpose : optional(string, "VPC_PEERING"),<br> type : optional(string, "INTERNAL"),<br> address : optional(string, null),<br> prefix_length : optional(number, 16)<br> }))</pre> | n/a | yes |
| import\_custom\_routes | Import custom routes to peering rout config | `bool` | `false` | no |
| network | Network details including name and id | <pre>object({<br> name = optional(string, null),<br> id = string<br> })</pre> | 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 |

Expand Down
9 changes: 5 additions & 4 deletions modules/service-networking/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
13 changes: 5 additions & 8 deletions modules/service-networking/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
info:
title: Terraform Google service networking
source:
repo: https://github.com/q2w/terraform-google-network.git
repo: https://github.com/terraform-google-modules/terraform-google-network.git
sourceType: git
dir: /modules/service-networking
version: 9.1.0
Expand Down Expand Up @@ -118,20 +118,17 @@ spec:
name : string,
purpose : optional(string, "VPC_PEERING"),
type : optional(string, "INTERNAL"),
address : optional(string, null),
prefix_length : optional(number, 16)
}))
required: true
- name: import_custom_routes
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
Expand Down
10 changes: 4 additions & 6 deletions modules/service-networking/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 015be39

Please sign in to comment.