-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
NON_GCP_PRIVATE_IP_PORT
as networkEndpointType for NetworkEndpo…
…intGroup (#5684) * Add NON_GCP_PRIVATE_IP_PORT as networkEndpointType for NetworkEndpointGroup * Fix the Network Endpoint Group non-GCP example * Make networkEndpoint instance optional, handle, and add example * Put the hybrid endpoint in the hybrid NEG
- Loading branch information
Alex Ellis
authored
Feb 22, 2022
1 parent
9a9e319
commit 3788bd2
Showing
6 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
mmv1/templates/terraform/custom_import/compute_network_endpoint.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
config := meta.(*Config) | ||
// instance is optional, so use * instead of + when reading the import id | ||
if err := parseImportId([]string{ | ||
"projects/(?P<project>[^/]+)/zones/(?P<zone>[^/]+)/networkEndpointGroups/(?P<network_endpoint_group>[^/]+)/(?P<instance>[^/]*)/(?P<ip_address>[^/]+)/(?P<port>[^/]+)", | ||
"(?P<project>[^/]+)/(?P<zone>[^/]+)/(?P<network_endpoint_group>[^/]+)/(?P<instance>[^/]*)/(?P<ip_address>[^/]+)/(?P<port>[^/]+)", | ||
"(?P<zone>[^/]+)/(?P<network_endpoint_group>[^/]+)/(?P<instance>[^/]*)/(?P<ip_address>[^/]+)/(?P<port>[^/]+)", | ||
"(?P<network_endpoint_group>[^/]+)/(?P<instance>[^/]*)/(?P<ip_address>[^/]+)/(?P<port>[^/]+)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := replaceVars(d, config, "{{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
105 changes: 105 additions & 0 deletions
105
mmv1/templates/terraform/examples/global_forwarding_rule_hybrid.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Roughly mirrors https://cloud.google.com/load-balancing/docs/https/setting-up-ext-https-hybrid | ||
|
||
resource "google_compute_network" "default" { | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
} | ||
|
||
// Zonal NEG with GCE_VM_IP_PORT | ||
resource "google_compute_network_endpoint_group" "default" { | ||
name = "<%= ctx[:vars]['default_neg_name'] %>" | ||
network = google_compute_network.default.id | ||
default_port = "90" | ||
zone = "us-central1-a" | ||
network_endpoint_type = "GCE_VM_IP_PORT" | ||
} | ||
|
||
// Hybrid connectivity NEG | ||
resource "google_compute_network_endpoint_group" "hybrid" { | ||
name = "<%= ctx[:vars]['hybrid_neg_name'] %>" | ||
network = google_compute_network.default.id | ||
default_port = "90" | ||
zone = "us-central1-a" | ||
network_endpoint_type = "NON_GCP_PRIVATE_IP_PORT" | ||
} | ||
|
||
resource "google_compute_network_endpoint" "hybrid-endpoint" { | ||
network_endpoint_group = google_compute_network_endpoint_group.hybrid.name | ||
port = google_compute_network_endpoint_group.hybrid.default_port | ||
ip_address = "127.0.0.1" | ||
} | ||
|
||
// Backend service for Zonal NEG | ||
resource "google_compute_backend_service" "default" { | ||
name = "<%= ctx[:vars]['default_backend_service_name'] %>" | ||
port_name = "http" | ||
protocol = "HTTP" | ||
timeout_sec = 10 | ||
backend { | ||
group = google_compute_network_endpoint_group.default.id | ||
balancing_mode = "RATE" | ||
max_rate_per_endpoint = 10 | ||
} | ||
health_checks = [google_compute_health_check.default.id] | ||
} | ||
|
||
// Backgend service for Hybrid NEG | ||
resource "google_compute_backend_service" "hybrid" { | ||
name = "<%= ctx[:vars]['hybrid_backend_service_name'] %>" | ||
port_name = "http" | ||
protocol = "HTTP" | ||
timeout_sec = 10 | ||
backend { | ||
group = google_compute_network_endpoint_group.hybrid.id | ||
balancing_mode = "RATE" | ||
max_rate_per_endpoint = 10 | ||
} | ||
health_checks = [google_compute_health_check.default.id] | ||
} | ||
|
||
resource "google_compute_health_check" "default" { | ||
name = "<%= ctx[:vars]['health_check_name'] %>" | ||
timeout_sec = 1 | ||
check_interval_sec = 1 | ||
|
||
tcp_health_check { | ||
port = "80" | ||
} | ||
} | ||
|
||
resource "google_compute_url_map" "default" { | ||
name = "url-map-<%= ctx[:vars]['http_proxy_name'] %>" | ||
description = "a description" | ||
default_service = google_compute_backend_service.default.id | ||
|
||
host_rule { | ||
hosts = ["mysite.com"] | ||
path_matcher = "allpaths" | ||
} | ||
|
||
path_matcher { | ||
name = "allpaths" | ||
default_service = google_compute_backend_service.default.id | ||
|
||
path_rule { | ||
paths = ["/*"] | ||
service = google_compute_backend_service.default.id | ||
} | ||
|
||
path_rule { | ||
paths = ["/hybrid"] | ||
service = google_compute_backend_service.hybrid.id | ||
} | ||
} | ||
} | ||
|
||
resource "google_compute_target_http_proxy" "default" { | ||
name = "<%= ctx[:vars]['http_proxy_name'] %>" | ||
description = "a description" | ||
url_map = google_compute_url_map.default.id | ||
} | ||
|
||
resource "google_compute_global_forwarding_rule" "default" { | ||
name = "<%= ctx[:vars]['forwarding_rule_name'] %>" | ||
target = google_compute_target_http_proxy.default.id | ||
port_range = "80" | ||
} |
17 changes: 17 additions & 0 deletions
17
mmv1/templates/terraform/examples/network_endpoint_group_non_gcp.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "google_compute_network_endpoint_group" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['neg_name'] %>" | ||
network = google_compute_network.default.id | ||
default_port = "90" | ||
zone = "us-central1-a" | ||
network_endpoint_type = "NON_GCP_PRIVATE_IP_PORT" | ||
} | ||
|
||
resource "google_compute_network_endpoint" "default-endpoint" { | ||
network_endpoint_group = google_compute_network_endpoint_group.<%= ctx[:primary_resource_id] %>.name | ||
port = google_compute_network_endpoint_group.<%= ctx[:primary_resource_id] %>.default_port | ||
ip_address = "127.0.0.1" | ||
} | ||
|
||
resource "google_compute_network" "default" { | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters