-
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 network_url attribute in consumer_accept_list block of google_com…
…pute_service_attachment resource (#9895) * add network_url attribute in consumer_accept_list block of google_compute_service_attachment resource * Bugfix: Use SelfLinkRelativePath check to prevent false positive resource changes
- Loading branch information
1 parent
3791c34
commit 0249d74
Showing
3 changed files
with
172 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
mmv1/templates/terraform/constants/compute_service_attachment.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,50 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2020 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
-%> | ||
|
||
// Hash based on key, which is either project_id_or_num or network_url. | ||
func computeServiceAttachmentConsumerAcceptListsHash(v interface{}) int { | ||
if v == nil { | ||
return 0 | ||
} | ||
|
||
var buf bytes.Buffer | ||
m := v.(map[string]interface{}) | ||
log.Printf("[DEBUG] hashing %v", m) | ||
|
||
if v, ok := m["project_id_or_num"]; ok { | ||
if v == nil { | ||
v = "" | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
|
||
if v, ok := m["network_url"]; ok { | ||
if v == nil { | ||
v = "" | ||
} else { | ||
if networkUrl, err := tpgresource.GetRelativePath(v.(string)); err != nil { | ||
log.Printf("[WARN] Error on retrieving relative path of network url: %s", err) | ||
} else { | ||
v = networkUrl | ||
} | ||
} | ||
|
||
buf.WriteString(fmt.Sprintf("%v-", v)) | ||
} | ||
|
||
log.Printf("[DEBUG] computed hash value of %v from %v", tpgresource.Hashcode(buf.String()), buf.String()) | ||
return tpgresource.Hashcode(buf.String()) | ||
} |
97 changes: 97 additions & 0 deletions
97
mmv1/templates/terraform/examples/service_attachment_explicit_networks.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,97 @@ | ||
resource "google_compute_service_attachment" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['service_attachment_name'] %>" | ||
region = "us-west2" | ||
description = "A service attachment configured with Terraform" | ||
|
||
enable_proxy_protocol = false | ||
|
||
connection_preference = "ACCEPT_MANUAL" | ||
nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id] | ||
target_service = google_compute_forwarding_rule.psc_ilb_target_service.id | ||
|
||
consumer_accept_lists { | ||
network_url = google_compute_network.psc_ilb_consumer_network.self_link | ||
connection_limit = 1 | ||
} | ||
} | ||
|
||
resource "google_compute_network" "psc_ilb_consumer_network" { | ||
name = "<%= ctx[:vars]['consumer_network_name'] %>" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "psc_ilb_consumer_subnetwork" { | ||
name = "<%= ctx[:vars]['consumer_network_name'] %>" | ||
ip_cidr_range = "10.0.0.0/16" | ||
region = "us-west2" | ||
network = google_compute_network.psc_ilb_consumer_network.id | ||
} | ||
|
||
resource "google_compute_address" "psc_ilb_consumer_address" { | ||
name = "<%= ctx[:vars]['consumer_address_name'] %>" | ||
region = "us-west2" | ||
|
||
subnetwork = google_compute_subnetwork.psc_ilb_consumer_subnetwork.id | ||
address_type = "INTERNAL" | ||
} | ||
|
||
resource "google_compute_forwarding_rule" "psc_ilb_consumer" { | ||
name = "<%= ctx[:vars]['consumer_forwarding_rule_name'] %>" | ||
region = "us-west2" | ||
|
||
target = google_compute_service_attachment.psc_ilb_service_attachment.id | ||
load_balancing_scheme = "" # need to override EXTERNAL default when target is a service attachment | ||
network = google_compute_network.psc_ilb_consumer_network.id | ||
subnetwork = google_compute_subnetwork.psc_ilb_consumer_subnetwork.id | ||
ip_address = google_compute_address.psc_ilb_consumer_address.id | ||
} | ||
|
||
resource "google_compute_forwarding_rule" "psc_ilb_target_service" { | ||
name = "<%= ctx[:vars]['producer_forwarding_rule_name'] %>" | ||
region = "us-west2" | ||
|
||
load_balancing_scheme = "INTERNAL" | ||
backend_service = google_compute_region_backend_service.producer_service_backend.id | ||
all_ports = true | ||
network = google_compute_network.psc_ilb_network.name | ||
subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name | ||
} | ||
|
||
resource "google_compute_region_backend_service" "producer_service_backend" { | ||
name = "<%= ctx[:vars]['producer_service_name'] %>" | ||
region = "us-west2" | ||
|
||
health_checks = [google_compute_health_check.producer_service_health_check.id] | ||
} | ||
|
||
resource "google_compute_health_check" "producer_service_health_check" { | ||
name = "<%= ctx[:vars]['producer_health_check_name'] %>" | ||
|
||
check_interval_sec = 1 | ||
timeout_sec = 1 | ||
tcp_health_check { | ||
port = "80" | ||
} | ||
} | ||
|
||
resource "google_compute_network" "psc_ilb_network" { | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" { | ||
name = "<%= ctx[:vars]['producer_subnetwork_name'] %>" | ||
region = "us-west2" | ||
|
||
network = google_compute_network.psc_ilb_network.id | ||
ip_cidr_range = "10.0.0.0/16" | ||
} | ||
|
||
resource "google_compute_subnetwork" "psc_ilb_nat" { | ||
name = "<%= ctx[:vars]['nat_subnetwork_name'] %>" | ||
region = "us-west2" | ||
|
||
network = google_compute_network.psc_ilb_network.id | ||
purpose = "PRIVATE_SERVICE_CONNECT" | ||
ip_cidr_range = "10.1.0.0/16" | ||
} |