Skip to content

Commit

Permalink
Added network and subnetwork fields to google_compute_region_network_…
Browse files Browse the repository at this point in the history
…endpoint_group for PSC. (#6275)
  • Loading branch information
rosmo authored Jul 25, 2022
1 parent 83d37ef commit c2a78c7
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mmv1/products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8562,6 +8562,21 @@ objects:
description: |
The target service url used to set up private service connection to
a Google API or a PSC Producer Service Attachment.
- !ruby/object:Api::Type::ResourceRef
name: 'network'
resource: 'Network'
imports: 'selfLink'
description: |
This field is only used for PSC.
The URL of the network to which all network endpoints in the NEG belong. Uses
"default" project network if unspecified.
- !ruby/object:Api::Type::ResourceRef
name: 'subnetwork'
resource: 'Subnetwork'
imports: 'selfLink'
description: |
This field is only used for PSC.
Optional URL of the subnetwork to which all network endpoints in the NEG belong.
- !ruby/object:Api::Type::NestedObject
name: 'cloudRun'
conflicts:
Expand Down
12 changes: 12 additions & 0 deletions mmv1/products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,18 @@ overrides: !ruby/object:Overrides::ResourceOverrides
primary_resource_id: "psc_neg"
vars:
neg_name: "psc-neg"
- !ruby/object:Provider::Terraform::Examples
name: "region_network_endpoint_group_psc_service_attachment"
primary_resource_id: "psc_neg_service_attachment"
vars:
neg_name: "psc-neg"
network_name: "psc-network"
subnetwork_name: "psc-subnetwork"
psc_subnetwork_name: "psc-subnetwork-nat"
backend_service_name: "psc-backend"
forwarding_rule_name: "psc-forwarding-rule"
service_attachment_name: "psc-service-attachment"
health_check_name: "psc-healthcheck"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
resource "google_compute_network" "default" {
name = "<%= ctx[:vars]['network_name'] %>"
}

resource "google_compute_subnetwork" "default" {
name = "<%= ctx[:vars]['subnetwork_name'] %>"
ip_cidr_range = "10.0.0.0/16"
region = "europe-west4"
network = google_compute_network.default.id
}

resource "google_compute_subnetwork" "psc_subnetwork" {
name = "<%= ctx[:vars]['psc_subnetwork_name'] %>"
ip_cidr_range = "10.1.0.0/16"
region = "europe-west4"
purpose = "PRIVATE_SERVICE_CONNECT"
network = google_compute_network.default.id
}

resource "google_compute_health_check" "default" {
name = "<%= ctx[:vars]['health_check_name'] %>"

check_interval_sec = 1
timeout_sec = 1
tcp_health_check {
port = "80"
}
}
resource "google_compute_region_backend_service" "default" {
name = "<%= ctx[:vars]['backend_service_name'] %>"
region = "europe-west4"

health_checks = [google_compute_health_check.default.id]
}

resource "google_compute_forwarding_rule" "default" {
name = "<%= ctx[:vars]['forwarding_rule_name'] %>"
region = "europe-west4"

load_balancing_scheme = "INTERNAL"
backend_service = google_compute_region_backend_service.default.id
all_ports = true
network = google_compute_network.default.name
subnetwork = google_compute_subnetwork.default.name
}

resource "google_compute_service_attachment" "default" {
name = "<%= ctx[:vars]['service_attachment_name'] %>"
region = "europe-west4"
description = "A service attachment configured with Terraform"

enable_proxy_protocol = false
connection_preference = "ACCEPT_AUTOMATIC"
nat_subnets = [google_compute_subnetwork.psc_subnetwork.self_link]
target_service = google_compute_forwarding_rule.default.self_link
}

resource "google_compute_region_network_endpoint_group" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['neg_name'] %>"
region = "europe-west4"

network_endpoint_type = "PRIVATE_SERVICE_CONNECT"
psc_target_service = google_compute_service_attachment.default.self_link

network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
}

0 comments on commit c2a78c7

Please sign in to comment.