forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global NEG (GoogleCloudPlatform#3333)
* Adding external neg with fqdn * Add decoder to fetch networkEndpoint * Test passing, add custom import, decoder * Fix old test * Exclude from ansible/inspec * networkEndpointGroup -> globalNetworkEndpointGroup for global endpoint * Rebase, dont pre delete empty fields * Delete unused file
- Loading branch information
Showing
15 changed files
with
459 additions
and
2 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
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
18 changes: 18 additions & 0 deletions
18
templates/terraform/custom_import/compute_global_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,18 @@ | ||
config := meta.(*Config) | ||
// FQDN, port and ip_address are optional, so use * instead of + when reading the import id | ||
if err := parseImportId([]string{ | ||
"projects/(?P<project>[^/]?)/global/networkEndpointGroups/(?P<global_network_endpoint_group>[^/]+)/(?P<ip_address>[^/]+)/(?P<fqdn>[^/]*)/(?P<port>[^/]+)", | ||
"(?P<project>[^/]+)/(?P<global_network_endpoint_group>[^/]+)/(?P<ip_address>[^/]*)/(?P<fqdn>[^/]*)/(?P<port>[^/]*)", | ||
"(?P<global_network_endpoint_group>[^/]+)/(?P<ip_address>[^/]*)/(?P<fqdn>[^/]*)/(?P<port>[^/]*)", | ||
}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Replace import id for the resource id | ||
id, err := replaceVars(d, config, "{{project}}/{{global_network_endpoint_group}}/{{ip_address}}/{{fqdn}}/{{port}}") | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
return []*schema.ResourceData{d}, nil |
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,20 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2017 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. | ||
-%> | ||
v, ok := res["networkEndpoint"] | ||
if !ok || v == nil { | ||
return res, nil | ||
} | ||
|
||
return v.(map[string]interface{}), nil |
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,20 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2017 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. | ||
-%> | ||
v, ok := res["networkEndpoint"] | ||
if !ok || v == nil { | ||
return res, nil | ||
} | ||
|
||
return v.(map[string]interface{}), nil |
21 changes: 21 additions & 0 deletions
21
templates/terraform/encoders/compute_global_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,21 @@ | ||
<%# The license inside this block applies to this file. | ||
# Copyright 2017 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. | ||
-%> | ||
// Network Endpoint Group is a URL parameter only, so replace self-link/path with resource name only. | ||
d.Set("global_network_endpoint_group", GetResourceNameFromSelfLink(d.Get("global_network_endpoint_group").(string))) | ||
|
||
wrappedReq := map[string]interface{}{ | ||
"networkEndpoints": []interface{}{obj}, | ||
} | ||
return wrappedReq, nil |
18 changes: 18 additions & 0 deletions
18
templates/terraform/examples/global_network_endpoint.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,18 @@ | ||
resource "google_compute_global_network_endpoint" "<%= ctx[:primary_resource_id] %>" { | ||
global_network_endpoint_group = google_compute_network_endpoint_group.neg.name | ||
|
||
fqdn = "www.example.com" | ||
port = google_compute_network_endpoint_group.neg.default_port | ||
ip_address = google_compute_instance.endpoint-instance.network_interface[0].network_ip | ||
} | ||
|
||
resource "google_compute_global_network_endpoint_group" "group" { | ||
name = "<%= ctx[:vars]['neg_name'] %>" | ||
network = google_compute_network.default.self_link | ||
default_port = "90" | ||
} | ||
|
||
resource "google_compute_network" "default" { | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
auto_create_subnetworks = false | ||
} |
5 changes: 5 additions & 0 deletions
5
templates/terraform/examples/global_network_endpoint_group.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,5 @@ | ||
resource "google_compute_global_network_endpoint_group" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['neg_name'] %>" | ||
default_port = "90" | ||
network_endpoint_type = "INTERNET_FQDN_PORT" | ||
} |
5 changes: 5 additions & 0 deletions
5
templates/terraform/examples/global_network_endpoint_group_ip_address.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,5 @@ | ||
resource "google_compute_global_network_endpoint_group" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['neg_name'] %>" | ||
network_endpoint_type = "INTERNET_IP_PORT" | ||
default_port = 90 | ||
} |
25 changes: 25 additions & 0 deletions
25
templates/terraform/post_create/global_network_endpoint_group.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,25 @@ | ||
endpointObj := make(map[string]interface{}) | ||
if v, ok := d.GetOkExists("fqdn"); !isEmptyValue(reflect.ValueOf(fqdnProp)) && (ok || !reflect.DeepEqual(v, fqdnProp)) { | ||
endpointObj["fqdn"] = fqdnProp | ||
} | ||
if v, ok := d.GetOkExists("port"); !isEmptyValue(reflect.ValueOf(portProp)) && (ok || !reflect.DeepEqual(v, portProp)) { | ||
endpointObj["port"] = portProp | ||
} | ||
if v, ok := d.GetOkExists("ip_address"); !isEmptyValue(reflect.ValueOf(ipAddressProp)) && (ok || !reflect.DeepEqual(v, ipAddressProp)) { | ||
endpointObj["ipAddress"] = ipAddressProp | ||
} | ||
|
||
wrappedReq := map[string]interface{}{ | ||
"networkEndpoints": []interface{}{endpointObj}, | ||
} | ||
|
||
attachUrl, err := replaceVars(d, config, "{{ComputeBasePath}}projects/{{project}}/global/networkEndpointGroups/{{name}}/attachNetworkEndpoints") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Creating new GlobalNetworkEndpoint: %#v", wrappedReq) | ||
_, err = sendRequestWithTimeout(config, "POST", project, attachUrl, wrappedReq, d.Timeout(schema.TimeoutCreate)) | ||
if err != nil { | ||
return fmt.Errorf("Error creating GlobalNetworkEndpoint: %s", err) | ||
} |
Oops, something went wrong.